My search controller does this:
search = Sunspot.search(Item) do
fulltext params[:q] do
fields(:foo, :bar, :bletch)
end
end
And in my rspec controller test I have the following:
get :show, :q => q
expect(Sunspot.session).to have_search_params(:fulltext, q, proc do
fields(:foo, :bar, :bletch)
end)
Side note: when I tried using a block instead of a proc, the block was never executed:
have_search_params(:fulltext, q) do
# This block was never executed
end
My support/sunspot.rb contains only the following:
Sunspot.session = SunspotMatchers::SunspotSessionSpy.new(Sunspot.session)
When I run the test, I get the following error:
1) SearchController GET search when a user runs a search performs a fulltext search on the right fields
Failure/Error: fields(:foo, :bar, :bletch)
NoMethodError:
undefined method `fields' for #<Sunspot::DSL::Search:0x007fa0f0da0168>
# ./spec/controllers/search_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
# ./spec/controllers/search_controller_spec.rb:27:in `block (4 levels) in <top (required)>'
What's the right way to test that my controller is supplying the correct params when doing a fulltext search? Google yields no relevant results when querying this problem.
Aucun commentaire:
Enregistrer un commentaire