class Mongoid::Matchers::HaveIndexMatcher
Attributes
attrs[R]
klass[R]
Public Class Methods
new(*attrs)
click to toggle source
# File lib/matchers/document/have_index.rb, line 13 def initialize *attrs @attrs = attrs.map(&:to_sym) end
Public Instance Methods
description()
click to toggle source
# File lib/matchers/document/have_index.rb, line 30 def description "have an index for #{attrs.inspect}" end
failure_message()
click to toggle source
# File lib/matchers/document/have_index.rb, line 22 def failure_message "#{klass} to #{description}, but only found indexes #{indexes.inspect}" end
matches?(subject)
click to toggle source
# File lib/matchers/document/have_index.rb, line 17 def matches? subject @klass = class_of subject index_options.any? { |idx, _| idx.keys == attrs } end
negative_failure_message()
click to toggle source
# File lib/matchers/document/have_index.rb, line 26 def negative_failure_message "#{klass} to not #{description}, but found an index for #{attrs.inspect}" end
Private Instance Methods
index_options()
click to toggle source
# File lib/matchers/document/have_index.rb, line 36 def index_options if Mongoid::VERSION.to_i < 4 klass.index_options else Hash[klass.index_specifications.map{ |i| [i.key, i.options] }] end end
indexes()
click to toggle source
# File lib/matchers/document/have_index.rb, line 44 def indexes index_options.keys.map(&:keys) end