mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
IrreversibleMigration is raised if we cannot invert the command
This commit is contained in:
parent
b29a24bb6f
commit
96b50a0392
2 changed files with 12 additions and 1 deletions
|
@ -20,7 +20,11 @@ module ActiveRecord
|
|||
# Returns a list that represents commands that are the inverse of the
|
||||
# commands stored in +commands+.
|
||||
def inverse
|
||||
@commands.reverse.map { |name, args| send(:"invert_#{name}", args) }
|
||||
@commands.reverse.map { |name, args|
|
||||
method = :"invert_#{name}"
|
||||
raise IrreversibleMigration unless respond_to?(method, true)
|
||||
send(method, args)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -7,6 +7,13 @@ module ActiveRecord
|
|||
@recorder = CommandRecorder.new
|
||||
end
|
||||
|
||||
def test_unknown_commands_raise_exception
|
||||
@recorder.record :execute, ['some sql']
|
||||
assert_raises(ActiveRecord::IrreversibleMigration) do
|
||||
@recorder.inverse
|
||||
end
|
||||
end
|
||||
|
||||
def test_record
|
||||
@recorder.record :create_table, [:system_settings]
|
||||
assert_equal 1, @recorder.commands.length
|
||||
|
|
Loading…
Reference in a new issue