Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-11-17 14:33:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-11-17 14:33:21 +0300
commit7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch)
tree5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/support/migration.rb
parent185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff)
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/support/migration.rb')
-rw-r--r--spec/support/migration.rb36
1 files changed, 32 insertions, 4 deletions
diff --git a/spec/support/migration.rb b/spec/support/migration.rb
index 490aa836d74..2a69630a29a 100644
--- a/spec/support/migration.rb
+++ b/spec/support/migration.rb
@@ -16,14 +16,42 @@ RSpec.configure do |config|
schema_migrate_down!
end
+ config.after(:context, :migration) do
+ Gitlab::CurrentSettings.clear_in_memory_application_settings!
+ end
+
+ config.append_after(:context, :migration) do
+ recreate_databases_and_seed_if_needed || ensure_schema_and_empty_tables
+ end
+
+ config.around(:each, :migration) do |example|
+ self.class.use_transactional_tests = false
+
+ migration_schema = example.metadata[:migration]
+ migration_schema = :gitlab_main if migration_schema == true
+ base_model = Gitlab::Database.schemas_to_base_models.fetch(migration_schema).first
+
+ # Migration require an `ActiveRecord::Base` to point to desired database
+ if base_model != ActiveRecord::Base
+ with_reestablished_active_record_base do
+ reconfigure_db_connection(
+ model: ActiveRecord::Base,
+ config_model: base_model
+ )
+
+ example.run
+ end
+ else
+ example.run
+ end
+
+ self.class.use_transactional_tests = true
+ end
+
# 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
- Gitlab::CurrentSettings.clear_in_memory_application_settings!
- end
end