Skip to content

Commit be92230

Browse files
committed
Merge branch 'prevent-override-of-attr_encrypted' into 'master'
Prevent attr_encrypted models from being overriden Closes gitlab-ee#8234 See merge request gitlab-org/gitlab-ce!22764
2 parents 5fcd7a8 + 8fd2c8b commit be92230

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

spec/support/helpers/migrations_helpers.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
module MigrationsHelpers
2+
def active_record_base
3+
ActiveRecord::Base
4+
end
5+
26
def table(name)
3-
Class.new(ActiveRecord::Base) do
7+
Class.new(active_record_base) do
48
self.table_name = name
59
self.inheritance_column = :_type_disabled
610

@@ -19,7 +23,7 @@ def migrations
1923
end
2024

2125
def clear_schema_cache!
22-
ActiveRecord::Base.connection_pool.connections.each do |conn|
26+
active_record_base.connection_pool.connections.each do |conn|
2327
conn.schema_cache.clear!
2428
end
2529
end
@@ -40,11 +44,18 @@ def reset_column_in_all_models
4044
# Reset column information for the most offending classes **after** we
4145
# migrated the schema up, otherwise, column information could be
4246
# outdated. We have a separate method for this so we can override it in EE.
43-
ActiveRecord::Base.descendants.each(&method(:reset_column_information))
47+
active_record_base.descendants.each(&method(:reset_column_information))
48+
end
4449

45-
# Without that, we get errors because of missing attributes, e.g.
50+
def refresh_attribute_methods
51+
# Without this, we get errors because of missing attributes, e.g.
4652
# super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8>
47-
ApplicationSetting.define_attribute_methods
53+
# attr_encrypted also expects ActiveRecord attribute methods to be
54+
# defined, or it will override the accessors:
55+
# https://gitlab.com/gitlab-org/gitlab-ee/issues/8234#note_113976421
56+
[ApplicationSetting, SystemHook].each do |model|
57+
model.define_attribute_methods
58+
end
4859
end
4960

5061
def reset_column_information(klass)
@@ -84,6 +95,7 @@ def schema_migrate_up!
8495
end
8596

8697
reset_column_in_all_models
98+
refresh_attribute_methods
8799
end
88100

89101
def disable_migrations_output

0 commit comments

Comments
 (0)