diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-24 17:28:19 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-24 17:28:19 +0000 |
commit | 0c2b07bfcb884e2b1ab6b5521596423578a3cdf8 (patch) | |
tree | e141bb9c790d02bdcae6d3d66f563c94475a9d51 /spec/support | |
parent | a77c4d2dce9e77e7104f009822faf56063a37dea (diff) | |
download | gitlab-ce-0c2b07bfcb884e2b1ab6b5521596423578a3cdf8.tar.gz |
Add latest changes from gitlab-org/gitlab@15-5-stable-ee
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/database/multiple_databases.rb | 20 | ||||
-rw-r--r-- | spec/support/database_cleaner.rb | 10 | ||||
-rw-r--r-- | spec/support/migration.rb | 2 |
3 files changed, 20 insertions, 12 deletions
diff --git a/spec/support/database/multiple_databases.rb b/spec/support/database/multiple_databases.rb index b863767b5df..b6341c2caec 100644 --- a/spec/support/database/multiple_databases.rb +++ b/spec/support/database/multiple_databases.rb @@ -2,15 +2,6 @@ module Database module MultipleDatabases - def run_and_cleanup(example) - # Each example may call `migrate!`, so we must ensure we are migrated down every time - schema_migrate_down! - - example.run - - delete_from_all_tables!(except: deletion_except_tables) - end - def skip_if_multiple_databases_not_setup skip 'Skipping because multiple databases not set up' unless Gitlab::Database.has_config?(:ci) end @@ -40,10 +31,15 @@ module Database config_model: base_model ) - schema_migrate_up! delete_from_all_tables!(except: deletion_except_tables) + schema_migrate_up! end end + + # ActiveRecord::Base.clear_all_connections! disconnects and clears attribute methods + # Force a refresh to avoid schema failures. + reset_column_in_all_models + refresh_attribute_methods end # The usage of this method switches temporarily used `connection_handler` @@ -152,10 +148,10 @@ RSpec.configure do |config| config_model: base_model ) - run_and_cleanup(example) + example.run end else - run_and_cleanup(example) + example.run end self.class.use_transactional_tests = true diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index 7bd1f0c5dfa..222cbe9feeb 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -22,4 +22,14 @@ RSpec.configure do |config| self.class.use_transactional_tests = true end + + config.around(:each, :migration) do |example| + self.class.use_transactional_tests = false + + example.run + + delete_from_all_tables!(except: deletion_except_tables) + + self.class.use_transactional_tests = true + end end diff --git a/spec/support/migration.rb b/spec/support/migration.rb index 24e2fc2ff31..490aa836d74 100644 --- a/spec/support/migration.rb +++ b/spec/support/migration.rb @@ -19,6 +19,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 config.after(:context, :migration) do |