Top Level Namespace

Defined Under Namespace

Modules: MigrationData

Instance Method Summary collapse

Instance Method Details

#all_migrations(path) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/migration_data/testing.rb', line 17

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

#require_migration(migration_name) ⇒ Object

Raises:

  • (LoadError)


3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/migration_data/testing.rb', line 3

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

  migration_name += '.rb' unless migration_name.end_with?('.rb')
  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