From a7942c61a40d305f738636f4be547b52ff28d32b Mon Sep 17 00:00:00 2001 From: Mario Perez Date: Thu, 27 Sep 2018 10:04:19 +0200 Subject: [PATCH] Fixes require migration for Rails 5.2 --- lib/migration_data/testing.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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