Skip to content

Commit 01fbdb3

Browse files
committed
Fix a NoMethodError schema_statements.rb
If you call `remove_index` with wrong options, say a type, like I did, you get: ``` == 20160810072541 RemoveUniqueIndexOnGoals: migrating ========================= -- remove_index(:goal, {:coulmn=>:kid_id, :unique=>true}) rails aborted! StandardError: An error has occurred, this and all later migrations canceled: undefined method `ArgumentError' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter:0x007fb7dec91b28> ``` What happened is that I mistyped column (coulmn) and got a `NoMethodError`, because of a missing comma during the raise. This made Ruby think we're calling the method `ArgumentError`.
1 parent 7b31b06 commit 01fbdb3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ def index_name_for_remove(table_name, options = {})
12081208
checks << lambda { |i| i.columns.join("_and_") == column_names.join("_and_") }
12091209
end
12101210

1211-
raise ArgumentError "No name or columns specified" if checks.none?
1211+
raise ArgumentError, "No name or columns specified" if checks.none?
12121212

12131213
matching_indexes = indexes(table_name).select { |i| checks.all? { |check| check[i] } }
12141214

activerecord/test/cases/adapters/postgresql/active_schema_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ def test_remove_index_when_name_is_specified
8181
assert_equal expected, remove_index(:people, name: "index_people_on_last_name", algorithm: :concurrently)
8282
end
8383

84+
def test_remove_index_with_wrong_option
85+
assert_raises ArgumentError do
86+
remove_index(:people, coulmn: :last_name)
87+
end
88+
end
89+
8490
private
8591
def method_missing(method_symbol, *arguments)
8692
ActiveRecord::Base.connection.send(method_symbol, *arguments)

0 commit comments

Comments
 (0)