提交 f7aba153 编写于 作者: G Grzegorz Bizon

Make migration specs by using migrator in around hook

上级 acc22a84
...@@ -2,10 +2,23 @@ require 'spec_helper' ...@@ -2,10 +2,23 @@ require 'spec_helper'
require Rails.root.join('db', 'migrate', '20170525132202_migrate_pipeline_stages.rb') require Rails.root.join('db', 'migrate', '20170525132202_migrate_pipeline_stages.rb')
describe MigratePipelineStages, :migration, schema: 20170523091700 do describe MigratePipelineStages, :migration, schema: 20170523091700 do
##
# TODO, extract to migrations helper
#
def table(name) def table(name)
Class.new(ActiveRecord::Base) { self.table_name = name } Class.new(ActiveRecord::Base) { self.table_name = name }
end 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 # Create test data
# #
...@@ -13,10 +26,10 @@ describe MigratePipelineStages, :migration, schema: 20170523091700 do ...@@ -13,10 +26,10 @@ describe MigratePipelineStages, :migration, schema: 20170523091700 do
table(:ci_pipelines).create!(ref: 'master', sha: 'adf43c3a') table(:ci_pipelines).create!(ref: 'master', sha: 'adf43c3a')
end 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 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 expect(ActiveRecord::Base.connection.table_exists?('ci_stages')).to eq true
end end
......
...@@ -100,7 +100,7 @@ RSpec.configure do |config| ...@@ -100,7 +100,7 @@ RSpec.configure do |config|
example.run example.run
ActiveRecord::Migration.maintain_test_schema! ActiveRecord::Migrator.migrate(migrations_paths)
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册