Commit 028423c2 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Calculate previous migration version in specs support

This makes it possible to test migration on the schema this migration
was written for, without a need to specify a previous schema version
manually.
parent 1a438e9f
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170526185921_migrate_build_stage_reference.rb')
describe MigrateBuildStageReference, :migration, schema: 20170526185602 do
describe MigrateBuildStageReference, :migration do
##
# Create test data - pipeline and CI/CD jobs.
#
......
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170526185842_migrate_pipeline_stages.rb')
describe MigratePipelineStages, :migration, schema: 20170526185602 do
describe MigratePipelineStages, :migration do
##
# Create test data - pipeline and CI/CD jobs.
#
......
......@@ -94,10 +94,10 @@ RSpec.configure do |config|
Sidekiq.redis(&:flushall)
end
config.around(:example, migration: true) do |example|
config.around(:example, :migration) do |example|
begin
schema_version = example.metadata.fetch(:schema)
ActiveRecord::Migrator.migrate(migrations_paths, schema_version)
ActiveRecord::Migrator
.migrate(migrations_paths, previous_migration.version)
example.run
ensure
......
......@@ -11,6 +11,16 @@ module MigrationsHelpers
ActiveRecord::Base.connection.table_exists?(name)
end
def migrations
ActiveRecord::Migrator.migrations(migrations_paths)
end
def previous_migration
migrations.each_cons(2) do |previous, migration|
break previous if migration.name == described_class.name
end
end
def migrate!
ActiveRecord::Migrator.up(migrations_paths) do |migration|
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