Skip to content

Commit

Permalink
CommandRecorder should delegate in method_missing where possible. Fix…
Browse files Browse the repository at this point in the history
…es some tests in migration_test.rb under mysql. The problem was introduced in c278a2c.
  • Loading branch information
jonleighton committed Jun 29, 2011
1 parent b4d8c7d commit 4d256bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion activerecord/lib/active_record/migration/command_recorder.rb
Expand Up @@ -97,7 +97,11 @@ def invert_add_timestamps(args)
# 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)
record(method, args)
if delegate.respond_to?(method)
delegate.send(method, *args, &block)
else
record(method, args)
end
end

end
Expand Down
7 changes: 6 additions & 1 deletion activerecord/test/cases/migration/command_recorder_test.rb
Expand Up @@ -31,7 +31,12 @@ def create_table(name); end
assert_equal [[:create_table, [:horses]]], recorder.commands
end

def test_unknown_commands_raise_exception
def test_unknown_commands_delegate
recorder = CommandRecorder.new(stub(:foo => 'bar'))
assert_equal 'bar', recorder.foo
end

def test_unknown_commands_raise_exception_if_they_cannot_delegate
@recorder.record :execute, ['some sql']
assert_raises(ActiveRecord::IrreversibleMigration) do
@recorder.inverse
Expand Down

0 comments on commit 4d256bc

Please sign in to comment.