Class: Mongoid::Matchers::HaveIndexMatcher
- Defined in:
- lib/matchers/document/have_index.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #indexes ⇒ Object
-
#initialize(*fields) ⇒ HaveIndexMatcher
constructor
A new instance of HaveIndexMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods included from Helpers
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
#description ⇒ Object
23 24 25 |
# File 'lib/matchers/document/have_index.rb', line 23 def description "have an index for #{@fields.inspect}" end |
#failure_message ⇒ Object
15 16 17 |
# File 'lib/matchers/document/have_index.rb', line 15 def "#{@klass} to #{description}, but only found indexes #{indexes.inspect}" end |
#indexes ⇒ Object
27 28 29 |
# File 'lib/matchers/document/have_index.rb', line 27 def indexes @klass..keys.map(&:keys) end |
#matches?(subject) ⇒ Boolean
8 9 10 11 12 13 |
# File 'lib/matchers/document/have_index.rb', line 8 def matches?(subject) @klass = class_of(subject) @klass..any? do |index, | index.keys == @fields end end |
#negative_failure_message ⇒ Object
19 20 21 |
# File 'lib/matchers/document/have_index.rb', line 19 def "#{@klass} to not #{description}, but found an index for #{@fields.inspect}" end |