Commit c76f8f3e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Make it possible to provide schema version in tests

parent 71564974
...@@ -210,7 +210,11 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads::Event do ...@@ -210,7 +210,11 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads::Event do
end end
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(:migration) { described_class.new }
let(:project) { create(:project_empty_repo) } let(:project) { create(:project_empty_repo) }
let(:author) { create(:user) } let(:author) { create(:user) }
...@@ -229,21 +233,6 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads do ...@@ -229,21 +233,6 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads do
) )
end 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 describe '#perform' do
it 'returns if data should not be migrated' do it 'returns if data should not be migrated' do
allow(migration).to receive(:migrate?).and_return(false) allow(migration).to receive(:migrate?).and_return(false)
......
...@@ -132,17 +132,12 @@ RSpec.configure do |config| ...@@ -132,17 +132,12 @@ RSpec.configure do |config|
Sidekiq.redis(&:flushall) Sidekiq.redis(&:flushall)
end end
config.before(:context, :migration) do |example| config.before(:context, :migration) do
ActiveRecord::Migrator schema_migrate_down!
.migrate(migrations_paths, previous_migration.version)
reset_column_in_migration_models
end end
config.after(:context, :migration) do config.after(:context, :migration) do
ActiveRecord::Migrator.migrate(migrations_paths) schema_migrate_up!
reset_column_in_migration_models
end end
config.around(:each, :nested_groups) do |example| config.around(:each, :nested_groups) do |example|
......
...@@ -31,6 +31,21 @@ module MigrationsHelpers ...@@ -31,6 +31,21 @@ module MigrationsHelpers
end end
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! def migrate!
ActiveRecord::Migrator.up(migrations_paths) do |migration| ActiveRecord::Migrator.up(migrations_paths) do |migration|
migration.name == described_class.name migration.name == described_class.name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment