vmware-archive / sunspot_matchers

RSpec matchers for testing Sunspot searches

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem specifying some matchers

medihack opened this issue · comments

Hi. I have problem to describe some matcher. Maybe you could help me here.

with(:tag_ids).all_of([3, 7])
sunspot.should have_search_params(:with, :tag_ids, [3, 7]) 
# also not working
sunspot.should have_search_params(:with, :tag_ids, Proc.new {
    all_of do
      with :tag_ids, 3
      with :tag_ids, 7
    end
  })

not sure how to get that all_of in there

keywords "foo", :fields => [:name]
sunspot.should have_search_params(:keywords, "foo", :fields => [:name])

doesn't work .. not sure how to specify :fields here

sunspot.should_not have_search_params(:order_by, any_param, any_param)

any_param doesn't seem to work here. I just want to check that order_by was not called in the last search at all.

Ok, I figured out 2 of the 3 problems (solutions below if someone ever has the same problem).

The one that remains:

sunspot.should_not have_search_params(:order_by, any_param, any_param)

I get an error that says No field configured for Grid with name 'ANY_PARAM'
So I switched to:

sunspot.should_not have_search_params(:order_by, :name, any_param)

and get Unknown sort direction ANY_PARAM. Acceptable input is: :ascending, :asc, :descending, :desc

So how could I check if "order_by" was not called at all?

Here the solutions for the two other matcher:

sunspot.should have_search_params(:keywords, Proc.new {
  keywords "Mer", :fields => :name
})

sunspot.should have_search_params(:with, Proc.new {
  with(:tag_ids).all_of([3, 7])
})

Currently it doesn't support any_param for :order_by matches.

Looking at it, it does seem a bit more tricky than where any_param is currently supported, but I think it is doable. I'll try to get it done in the next day or two.

Do you think it would be useful to use any_param for both field and direction, or are you mostly looking for field?

Just release a new version that supports any_param for either the field, or the direction of an order_by.

Thank you Joseph.