Guest User

Untitled

a guest
Jul 11th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. # thinking_sphinx_macros.rb in test/shoulda_macros
  2. def should_be_thinking_sphinxed(options = {})
  3. klass = self.to_s.scan(/(.*)Test/).flatten.first.constantize || options[:klass]
  4. fields = Array(options[:fields])
  5. attributes = Array(options[:attributes])
  6.  
  7. should "be indexed by ThinkingSphinx" do
  8. assert ThinkingSphinx.indexed_models.include?(klass.to_s), "class #{klass} is not indexed"
  9. end
  10.  
  11. unless options[:fields].blank?
  12. indexed_fields = klass.sphinx_indexes[0].fields.map(&:unique_name)
  13.  
  14. options[:fields].each do |field|
  15. should "have indexed field #{field}" do
  16. assert indexed_fields.include?(field), "field #{field} is not indexed"
  17. end
  18. end
  19. end
  20.  
  21. unless options[:attributes].blank?
  22. indexed_attributes = klass.sphinx_indexes[0].attributes.map(&:unique_name)
  23.  
  24. options[:attributes].each do |attribute|
  25. should "have indexed attribute #{attribute}" do
  26. assert indexed_attributes.include?(attribute), "attribute #{attribute} is not indexed"
  27. end
  28. end
  29. end
  30. end
Add Comment
Please, Sign In to add comment