Skip to content

Commit

Permalink
Merge pull request rails#26688 from kamipo/remove_respond_to_indexes
Browse files Browse the repository at this point in the history
Remove unnecessary `respond_to?(:indexes)` checking
  • Loading branch information
kaspth authored Oct 28, 2016
2 parents 3f2046f + 444cf0d commit 86bf5ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1199,10 +1199,6 @@ def quoted_columns_for_index(column_names, **options)
def index_name_for_remove(table_name, options = {})
return options[:name] if can_remove_index_by_name?(options)

# if the adapter doesn't support the indexes call the best we can do
# is return the default index name for the options provided
return index_name(table_name, options) unless respond_to?(:indexes)

checks = []

if options.is_a?(Hash)
Expand Down
23 changes: 9 additions & 14 deletions activerecord/test/cases/adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,15 @@ def test_data_source_exists?
def test_indexes
idx_name = "accounts_idx"

if @connection.respond_to?(:indexes)
indexes = @connection.indexes("accounts")
assert indexes.empty?

@connection.add_index :accounts, :firm_id, name: idx_name
indexes = @connection.indexes("accounts")
assert_equal "accounts", indexes.first.table
assert_equal idx_name, indexes.first.name
assert !indexes.first.unique
assert_equal ["firm_id"], indexes.first.columns
else
warn "#{@connection.class} does not respond to #indexes"
end

indexes = @connection.indexes("accounts")
assert indexes.empty?

@connection.add_index :accounts, :firm_id, name: idx_name
indexes = @connection.indexes("accounts")
assert_equal "accounts", indexes.first.table
assert_equal idx_name, indexes.first.name
assert !indexes.first.unique
assert_equal ["firm_id"], indexes.first.columns
ensure
@connection.remove_index(:accounts, name: idx_name) rescue nil
end
Expand Down

0 comments on commit 86bf5ad

Please sign in to comment.