Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Simple fix for correctly inverting an add_index migration when a name…

… has been provided
  • Loading branch information...
commit 54866b057496c1ffbec6d38c4257f8c03cb87f87 1 parent 5ec3430
David Workman workmad3 authored tenderlove committed
8 activerecord/lib/active_record/migration/command_recorder.rb
View
@@ -79,8 +79,12 @@ def invert_rename_column(args)
end
def invert_add_index(args)
- table, columns, _ = *args
- [:remove_index, [table, {:column => columns}]]
+ table, columns, options = *args
+ if options && options[:name]
+ [:remove_index, [table, {:name => options[:name]}]]
+ else
+ [:remove_index, [table, {:column => columns}]]
+ end
end
def invert_remove_timestamps(args)
6 activerecord/test/cases/migration/command_recorder_test.rb
View
@@ -91,6 +91,12 @@ def test_invert_add_index
assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove
end
+ def test_invert_add_index_with_name
+ @recorder.record :add_index, [:table, [:one, :two], {:name => "new_index"}]
+ remove = @recorder.inverse.first
+ assert_equal [:remove_index, [:table, {:name => "new_index"}]], remove
+ end
+
def test_invert_rename_index
@recorder.record :rename_index, [:old, :new]
rename = @recorder.inverse.first
Please sign in to comment.
Something went wrong with that request. Please try again.