提交 15f35c0a 编写于 作者: V Vijay Dev

Reversing the changes done in c278a2c5 while still resolving #1857.

The changes broke bulk migration tests and were fixed in 4d256bc6;
however that brought back the issue of #1857 and so this commit goes
back to the original scenario and just adds change_table to the list
of methods which are to be recorded in the CommandRecorder. The
method_missing now delegates all calls to the underlying connection as
before.
上级 908be477
...@@ -48,7 +48,7 @@ def respond_to?(*args) # :nodoc: ...@@ -48,7 +48,7 @@ def respond_to?(*args) # :nodoc:
super || delegate.respond_to?(*args) super || delegate.respond_to?(*args)
end end
[:create_table, :rename_table, :add_column, :remove_column, :rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps, :change_column, :change_column_default].each do |method| [:create_table, :change_table, :rename_table, :add_column, :remove_column, :rename_index, :rename_column, :add_index, :remove_index, :add_timestamps, :remove_timestamps, :change_column, :change_column_default].each do |method|
class_eval <<-EOV, __FILE__, __LINE__ + 1 class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{method}(*args) # def create_table(*args) def #{method}(*args) # def create_table(*args)
record(:"#{method}", args) # record(:create_table, args) record(:"#{method}", args) # record(:create_table, args)
...@@ -93,15 +93,11 @@ def invert_add_timestamps(args) ...@@ -93,15 +93,11 @@ def invert_add_timestamps(args)
[:remove_timestamps, args] [:remove_timestamps, args]
end end
# Record all the methods called in the +change+ method of a migration. # Forwards any missing method call to the \target.
# This will ensure that IrreversibleMigration is raised when the corresponding
# invert_method does not exist while the migration is rolled back.
def method_missing(method, *args, &block) def method_missing(method, *args, &block)
if delegate.respond_to?(method) @delegate.send(method, *args, &block)
delegate.send(method, *args, &block) rescue NoMethodError => e
else raise e, e.message.sub(/ for #<.*$/, " via proxy for #{@delegate}")
record(method, args)
end
end end
end end
......
...@@ -14,11 +14,9 @@ def america; end ...@@ -14,11 +14,9 @@ def america; end
assert recorder.respond_to?(:america) assert recorder.respond_to?(:america)
end end
def test_non_existing_method_records_and_raises_on_inversion def test_send_calls_super
@recorder.send(:non_existing_method, :horses) assert_raises(NoMethodError) do
assert_equal 1, @recorder.commands.length @recorder.send(:non_existing_method, :horses)
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.inverse
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册