diff --git a/spec/migrations/migrate_pipeline_stages_spec.rb b/spec/migrations/migrate_pipeline_stages_spec.rb index d6d26ab52adde64689456fe3286f95f4ed712268..4a469174b9e4044c2abe40488233fd7f45774f6e 100644 --- a/spec/migrations/migrate_pipeline_stages_spec.rb +++ b/spec/migrations/migrate_pipeline_stages_spec.rb @@ -2,23 +2,6 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20170525132202_migrate_pipeline_stages.rb') describe MigratePipelineStages, :migration, schema: 20170523091700 do - ## - # TODO, extract to migrations helper - # - def table(name) - Class.new(ActiveRecord::Base) { self.table_name = name } - end - - def migrations_paths - ActiveRecord::Migrator.migrations_paths - end - - def migrate! - ActiveRecord::Migrator.up(migrations_paths) do |migration| - migration.name == described_class.name - end - end - ## # Create test data # diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9ed705a526711b669ba137cd5e4d19f7c40583de..2c1c252be37ca0d91d2f3dea60e7f17331e8f69f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,6 +52,7 @@ RSpec.configure do |config| config.include StubGitlabCalls config.include StubGitlabData config.include ApiHelpers, :api + config.include MigrationsHelpers, :migration config.infer_spec_type_from_file_location! @@ -94,9 +95,8 @@ RSpec.configure do |config| end config.around(:example, migration: true) do |example| - schema_version = example.metadata[:schema] - migrations_paths = ActiveRecord::Migrator.migrations_paths - ActiveRecord::Migrator.migrate(migrations_paths, schema_version) + ActiveRecord::Migrator + .migrate(migrations_paths, example.metadata.fetch(:schema)) example.run diff --git a/spec/support/migrations_helpers.rb b/spec/support/migrations_helpers.rb new file mode 100644 index 0000000000000000000000000000000000000000..965b00b573193f4992aa66e9f1156d6aed5beed7 --- /dev/null +++ b/spec/support/migrations_helpers.rb @@ -0,0 +1,15 @@ +module MigrationsHelpers + def table(name) + Class.new(ActiveRecord::Base) { self.table_name = name } + end + + def migrations_paths + ActiveRecord::Migrator.migrations_paths + end + + def migrate! + ActiveRecord::Migrator.up(migrations_paths) do |migration| + migration.name == described_class.name + end + end +end