aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-02 18:58:27 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-11-02 19:00:58 -0200
commit8fc52706c376be03f644e847d1dd357fc88ead6f (patch)
tree90d5ba3565ef3b125144b5c65111930f2cb19cbe /activerecord
parent48a7a261c2e461ecab738d061c31a7dece699d97 (diff)
downloadrails-8fc52706c376be03f644e847d1dd357fc88ead6f.tar.gz
rails-8fc52706c376be03f644e847d1dd357fc88ead6f.tar.bz2
rails-8fc52706c376be03f644e847d1dd357fc88ead6f.zip
Raise an ArgumentError when passing an invalid option to add_index
Closes #8104
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb5
-rw-r--r--activerecord/test/cases/migration/index_test.rb6
3 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 1d43840573..da149dac54 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Raise an `ArgumentError` when passing an invalid option to `add_index`.
+
+ *Rafael Mendonça França*
+
* Fix `find_in_batches` crashing when IDs are strings and start option is not specified.
*Alexis Bernard*
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 8790518d37..a606a5c775 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -617,11 +617,14 @@ module ActiveRecord
def add_index_options(table_name, column_name, options = {})
column_names = Array(column_name)
- index_name = index_name(table_name, :column => column_names)
+ index_name = index_name(table_name, column: column_names)
if Hash === options # legacy support, since this param was a string
+ options.assert_valid_keys(:unique, :order, :name, :where, :length)
+
index_type = options[:unique] ? "UNIQUE" : ""
index_name = options[:name].to_s if options.key?(:name)
+
if supports_partial_index?
index_options = options[:where] ? " WHERE #{options[:where]}" : ""
end
diff --git a/activerecord/test/cases/migration/index_test.rb b/activerecord/test/cases/migration/index_test.rb
index dd9492924c..bfa275fee2 100644
--- a/activerecord/test/cases/migration/index_test.rb
+++ b/activerecord/test/cases/migration/index_test.rb
@@ -91,6 +91,12 @@ module ActiveRecord
assert connection.index_exists?(:testings, [:foo, :bar])
end
+ def test_valid_index_options
+ assert_raise ArgumentError do
+ connection.add_index :testings, :foo, unqiue: true
+ end
+ end
+
def test_unique_index_exists
connection.add_index :testings, :foo, :unique => true