mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
prefer method sensors over actual ddl changes
This commit is contained in:
parent
8739a42c38
commit
8037c51083
2 changed files with 84 additions and 69 deletions
|
@ -173,26 +173,6 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
assert_raise(ActiveRecord::StatementInvalid) { BigNumber.find(:first) }
|
||||
end
|
||||
|
||||
def test_migrator
|
||||
assert !Person.column_methods_hash.include?(:last_name)
|
||||
assert !Reminder.table_exists?
|
||||
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
|
||||
|
||||
assert_equal 3, ActiveRecord::Migrator.current_version
|
||||
Person.reset_column_information
|
||||
assert Person.column_methods_hash.include?(:last_name)
|
||||
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
||||
assert_equal "hello world", Reminder.find(:first).content
|
||||
|
||||
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid")
|
||||
|
||||
assert_equal 0, ActiveRecord::Migrator.current_version
|
||||
Person.reset_column_information
|
||||
assert !Person.column_methods_hash.include?(:last_name)
|
||||
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
||||
end
|
||||
|
||||
def test_filtering_migrations
|
||||
assert !Person.column_methods_hash.include?(:last_name)
|
||||
assert !Reminder.table_exists?
|
||||
|
@ -249,55 +229,6 @@ class MigrationTest < ActiveRecord::TestCase
|
|||
assert migration.went_down, 'have not gone down'
|
||||
end
|
||||
|
||||
def test_migrator_one_up
|
||||
assert !Person.column_methods_hash.include?(:last_name)
|
||||
assert !Reminder.table_exists?
|
||||
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
||||
|
||||
Person.reset_column_information
|
||||
assert Person.column_methods_hash.include?(:last_name)
|
||||
assert !Reminder.table_exists?
|
||||
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 2)
|
||||
|
||||
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
|
||||
assert_equal "hello world", Reminder.find(:first).content
|
||||
end
|
||||
|
||||
def test_migrator_one_down
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid")
|
||||
|
||||
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 1)
|
||||
|
||||
Person.reset_column_information
|
||||
assert Person.column_methods_hash.include?(:last_name)
|
||||
assert !Reminder.table_exists?
|
||||
end
|
||||
|
||||
def test_migrator_one_up_one_down
|
||||
ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", 1)
|
||||
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", 0)
|
||||
|
||||
assert !Person.column_methods_hash.include?(:last_name)
|
||||
assert !Reminder.table_exists?
|
||||
end
|
||||
|
||||
def test_migrator_double_up
|
||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
|
||||
assert_nothing_raised { ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1) }
|
||||
assert_equal(1, ActiveRecord::Migrator.current_version)
|
||||
end
|
||||
|
||||
def test_migrator_double_down
|
||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||
ActiveRecord::Migrator.run(:up, MIGRATIONS_ROOT + "/valid", 1)
|
||||
ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1)
|
||||
assert_nothing_raised { ActiveRecord::Migrator.run(:down, MIGRATIONS_ROOT + "/valid", 1) }
|
||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||
end
|
||||
|
||||
def test_migrator_one_up_with_exception_and_rollback
|
||||
unless ActiveRecord::Base.connection.supports_ddl_transactions?
|
||||
skip "not supported on #{ActiveRecord::Base.connection.class}"
|
||||
|
|
|
@ -154,5 +154,89 @@ module ActiveRecord
|
|||
ActiveRecord::SchemaMigration.create!(:version => '1000')
|
||||
assert_equal 1000, ActiveRecord::Migrator.current_version
|
||||
end
|
||||
|
||||
def test_migrator_one_up
|
||||
calls, migrations = sensors(3)
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations, 1).migrate
|
||||
assert_equal [[:up, 0], [:up, 1]], calls
|
||||
calls.clear
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations, 2).migrate
|
||||
assert_equal [[:up, 2]], calls
|
||||
end
|
||||
|
||||
def test_migrator_one_down
|
||||
calls, migrations = sensors(3)
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations).migrate
|
||||
assert_equal [[:up, 0], [:up, 1], [:up, 2]], calls
|
||||
calls.clear
|
||||
|
||||
ActiveRecord::Migrator.new(:down, migrations, 1).migrate
|
||||
|
||||
assert_equal [[:down, 2]], calls
|
||||
end
|
||||
|
||||
def test_migrator_one_up_one_down
|
||||
calls, migrations = sensors(3)
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations, 1).migrate
|
||||
assert_equal [[:up, 0], [:up, 1]], calls
|
||||
calls.clear
|
||||
|
||||
ActiveRecord::Migrator.new(:down, migrations, 0).migrate
|
||||
assert_equal [[:down, 1]], calls
|
||||
end
|
||||
|
||||
def test_migrator_double_up
|
||||
calls, migrations = sensors(3)
|
||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations, 1).migrate
|
||||
assert_equal [[:up, 0], [:up, 1]], calls
|
||||
calls.clear
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations, 1).migrate
|
||||
assert_equal [], calls
|
||||
end
|
||||
|
||||
def test_migrator_double_down
|
||||
calls, migrations = sensors(3)
|
||||
|
||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||
|
||||
ActiveRecord::Migrator.new(:up, migrations, 1).run
|
||||
assert_equal [[:up, 1]], calls
|
||||
calls.clear
|
||||
|
||||
ActiveRecord::Migrator.new(:down, migrations, 1).run
|
||||
assert_equal [[:down, 1]], calls
|
||||
calls.clear
|
||||
|
||||
ActiveRecord::Migrator.new(:down, migrations, 1).run
|
||||
assert_equal [], calls
|
||||
|
||||
assert_equal(0, ActiveRecord::Migrator.current_version)
|
||||
end
|
||||
|
||||
private
|
||||
def m(name, version, &block)
|
||||
x = Sensor.new name, version
|
||||
x.extend(Module.new {
|
||||
define_method(:up) { block.call(:up, x); super() }
|
||||
define_method(:down) { block.call(:down, x); super() }
|
||||
}) if block_given?
|
||||
end
|
||||
|
||||
def sensors(count)
|
||||
calls = []
|
||||
migrations = 3.times.map { |i|
|
||||
m(nil, i) { |c,migration|
|
||||
calls << [c, migration.version]
|
||||
}
|
||||
}
|
||||
[calls, migrations]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue