aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Workman <workmad3@gmail.com>2011-05-23 13:54:38 +0100
committerDavid Workman <workmad3@gmail.com>2011-05-23 13:54:51 +0100
commita7fad65792b37a3f8643149ebbee64cfabfbcea8 (patch)
tree8c9ab94295acd823b0d3ac9f0c65a13df991f2d5
parenta8b2a895b795b02805a6d6478f7a8c55035e19d4 (diff)
downloadrails-a7fad65792b37a3f8643149ebbee64cfabfbcea8.tar.gz
rails-a7fad65792b37a3f8643149ebbee64cfabfbcea8.tar.bz2
rails-a7fad65792b37a3f8643149ebbee64cfabfbcea8.zip
Simple fix for correctly inverting an add_index migration when a name has been provided
-rw-r--r--activerecord/lib/active_record/migration/command_recorder.rb8
-rw-r--r--activerecord/test/cases/migration/command_recorder_test.rb6
2 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/migration/command_recorder.rb b/activerecord/lib/active_record/migration/command_recorder.rb
index c9d57ce812..5f4dd798a7 100644
--- a/activerecord/lib/active_record/migration/command_recorder.rb
+++ b/activerecord/lib/active_record/migration/command_recorder.rb
@@ -79,8 +79,12 @@ module ActiveRecord
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)
diff --git a/activerecord/test/cases/migration/command_recorder_test.rb b/activerecord/test/cases/migration/command_recorder_test.rb
index ae531ebb4c..3e404eaf70 100644
--- a/activerecord/test/cases/migration/command_recorder_test.rb
+++ b/activerecord/test/cases/migration/command_recorder_test.rb
@@ -86,6 +86,12 @@ module ActiveRecord
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