Top Level Namespace

Defined Under Namespace

Modules: MigrationData

Instance Method Summary collapse

Instance Method Details

#require_migration(migration_name) ⇒ Object

Raises:

  • (LoadError)


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

def require_migration(migration_name)
  path = ActiveRecord::Migrator.migrations_path
  all_migrations = ActiveRecord::Migrator.migrations(path)

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