Commit f7aba153 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Make migration specs by using migrator in around hook

parent acc22a84
......@@ -2,10 +2,23 @@ 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
#
......@@ -13,10 +26,10 @@ describe MigratePipelineStages, :migration, schema: 20170523091700 do
table(:ci_pipelines).create!(ref: 'master', sha: 'adf43c3a')
end
it 'correctly migrates pipeline stages' do
it 'correctly migrates pipeline stages' do |migration, meta|
expect(ActiveRecord::Base.connection.table_exists?('ci_stages')).to eq false
described_class.new.migrate(:up)
migrate!
expect(ActiveRecord::Base.connection.table_exists?('ci_stages')).to eq true
end
......
......@@ -100,7 +100,7 @@ RSpec.configure do |config|
example.run
ActiveRecord::Migration.maintain_test_schema!
ActiveRecord::Migrator.migrate(migrations_paths)
end
end
......
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