Permalink
Browse files

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

… has been provided
  • Loading branch information...
1 parent 5ec3430 commit 54866b057496c1ffbec6d38c4257f8c03cb87f87 @workmad3 workmad3 committed with tenderlove May 23, 2011
@@ -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)
@@ -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

0 comments on commit 54866b0

Please sign in to comment.