Skip to content

Commit 25579fc

Browse files
committed
Fix index_exists? to handle empty columns argument
1 parent 9caf1d7 commit 25579fc

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def column_options
4848
end
4949

5050
def defined_for?(columns = nil, name: nil, unique: nil, valid: nil, **options)
51-
columns = options[:column] if columns.nil?
51+
columns = options[:column] if columns.blank?
5252
(columns.nil? || Array(self.columns) == Array(columns).map(&:to_s)) &&
5353
(name.nil? || self.name == name.to_s) &&
5454
(unique.nil? || self.unique == unique) &&

activerecord/test/cases/migration/index_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def test_index_exists_on_multiple_columns
172172
def test_index_exists_with_custom_name_checks_columns
173173
connection.add_index :testings, [:foo, :bar], name: "my_index"
174174
assert connection.index_exists?(:testings, [:foo, :bar], name: "my_index")
175+
assert connection.index_exists?(:testings, [], name: "my_index")
175176
assert_not connection.index_exists?(:testings, [:foo], name: "my_index")
176177
end
177178

0 commit comments

Comments
 (0)