Skip to content
Browse files

Merge branch 'master' of github.com:jnunemaker/plucky

Conflicts:
	test/plucky/test_criteria_hash.rb
  • Loading branch information...
2 parents fd0661e + 76dc51b commit 45937f4446fb6d6d57e512dbbc61951359146358 @jnunemaker jnunemaker committed
Showing with 11 additions and 1 deletion.
  1. +5 −1 lib/plucky/criteria_hash.rb
  2. +6 −0 spec/plucky/criteria_hash_spec.rb
View
6 lib/plucky/criteria_hash.rb
@@ -55,7 +55,11 @@ def merge(other)
if value_is_hash && other_is_hash
value.update(other_value) do |key, old_value, new_value|
- Array(old_value).concat(Array(new_value)).uniq
+ if old_value.is_a?(Hash) && new_value.is_a?(Hash)
+ self.class.new(old_value).merge(self.class.new(new_value)).to_hash
+ else
+ Array(old_value).concat(Array(new_value)).uniq
+ end
end
elsif value_is_hash && !other_is_hash
if modifier_key = value.keys.detect { |k| k.to_s[0, 1] == '$' }
View
6 spec/plucky/criteria_hash_spec.rb
@@ -306,6 +306,12 @@
c1.merge(c2).should == described_class.new('$in' => [1, 2, 3])
end
+ it "is able to merge two modifier hashes with hash values" do
+ c1 = CriteriaHash.new(:arr => {'$elemMatch' => {:foo => 'bar'}})
+ c2 = CriteriaHash.new(:arr => {'$elemMatch' => {:omg => 'ponies'}})
+ c1.merge(c2).should == CriteriaHash.new(:arr => {'$elemMatch' => {:foo => 'bar', :omg => 'ponies'}})
+ end
+
it "merges matching keys with a single modifier" do
c1 = described_class.new(:foo => {'$in' => [1, 2, 3]})
c2 = described_class.new(:foo => {'$in' => [1, 4, 5]})

0 comments on commit 45937f4

Please sign in to comment.
Something went wrong with that request. Please try again.