prismicio-community / ruby-kit

Community maintained development kit for Prismic and the Ruby language
https://prismic.io
Apache License 2.0
45 stars 35 forks source link

Predicates ignored when a form AND predicates are used #6

Closed rudyrigot closed 10 years ago

rudyrigot commented 10 years ago

Basically, when you write something like: @api.create_search_form("products").query(%([[:d = any(document.tags, ["Cupcake", "Macaron"])]])).submit(@master_ref).size.should == 11 the query method is simply ignored (all the documents matching the form are returned no matter what additional predicates are submitted inside query).

The origin is the same problem described in issue #3 of the JS kit, simply the two kits react differently:

I'm waiting for the answer on how to handle it in JS to fix it here the same way; I'm working on it on a branch I've only pushed on my GitHub fork so far, and I've written it as a test that fails for now, as it should (the test works by calling the real LesBonnesChoses API, to make sure it's happening in the real world).

rudyrigot commented 10 years ago

Note: when either a form OR predicates are used, everything works fine, of course (I've created tests for that too on my branch).

dohzya commented 10 years ago

The set SearchForm#set method handle a Hash, but some values are stored in an array. It looks like this:

{
  'param1' => 'val1',
  'param2' => ['val2a', 'val2b'],
}

This syntax is understood by the HTTP lib which transforms it into param1=val1&param2=val2a&param2=valb

However, there were a problem with SearchForm initialization, that I fixed with 7c422ef34e06d210372e918f0badbd99a273c985

I let you close the issue if this commit fixed it :-)

rudyrigot commented 10 years ago

Awesome man! All my tests pass!

I just pushed this commit, that introduces a lesbonneschoses_spec.rb that tests on the actual Les Bonnes Choses API, since this is how I had written the failing test that now passes. If you want to add to it at some point, you now know it's there. Thanks man!

rudyrigot commented 10 years ago

This commit ;)

sadache commented 10 years ago

But still error report is wrong if there is a mistake in one of the predicates.

On Sat, Nov 23, 2013 at 8:19 PM, Rudy Rigot notifications@github.comwrote:

This commithttps://github.com/prismicio/ruby-kit/commit/59977f05680fa01d47d8f862a56353c3e6e07d5f;)

— Reply to this email directly or view it on GitHubhttps://github.com/prismicio/ruby-kit/issues/6#issuecomment-29139420 .

http://sadache.tumblr.com ʎdoɹʇuǝ

rudyrigot commented 10 years ago

Not sure I understand, I didn't test errors in predicates in this one; we do need to test them though, but as Etienne was saying this weeks, the Ruby kit does need a bit more tests to be written globally.