Skip to content

Commit

Permalink
Simple fix for correctly inverting an add_index migration when a name…
Browse files Browse the repository at this point in the history
… has been provided
  • Loading branch information
workmad3 authored and tenderlove committed Aug 22, 2011
1 parent 5ec3430 commit 54866b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions activerecord/lib/active_record/migration/command_recorder.rb
Expand Up @@ -79,8 +79,12 @@ def invert_rename_column(args)
end end


def invert_add_index(args) def invert_add_index(args)
table, columns, _ = *args table, columns, options = *args
[:remove_index, [table, {:column => columns}]] if options && options[:name]
[:remove_index, [table, {:name => options[:name]}]]
else
[:remove_index, [table, {:column => columns}]]
end
end end


def invert_remove_timestamps(args) def invert_remove_timestamps(args)
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/migration/command_recorder_test.rb
Expand Up @@ -91,6 +91,12 @@ def test_invert_add_index
assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove
end 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 def test_invert_rename_index
@recorder.record :rename_index, [:old, :new] @recorder.record :rename_index, [:old, :new]
rename = @recorder.inverse.first rename = @recorder.inverse.first
Expand Down

0 comments on commit 54866b0

Please sign in to comment.