testing instance based migrations
This commit is contained in:
parent
974ff0dd43
commit
68b66ef308
|
@ -306,11 +306,13 @@ module ActiveRecord
|
|||
|
||||
def up
|
||||
self.class.delegate = self
|
||||
return unless self.class.respond_to?(:up)
|
||||
self.class.up
|
||||
end
|
||||
|
||||
def down
|
||||
self.class.delegate = self
|
||||
return unless self.class.respond_to?(:down)
|
||||
self.class.down
|
||||
end
|
||||
|
||||
|
|
|
@ -1166,6 +1166,44 @@ if ActiveRecord::Base.connection.supports_migrations?
|
|||
assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
|
||||
end
|
||||
|
||||
class MockMigration < ActiveRecord::Migration
|
||||
attr_reader :went_up, :went_down
|
||||
def initialize
|
||||
@went_up = false
|
||||
@went_down = false
|
||||
end
|
||||
|
||||
def up
|
||||
@went_up = true
|
||||
super
|
||||
end
|
||||
|
||||
def down
|
||||
@went_down = true
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def test_instance_based_migration_up
|
||||
migration = MockMigration.new
|
||||
assert !migration.went_up, 'have not gone up'
|
||||
assert !migration.went_down, 'have not gone down'
|
||||
|
||||
migration.migrate :up
|
||||
assert migration.went_up, 'have gone up'
|
||||
assert !migration.went_down, 'have not gone down'
|
||||
end
|
||||
|
||||
def test_instance_based_migration_down
|
||||
migration = MockMigration.new
|
||||
assert !migration.went_up, 'have not gone up'
|
||||
assert !migration.went_down, 'have not gone down'
|
||||
|
||||
migration.migrate :down
|
||||
assert !migration.went_up, 'have gone up'
|
||||
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?
|
||||
|
|
Loading…
Reference in New Issue