1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

record unsupported methods in CommandRecorder instead of letting the unsupported methods go through to the underlying db causing errors like duplicate columns to occur when rolling back migrations

This commit is contained in:
Vijay Dev 2011-06-25 00:01:59 +05:30
parent 7e56bf7244
commit c278a2c5e1
2 changed files with 9 additions and 7 deletions

View file

@ -93,11 +93,11 @@ module ActiveRecord
[:remove_timestamps, args]
end
# Forwards any missing method call to the \target.
# Record all the methods called in the +change+ method of a migration.
# 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)
@delegate.send(method, *args, &block)
rescue NoMethodError => e
raise e, e.message.sub(/ for #<.*$/, " via proxy for #{@delegate}")
record(method, args)
end
end

View file

@ -14,9 +14,11 @@ module ActiveRecord
assert recorder.respond_to?(:america)
end
def test_send_calls_super
assert_raises(NoMethodError) do
@recorder.send(:non_existing_method, :horses)
def test_non_existing_method_records_and_raises_on_inversion
@recorder.send(:non_existing_method, :horses)
assert_equal 1, @recorder.commands.length
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.inverse
end
end