Class: SunspotMatchers::HaveSearchableField

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot_matchers/matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(field) ⇒ HaveSearchableField



324
325
326
# File 'lib/sunspot_matchers/matchers.rb', line 324

def initialize(field)
  @field = field
end

Instance Method Details

#descriptionObject



334
335
336
# File 'lib/sunspot_matchers/matchers.rb', line 334

def description
  "should have searchable field #{@field}"
end

#failure_message_for_shouldObject



338
339
340
341
# File 'lib/sunspot_matchers/matchers.rb', line 338

def failure_message_for_should
  message = "expected class: #{@klass} to have searchable field: #{@field}"
  message << ", but Sunspot was not configured on #{@klass}" unless @sunspot
end

#failure_message_for_should_notObject



343
344
345
# File 'lib/sunspot_matchers/matchers.rb', line 343

def failure_message_for_should_not
  "expected class: #{@klass} NOT to have searchable field: #{@field}"
end

#matches?(klass_or_object) ⇒ Boolean



328
329
330
331
332
# File 'lib/sunspot_matchers/matchers.rb', line 328

def matches?(klass_or_object)
  @klass = klass_or_object.class.name == 'Class' ? klass_or_object : klass_or_object.class
  @sunspot = Sunspot::Setup.for(@klass)
  @sunspot && (@sunspot.all_text_fields + @sunspot.fields).collect(&:name).include?(@field)
end