Permalink
Browse files

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

… has been provided
  • Loading branch information...
1 parent a8b2a89 commit a7fad65792b37a3f8643149ebbee64cfabfbcea8 @workmad3 workmad3 committed 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)
@@ -86,6 +86,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 a7fad65

Please sign in to comment.