Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1941 from vijaydev/command-recorder-fix

Reversing the changes related to CommandRecorder
  • Loading branch information...
commit 3adb24aa6be8c8fb131f07b523ff5dfd54580c1d 2 parents 17693a9 + 15f35c0
Jon Leighton jonleighton authored
14 activerecord/lib/active_record/migration/command_recorder.rb
View
@@ -48,7 +48,7 @@ def respond_to?(*args) # :nodoc:
super || delegate.respond_to?(*args)
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
def #{method}(*args) # def create_table(*args)
record(:"#{method}", args) # record(:create_table, args)
@@ -93,15 +93,11 @@ def invert_add_timestamps(args)
[:remove_timestamps, args]
end
- # 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.
+ # Forwards any missing method call to the \target.
def method_missing(method, *args, &block)
- if delegate.respond_to?(method)
- delegate.send(method, *args, &block)
- else
- record(method, args)
- end
+ @delegate.send(method, *args, &block)
+ rescue NoMethodError => e
+ raise e, e.message.sub(/ for #<.*$/, " via proxy for #{@delegate}")
end
end
8 activerecord/test/cases/migration/command_recorder_test.rb
View
@@ -14,11 +14,9 @@ def america; end
assert recorder.respond_to?(:america)
end
- 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
+ def test_send_calls_super
+ assert_raises(NoMethodError) do
+ @recorder.send(:non_existing_method, :horses)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.