summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-11-01 23:28:26 -0700
committerSteve Azzopardi <steveazz@outlook.com>2018-11-02 09:44:26 +0100
commit3bfb5f4708007e501ba91ce8f5f85c8bcce985f4 (patch)
tree3ce6232d1ce54d57c44758bfe49c360e3408199b
parentf4023a69cb5e78fca595a2151a2272fbdfd5917a (diff)
downloadgitlab-ce-prevent-override-of-attr_encrypted.tar.gz
Prevent attr_encrypted models from being overridenprevent-override-of-attr_encrypted
Fix failing spec in spec/controllers/admin/hooks_controller_spec.rb attr_encrypted expects models to have their attribute methods defined, or it will override them with standard Ruby accessors. Migration specs that rolled back the state of the database after columns were migrated to encrypted values were interfering with these definitions. To ensure that the SystemHook specs pass, we need to call `SystemHook.define_attribute_methods` to ensure that attr_encrypted sees the right methods that reflect the latest state of the database. Closes https://gitlab.com/gitlab-org/gitlab-ee/issues/8234
-rw-r--r--spec/support/helpers/migrations_helpers.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb
index 0c35764ed9a..ed1144fe233 100644
--- a/spec/support/helpers/migrations_helpers.rb
+++ b/spec/support/helpers/migrations_helpers.rb
@@ -1,6 +1,11 @@
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 +24,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 +45,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 +96,7 @@ module MigrationsHelpers
end
reset_column_in_all_models
+ refresh_attribute_methods
end
def disable_migrations_output