diff options
author | Stan Hu <stanhu@gmail.com> | 2018-11-07 21:04:51 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-07 21:04:51 +0000 |
commit | be92230c424c8673f80c4b28cd853db706df37d7 (patch) | |
tree | 5f3a0e7d09244895df9c2cb3d9c3fa399fd4d8a0 | |
parent | 5fcd7a87ab15bfeb15377918b93994699eb56c2e (diff) | |
parent | 8fd2c8b16ad7921aae60fbf5536fec263177337d (diff) | |
download | gitlab-ce-be92230c424c8673f80c4b28cd853db706df37d7.tar.gz |
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
-rw-r--r-- | spec/support/helpers/migrations_helpers.rb | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index 0c35764ed9a..5887c3eab74 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -1,6 +1,10 @@ module MigrationsHelpers + def active_record_base + ActiveRecord::Base + end + def table(name) - Class.new(ActiveRecord::Base) do + Class.new(active_record_base) do self.table_name = name self.inheritance_column = :_type_disabled @@ -19,7 +23,7 @@ module MigrationsHelpers end def clear_schema_cache! - ActiveRecord::Base.connection_pool.connections.each do |conn| + active_record_base.connection_pool.connections.each do |conn| conn.schema_cache.clear! end end @@ -40,11 +44,18 @@ module MigrationsHelpers # Reset column information for the most offending classes **after** we # migrated the schema up, otherwise, column information could be # outdated. We have a separate method for this so we can override it in EE. - ActiveRecord::Base.descendants.each(&method(:reset_column_information)) + active_record_base.descendants.each(&method(:reset_column_information)) + end - # Without that, we get errors because of missing attributes, e.g. + def refresh_attribute_methods + # Without this, we get errors because of missing attributes, e.g. # super: no superclass method `elasticsearch_indexing' for #<ApplicationSetting:0x00007f85628508d8> - ApplicationSetting.define_attribute_methods + # attr_encrypted also expects ActiveRecord attribute methods to be + # defined, or it will override the accessors: + # https://gitlab.com/gitlab-org/gitlab-ee/issues/8234#note_113976421 + [ApplicationSetting, SystemHook].each do |model| + model.define_attribute_methods + end end def reset_column_information(klass) @@ -84,6 +95,7 @@ module MigrationsHelpers end reset_column_in_all_models + refresh_attribute_methods end def disable_migrations_output |