Class: RSpecExtensionsCollection::Matchers::SearchMatcher

Inherits:
Object
  • Object
show all
Includes:
MongoidModelHelpers
Defined in:
lib/rspec_extensions_collection/matchers/search_matcher.rb

Direct Known Subclasses

SearchEmbeddedMatcher

Constant Summary collapse

KEYWORD =
"temp"
FIELD_CONTENT_WITH_KEYWORD =
"This contains the keyword #{KEYWORD} and something else."
FIELD_CONTENT_WITHOUT_KEYWORD =
"Used for some data."
LOCALES =
["en", "fr"]

Instance Method Summary collapse

Methods included from MongoidModelHelpers

#execute_query_to_models

Constructor Details

#initialize(*args) ⇒ SearchMatcher



28
29
30
31
32
33
# File 'lib/rspec_extensions_collection/matchers/search_matcher.rb', line 28

def initialize(*args)
  if args.try(:last).instance_of?(Hash)
    @locale = args.pop[:locale]
  end    
  @fields = args
end

Instance Method Details

#failure_message_for_shouldObject



43
44
45
# File 'lib/rspec_extensions_collection/matchers/search_matcher.rb', line 43

def failure_message_for_should
  "expected #{@model_class} to find #{@matching_models} but got #{execute_query_to_models(@search_result)}"
end

#matches?(model_class) ⇒ Boolean



35
36
37
38
39
40
41
# File 'lib/rspec_extensions_collection/matchers/search_matcher.rb', line 35

def matches?(model_class)
  @model_class = model_class
  @model_class.delete_all
  create_models
  @search_result = execute
  execute_query_to_models(@search_result.asc(:_id)) == @matching_models
end