Permalink
Browse files

Raise an ArgumentError when passing an invalid option to add_index

Closes #8104
  • Loading branch information...
1 parent 48a7a26 commit 8fc52706c376be03f644e847d1dd357fc88ead6f @rafaelfranca rafaelfranca committed Nov 2, 2012
@@ -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*
@@ -617,11 +617,14 @@ def options_include_default?(options)
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
@@ -91,6 +91,12 @@ def test_index_exists_on_multiple_columns
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

0 comments on commit 8fc5270

Please sign in to comment.