Namespace
Methods
T
Instance Public methods
test_down()
# File activerecord/test/cases/invertible_migration_test.rb, line 339
def test_down
  LegacyMigration.up
  LegacyMigration.down
  ActiveSupport::Deprecation.silence { assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist" }
end
test_exception_on_removing_index_without_column_option()
# File activerecord/test/cases/invertible_migration_test.rb, line 177
def test_exception_on_removing_index_without_column_option
  index_definition = ["horses", [:name, :color]]
  migration1 = RemoveIndexMigration1.new
  migration1.migrate(:up)
  assert migration1.connection.index_exists?(*index_definition)

  migration2 = RemoveIndexMigration2.new
  migration2.migrate(:up)
  assert_not migration2.connection.index_exists?(*index_definition)

  migration2.migrate(:down)
  assert migration2.connection.index_exists?(*index_definition)
end
test_legacy_down()
# File activerecord/test/cases/invertible_migration_test.rb, line 328
def test_legacy_down
  LegacyMigration.migrate :up
  LegacyMigration.migrate :down
  ActiveSupport::Deprecation.silence { assert !ActiveRecord::Base.connection.table_exists?("horses"), "horses should not exist" }
end
test_legacy_up()
# File activerecord/test/cases/invertible_migration_test.rb, line 323
def test_legacy_up
  LegacyMigration.migrate :up
  ActiveSupport::Deprecation.silence { assert ActiveRecord::Base.connection.table_exists?("horses"), "horses should exist" }
end
test_migrate_down()
# File activerecord/test/cases/invertible_migration_test.rb, line 197
def test_migrate_down
  migration = InvertibleMigration.new
  migration.migrate :up
  migration.migrate :down
  ActiveSupport::Deprecation.silence { assert !migration.connection.table_exists?("horses") }
end
test_migrate_down_with_table_name_prefix()
# File activerecord/test/cases/invertible_migration_test.rb, line 345
def test_migrate_down_with_table_name_prefix
  ActiveRecord::Base.table_name_prefix = 'p_'
  ActiveRecord::Base.table_name_suffix = '_s'
  migration = InvertibleMigration.new
  migration.migrate(:up)
  assert_nothing_raised { migration.migrate(:down) }
  ActiveSupport::Deprecation.silence { assert !ActiveRecord::Base.connection.table_exists?("p_horses_s"), "p_horses_s should not exist" }
ensure
  ActiveRecord::Base.table_name_prefix = ActiveRecord::Base.table_name_suffix = ''
end
test_migrate_enable_and_disable_extension()
# File activerecord/test/cases/invertible_migration_test.rb, line 279
def test_migrate_enable_and_disable_extension
  migration1 = InvertibleMigration.new
  migration2 = DisableExtension1.new
  migration3 = DisableExtension2.new

  migration1.migrate(:up)
  migration2.migrate(:up)
  assert_equal true, Horse.connection.extension_enabled?('hstore')

  migration3.migrate(:up)
  assert_equal false, Horse.connection.extension_enabled?('hstore')

  migration3.migrate(:down)
  assert_equal true, Horse.connection.extension_enabled?('hstore')

  migration2.migrate(:down)
  assert_equal false, Horse.connection.extension_enabled?('hstore')
end
test_migrate_nested_revert_whole_migration()
# File activerecord/test/cases/invertible_migration_test.rb, line 255
def test_migrate_nested_revert_whole_migration
  revert = NestedRevertWholeMigration.new(InvertibleRevertMigration)
  revert.migrate :down
  ActiveSupport::Deprecation.silence { assert revert.connection.table_exists?("horses") }
  revert.migrate :up
  ActiveSupport::Deprecation.silence { assert !revert.connection.table_exists?("horses") }
end
test_migrate_revert()
# File activerecord/test/cases/invertible_migration_test.rb, line 204
def test_migrate_revert
  migration = InvertibleMigration.new
  revert = InvertibleRevertMigration.new
  migration.migrate :up
  revert.migrate :up
  ActiveSupport::Deprecation.silence { assert !migration.connection.table_exists?("horses") }
  revert.migrate :down
  ActiveSupport::Deprecation.silence { assert migration.connection.table_exists?("horses") }
  migration.migrate :down
  ActiveSupport::Deprecation.silence { assert !migration.connection.table_exists?("horses") }
end
test_migrate_revert_add_index_with_name()
# File activerecord/test/cases/invertible_migration_test.rb, line 358
def test_migrate_revert_add_index_with_name
  RevertNamedIndexMigration1.new.migrate(:up)
  RevertNamedIndexMigration2.new.migrate(:up)
  RevertNamedIndexMigration2.new.migrate(:down)

  connection = ActiveRecord::Base.connection
  assert connection.index_exists?(:horses, :content),
         "index on content should exist"
  assert !connection.index_exists?(:horses, :content, name: "horses_index_named"),
        "horses_index_named index should not exist"
end
test_migrate_revert_by_part()
# File activerecord/test/cases/invertible_migration_test.rb, line 216
def test_migrate_revert_by_part
  InvertibleMigration.new.migrate :up
  received = []
  migration = InvertibleByPartsMigration.new
  migration.test = ->(dir){
    ActiveSupport::Deprecation.silence do
      assert migration.connection.table_exists?("horses")
      assert migration.connection.table_exists?("new_horses")
    end
    received << dir
  }
  migration.migrate :up
  assert_equal [:both, :up], received
  ActiveSupport::Deprecation.silence do
    assert !migration.connection.table_exists?("horses")
    assert migration.connection.table_exists?("new_horses")
  end
  migration.migrate :down
  assert_equal [:both, :up, :both, :down], received
  ActiveSupport::Deprecation.silence do
    assert migration.connection.table_exists?("horses")
    assert !migration.connection.table_exists?("new_horses")
  end
end
test_migrate_revert_change_column_default()
# File activerecord/test/cases/invertible_migration_test.rb, line 263
def test_migrate_revert_change_column_default
  migration1 = ChangeColumnDefault1.new
  migration1.migrate(:up)
  assert_equal "Sekitoba", Horse.new.name

  migration2 = ChangeColumnDefault2.new
  migration2.migrate(:up)
  Horse.reset_column_information
  assert_equal "Diomed", Horse.new.name

  migration2.migrate(:down)
  Horse.reset_column_information
  assert_equal "Sekitoba", Horse.new.name
end
test_migrate_revert_whole_migration()
# File activerecord/test/cases/invertible_migration_test.rb, line 241
def test_migrate_revert_whole_migration
  migration = InvertibleMigration.new
  [LegacyMigration, InvertibleMigration].each do |klass|
    revert = RevertWholeMigration.new(klass)
    migration.migrate :up
    revert.migrate :up
    ActiveSupport::Deprecation.silence { assert !migration.connection.table_exists?("horses") }
    revert.migrate :down
    ActiveSupport::Deprecation.silence { assert migration.connection.table_exists?("horses") }
    migration.migrate :down
    ActiveSupport::Deprecation.silence { assert !migration.connection.table_exists?("horses") }
  end
end
test_migrate_up()
# File activerecord/test/cases/invertible_migration_test.rb, line 191
def test_migrate_up
  migration = InvertibleMigration.new
  migration.migrate(:up)
  ActiveSupport::Deprecation.silence { assert migration.connection.table_exists?("horses"), "horses should exist" }
end
test_no_reverse()
# File activerecord/test/cases/invertible_migration_test.rb, line 169
def test_no_reverse
  migration = NonInvertibleMigration.new
  migration.migrate(:up)
  assert_raises(IrreversibleMigration) do
    migration.migrate(:down)
  end
end
test_revert_order()
# File activerecord/test/cases/invertible_migration_test.rb, line 299
def test_revert_order
  block = Proc.new{|t| t.string :name }
  recorder = ActiveRecord::Migration::CommandRecorder.new(ActiveRecord::Base.connection)
  recorder.instance_eval do
    create_table("apples", &block)
    revert do
      create_table("bananas", &block)
      revert do
        create_table("clementines")
        create_table("dates")
      end
      create_table("elderberries")
    end
    revert do
      create_table("figs")
      create_table("grapes")
    end
  end
  assert_equal [[:create_table, ["apples"], block], [:drop_table, ["elderberries"], nil],
                [:create_table, ["clementines"], nil], [:create_table, ["dates"], nil],
                [:drop_table, ["bananas"], block], [:drop_table, ["grapes"], nil],
                [:drop_table, ["figs"], nil]], recorder.commands
end
test_up()
# File activerecord/test/cases/invertible_migration_test.rb, line 334
def test_up
  LegacyMigration.up
  ActiveSupport::Deprecation.silence { assert ActiveRecord::Base.connection.table_exists?("horses"), "horses should exist" }
end