提交 96b50a03 编写于 作者: A Aaron Patterson

IrreversibleMigration is raised if we cannot invert the command

上级 b29a24bb
......@@ -20,7 +20,11 @@ def record(*command)
# 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 @@ def setup
@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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册