diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2018-12-15 01:01:04 +0800 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-12-19 11:24:54 +0100 |
commit | 25ef6f51c9899cc26661a2daac7ca0d47b95d443 (patch) | |
tree | 18b1a6dce0d2f32cff459f514d1179931e920b4e | |
parent | 0ff27ce05960598e5a1c0a1115180db0feeb689a (diff) | |
download | gitlab-ce-25ef6f51c9899cc26661a2daac7ca0d47b95d443.tar.gz |
Use fake application settings for migration tests
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/support/helpers/migrations_helpers.rb | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fb3421b61d3..ae5284c071b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -216,6 +216,8 @@ RSpec.configure do |config| # Each example may call `migrate!`, so we must ensure we are migrated down every time config.before(:each, :migration) do + use_fake_application_settings + schema_migrate_down! end diff --git a/spec/support/helpers/migrations_helpers.rb b/spec/support/helpers/migrations_helpers.rb index 5887c3eab74..cc1a28cb264 100644 --- a/spec/support/helpers/migrations_helpers.rb +++ b/spec/support/helpers/migrations_helpers.rb @@ -62,6 +62,22 @@ module MigrationsHelpers klass.reset_column_information end + # In some migration tests, we're using factories to create records, + # however those models might be depending on a schema version which + # doesn't have the columns we want in application_settings. + # In these cases, we'll need to use the fake application settings + # as if we have migrations pending + def use_fake_application_settings + # We stub this way because we can't stub on + # `current_application_settings` due to `method_missing` is + # depending on current_application_settings... + allow(ActiveRecord::Base.connection) + .to receive(:active?) + .and_return(false) + + stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') + end + def previous_migration migrations.each_cons(2) do |previous, migration| break previous if migration.name == described_class.name |