Commit 0f9fbae7 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add migrations helpers to simplify writing migration specs

parent f7aba153
...@@ -2,23 +2,6 @@ require 'spec_helper' ...@@ -2,23 +2,6 @@ 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)
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 # Create test data
# #
......
...@@ -52,6 +52,7 @@ RSpec.configure do |config| ...@@ -52,6 +52,7 @@ RSpec.configure do |config|
config.include StubGitlabCalls config.include StubGitlabCalls
config.include StubGitlabData config.include StubGitlabData
config.include ApiHelpers, :api config.include ApiHelpers, :api
config.include MigrationsHelpers, :migration
config.infer_spec_type_from_file_location! config.infer_spec_type_from_file_location!
...@@ -94,9 +95,8 @@ RSpec.configure do |config| ...@@ -94,9 +95,8 @@ RSpec.configure do |config|
end end
config.around(:example, migration: true) do |example| config.around(:example, migration: true) do |example|
schema_version = example.metadata[:schema] ActiveRecord::Migrator
migrations_paths = ActiveRecord::Migrator.migrations_paths .migrate(migrations_paths, example.metadata.fetch(:schema))
ActiveRecord::Migrator.migrate(migrations_paths, schema_version)
example.run 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%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment