提交 0f9fbae7 编写于 作者: G Grzegorz Bizon

Add migrations helpers to simplify writing migration specs

上级 f7aba153
......@@ -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
#
......
......@@ -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
......
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册