Class: Mongoid::Matchers::HaveIndexMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/matchers/document/have_index.rb

Instance Method Summary collapse

Methods included from Helpers

#class_of, #to_sentence

Constructor Details

#initialize(*fields) ⇒ HaveIndexMatcher

Returns a new instance of HaveIndexMatcher.



4
5
6
# File 'lib/matchers/document/have_index.rb', line 4

def initialize(*fields)
  @fields = fields.map(&:to_sym)
end

Instance Method Details

#descriptionObject



23
24
25
# File 'lib/matchers/document/have_index.rb', line 23

def description
  "have an index for #{@fields.inspect}"
end

#failure_messageObject



15
16
17
# File 'lib/matchers/document/have_index.rb', line 15

def failure_message
  "#{@klass} to #{description}, but only found indexes #{indexes.inspect}"
end

#indexesObject



27
28
29
# File 'lib/matchers/document/have_index.rb', line 27

def indexes
  @klass.index_options.keys.map(&:keys)
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
# File 'lib/matchers/document/have_index.rb', line 8

def matches?(subject)
  @klass = class_of(subject)
  @klass.index_options.any? do |index, options|
    index.keys == @fields
  end
end

#negative_failure_messageObject



19
20
21
# File 'lib/matchers/document/have_index.rb', line 19

def negative_failure_message
  "#{@klass} to not #{description}, but found an index for #{@fields.inspect}"
end