Skip to content

Instantly share code, notes, and snippets.

@MarkBennett
Created July 11, 2011 18:45
Show Gist options
  • Select an option

  • Save MarkBennett/1076500 to your computer and use it in GitHub Desktop.

Select an option

Save MarkBennett/1076500 to your computer and use it in GitHub Desktop.
RSpec matcher for table indexes
# Playlist.should be_indexed_on([:name])
RSpec::Matchers.define :be_indexed_on do |expected|
match do |actual|
indexes = ActiveRecord::Base.connection.indexes(actual.table_name)
expected.map!(&:to_s)
indexes.map { |index| index.columns.map(&:to_s) }.include?(expected)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment