class Mongoid::Matchers::HaveIndexFor
Constants
- MAPPINGS
Public Instance Methods
description()
click to toggle source
# File lib/matchers/indexes/v3/have_index_for.rb, line 38 def description desc = "have an index for #{index_key.inspect}" desc << " with options of #{index_options.inspect}" if index_options desc end
failure_message_for_should()
click to toggle source
# File lib/matchers/indexes/v3/have_index_for.rb, line 27 def failure_message_for_should "Expected #{model.inspect} to #{description}, got #{@errors.to_sentence}" end
Also aliased as: failure_message
failure_message_for_should_not()
click to toggle source
# File lib/matchers/indexes/v3/have_index_for.rb, line 31 def failure_message_for_should_not "Expected #{model.inspect} to not #{description}, got #{model.inspect} to #{description}" end
Also aliased as: failure_message_when_negated
matches?(klass)
click to toggle source
# File lib/matchers/indexes/v3/have_index_for.rb, line 8 def matches?(klass) @model = klass.is_a?(Class) ? klass : klass.class @errors = [] if model.index_options[index_key] if !index_options.nil? && !index_options.empty? index_options.each do |option, option_value| if denormalising_options(model.index_options[index_key])[option] != option_value @errors.push "index for #{index_key.inspect} with options of #{model.index_options[index_key].inspect}" end end end else @errors.push "no index for #{index_key}" end @errors.empty? end
Private Instance Methods
actual_index()
click to toggle source
# File lib/matchers/indexes/v4/have_index_for.rb, line 49 def actual_index @actual_index ||= model.index_specification(expected_index.key) end
denormalising_options(opts)
click to toggle source
# File lib/matchers/indexes/v3/have_index_for.rb, line 50 def denormalising_options(opts) options = {} opts.each_pair do |option, value| options[MAPPINGS[option] || option] = value end options end
expected_index()
click to toggle source
# File lib/matchers/indexes/v4/have_index_for.rb, line 44 def expected_index @expected_index ||= Mongoid::Indexable::Specification.new(model, index_key, index_options) end
index_description(index)
click to toggle source
# File lib/matchers/indexes/v4/have_index_for.rb, line 37 def index_description(index) desc = index.key.inspect.to_s desc << " for fields #{index.fields.inspect}" if index.fields.present? desc << " including options #{index.options.inspect}" if index.options.present? desc end