class Mongoid::Matchers::HaveIndexFor
Public Class Methods
new(index_key)
click to toggle source
# File lib/matchers/have_index_for.rb, line 8 def initialize(index_key) @index_key = index_key.symbolize_keys end
Public Instance Methods
description()
click to toggle source
# File lib/matchers/have_index_for.rb, line 40 def description "have an index #{index_description(expected_index)}" end
failure_message()
click to toggle source
# File lib/matchers/have_index_for.rb, line 26 def failure_message message = "Expected #{@model.inspect} to #{description}," if actual_index.nil? message << " found no index" else message << " got #{index_description(actual_index)}" end message end
failure_message_when_negated()
click to toggle source
# File lib/matchers/have_index_for.rb, line 36 def failure_message_when_negated "Expected #{@model.inspect} to not #{description}, got #{index_description(actual_index)}" end
matches?(actual)
click to toggle source
# File lib/matchers/have_index_for.rb, line 17 def matches?(actual) @model = actual.is_a?(Class) ? actual : actual.class actual_index && expected_index.key == actual_index.key && expected_index.fields == actual_index.fields && (expected_index.options.to_a - actual_index.options.to_a).empty? end
with_options(index_options)
click to toggle source
# File lib/matchers/have_index_for.rb, line 12 def with_options(index_options) @index_options = index_options self end
Private Instance Methods
actual_index()
click to toggle source
# File lib/matchers/have_index_for.rb, line 58 def actual_index @actual_index ||= @model.index_specification(expected_index.key) end
expected_index()
click to toggle source
# File lib/matchers/have_index_for.rb, line 53 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/have_index_for.rb, line 46 def index_description(index) desc = "#{index.key.inspect}" desc << " for fields #{index.fields.inspect}" if index.fields.present? desc << " including options #{index.options.inspect}" if index.options.present? desc end