Permalink
Browse files

Merge pull request #14 from jmchambers/master

added support for new $and operator by preventing wrapping with $in
  • Loading branch information...
2 parents 1f33a46 + 85f5a6b commit 8b5b3a50d9f84f5a9f91dc05ef7ca74dc55c6c7c @jnunemaker jnunemaker committed Aug 18, 2011
Showing with 4 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 lib/plucky/criteria_hash.rb
  3. +2 −1 test/plucky/test_criteria_hash.rb
View
@@ -1,3 +1,4 @@
+*.project
log
*.gem
Gemfile.lock
@@ -120,7 +120,7 @@ def normalized_value(parent_key, key, value)
case value
when Array, Set
value.map! { |v| Plucky.to_object_id(v) } if object_id?(parent_key)
- parent_key == key && key != :$or ? {'$in' => value.to_a} : value.to_a
+ parent_key == key && ![:$or, :$and].include?(key) ? {'$in' => value.to_a} : value.to_a
when Time
value.utc
when String
@@ -151,8 +151,9 @@ class CriteriaHashTest < Test::Unit::TestCase
CriteriaHash.new(:numbers => {'$any' => [1,2,3]})[:numbers].should == {'$any' => [1,2,3]}
end
- should "not turn value to $in with $or key" do
+ should "not turn value to $in with $or or $and key" do
CriteriaHash.new(:$or => [{:numbers => 1}, {:numbers => 2}] )[:$or].should == [{:numbers=>1}, {:numbers=>2}]
+ CriteriaHash.new(:$and => [{:numbers => 1}, {:numbers => 2}] )[:$and].should == [{:numbers=>1}, {:numbers=>2}]
end
end

0 comments on commit 8b5b3a5

Please sign in to comment.