diff --git a/lib/migration_data/testing.rb b/lib/migration_data/testing.rb index 026ca7a..5ae7eed 100644 --- a/lib/migration_data/testing.rb +++ b/lib/migration_data/testing.rb @@ -2,10 +2,10 @@ 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 @@ -13,3 +13,11 @@ def require_migration(migration_name) 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