Class: SunspotMatchers::HaveSearchableField
- Inherits:
-
Object
- Object
- SunspotMatchers::HaveSearchableField
- Defined in:
- lib/sunspot_matchers/matchers.rb
Direct Known Subclasses
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #fields_to_match ⇒ Object
-
#initialize(field) ⇒ HaveSearchableField
constructor
A new instance of HaveSearchableField.
- #matches?(klass_or_object) ⇒ Boolean
- #sunspot ⇒ Object
Constructor Details
#initialize(field) ⇒ HaveSearchableField
Returns a new instance of HaveSearchableField.
329 330 331 |
# File 'lib/sunspot_matchers/matchers.rb', line 329 def initialize(field) @field = field end |
Instance Method Details
#description ⇒ Object
338 339 340 |
# File 'lib/sunspot_matchers/matchers.rb', line 338 def description "have searchable field '#{@field}'" end |
#failure_message ⇒ Object
342 343 344 345 |
# File 'lib/sunspot_matchers/matchers.rb', line 342 def = "expected class: #{@klass} to have searchable field: #{@field}" << ", but Sunspot was not configured on #{@klass}" unless @sunspot end |
#failure_message_when_negated ⇒ Object
347 348 349 |
# File 'lib/sunspot_matchers/matchers.rb', line 347 def "expected class: #{@klass} NOT to have searchable field: #{@field}" end |
#fields_to_match ⇒ Object
355 356 357 |
# File 'lib/sunspot_matchers/matchers.rb', line 355 def fields_to_match (sunspot.all_text_fields + sunspot.fields).collect(&:name) end |
#matches?(klass_or_object) ⇒ Boolean
333 334 335 336 |
# File 'lib/sunspot_matchers/matchers.rb', line 333 def matches?(klass_or_object) @klass = klass_or_object.class.name == 'Class' ? klass_or_object : klass_or_object.class sunspot && fields_to_match.include?(@field) end |
#sunspot ⇒ Object
351 352 353 |
# File 'lib/sunspot_matchers/matchers.rb', line 351 def sunspot @sunspot ||= Sunspot::Setup.for(@klass) end |