Skip to content

Commit

Permalink
Merge pull request #36 from mapreal19/mario/fix-require-migration-rai…
Browse files Browse the repository at this point in the history
…ls52

Fixes require migration for Rails 5.2
  • Loading branch information
ka8725 authored Oct 11, 2018
2 parents 54fa2ee + a7942c6 commit 069ba0e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/migration_data/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

def require_migration(migration_name)
path = MigrationData::ActiveRecord::Migration.migration_dir
all_migrations = ActiveRecord::Migrator.migrations(path)
migrations = all_migrations(path)

migration_name += '.rb' unless migration_name.end_with?('.rb')
file = all_migrations.detect do |m|
file = migrations.detect do |m|
m.filename.end_with?(migration_name)
end

raise LoadError, "cannot load such file -- #{migration_name}" unless file

require Rails.root.join(file.filename)
end

def all_migrations(path)
if Rails::VERSION::MAJOR >= 5 && Rails::VERSION::MINOR >= 2
ActiveRecord::MigrationContext.new(path).migrations
else
ActiveRecord::Migrator.migrations(path)
end
end

0 comments on commit 069ba0e

Please sign in to comment.