module ThoughtBot::Shoulda::ActiveRecord::Macros
def should_have_indices(*columns)
should_have_index :age
should_have_indices :email, :name, [:commentable_type, :commentable_id]
Also aliased to should_have_index for readability
Ensures that there are DB indices on the given columns or tuples of columns.
def should_have_indices(*columns) table = model_class.table_name indices = ::ActiveRecord::Base.connection.indexes(table).map(&:columns) columns.each do |column| should "have index on #{table} for #{column.inspect}" do columns = [column].flatten.map(&:to_s) assert_contains(indices, columns) end end end