Skip to content

Commit

Permalink
Merge pull request #1229 from workmad3/master
Browse files Browse the repository at this point in the history
Fix for Issue #1205
  • Loading branch information
tenderlove committed May 27, 2011
2 parents 985ace4 + 06436b2 commit 2a9b3ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions activerecord/lib/active_record/migration/command_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ def invert_rename_column(args)
end

def invert_add_index(args)
table, columns, _ = *args
[:remove_index, [table, {:column => columns}]]
table, columns, options = *args
index_name = options.try(:[], :name)
options_hash = index_name ? {:name => index_name} : {:column => columns}
[:remove_index, [table, options_hash]]
end

def invert_remove_timestamps(args)
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/migration/command_recorder_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ 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_add_index_with_no_options
@recorder.record :add_index, [:table, [:one, :two]]
remove = @recorder.inverse.first
assert_equal [:remove_index, [:table, {:column => [:one, :two]}]], remove
end

def test_invert_rename_index
@recorder.record :rename_index, [:old, :new]
rename = @recorder.inverse.first
Expand Down

0 comments on commit 2a9b3ab

Please sign in to comment.