Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1857 from vijaydev/irreversible-migration

IrreversibleMigration is not raised when a method not supported by reversible migrations is called in the change method of a migration
  • Loading branch information...
commit 941d5c1f4051416e1b7993374343e343027978a7 2 parents a5cb5a5 + c278a2c
@tenderlove tenderlove authored
View
8 activerecord/lib/active_record/migration/command_recorder.rb
@@ -93,11 +93,11 @@ def invert_add_timestamps(args)
[: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
8 activerecord/test/cases/migration/command_recorder_test.rb
@@ -14,9 +14,11 @@ def america; end
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
Please sign in to comment.
Something went wrong with that request. Please try again.