summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-16 13:05:18 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-16 13:05:18 +0200
commitc76f8f3e8fda0b2233254a58cd0c1672fc0b6c5a (patch)
tree58111591af9c89ea9c74a8727a8ce5fd1b00c5c4
parent71564974935feafd3f0025ec51832fcea6cba003 (diff)
downloadgitlab-ce-c76f8f3e8fda0b2233254a58cd0c1672fc0b6c5a.tar.gz
Make it possible to provide schema version in tests
-rw-r--r--spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb21
-rw-r--r--spec/spec_helper.rb11
-rw-r--r--spec/support/migrations_helpers.rb15
3 files changed, 23 insertions, 24 deletions
diff --git a/spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb b/spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb
index 87f45619e7a..0d5fffa38ff 100644
--- a/spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_events_to_push_event_payloads_spec.rb
@@ -210,7 +210,11 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads::Event do
end
end
-describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads do
+##
+# The background migration relies on a temporary table, hence we're migrating
+# to a specific version of the database where said table is still present.
+#
+describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads, :migration, schema: 20170608152748 do
let(:migration) { described_class.new }
let(:project) { create(:project_empty_repo) }
let(:author) { create(:user) }
@@ -229,21 +233,6 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads do
)
end
- # The background migration relies on a temporary table, hence we're migrating
- # to a specific version of the database where said table is still present.
- before :all do
- ActiveRecord::Migration.verbose = false
-
- ActiveRecord::Migrator
- .migrate(ActiveRecord::Migrator.migrations_paths, 20170608152748)
- end
-
- after :all do
- ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths)
-
- ActiveRecord::Migration.verbose = true
- end
-
describe '#perform' do
it 'returns if data should not be migrated' do
allow(migration).to receive(:migrate?).and_return(false)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c606030220f..7d424cdf735 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -132,17 +132,12 @@ RSpec.configure do |config|
Sidekiq.redis(&:flushall)
end
- config.before(:context, :migration) do |example|
- ActiveRecord::Migrator
- .migrate(migrations_paths, previous_migration.version)
-
- reset_column_in_migration_models
+ config.before(:context, :migration) do
+ schema_migrate_down!
end
config.after(:context, :migration) do
- ActiveRecord::Migrator.migrate(migrations_paths)
-
- reset_column_in_migration_models
+ schema_migrate_up!
end
config.around(:each, :nested_groups) do |example|
diff --git a/spec/support/migrations_helpers.rb b/spec/support/migrations_helpers.rb
index aabdad13047..3e8c6b54c5a 100644
--- a/spec/support/migrations_helpers.rb
+++ b/spec/support/migrations_helpers.rb
@@ -31,6 +31,21 @@ module MigrationsHelpers
end
end
+ def migration_schema_version
+ self.class.metadata[:schema] || previous_migration.version
+ end
+
+ def schema_migrate_down!
+ ActiveRecord::Migrator
+ .migrate(migrations_paths, migration_schema_version)
+ reset_column_in_migration_models
+ end
+
+ def schema_migrate_up!
+ ActiveRecord::Migrator.migrate(migrations_paths)
+ reset_column_in_migration_models
+ end
+
def migrate!
ActiveRecord::Migrator.up(migrations_paths) do |migration|
migration.name == described_class.name