Permalink
Browse files

Ensure that plucky is not destructive with array of id inputs.

Fixes #15
  • Loading branch information...
1 parent 186c279 commit 0dd54de6ac39b9fddb7f341d01ba4c205faa50f1 @jnunemaker jnunemaker committed Apr 20, 2012
Showing with 9 additions and 4 deletions.
  1. +2 −2 lib/plucky/criteria_hash.rb
  2. +7 −2 test/plucky/test_criteria_hash.rb
@@ -122,7 +122,7 @@ def normalized_value(parent_key, key, value)
case value
when Array, Set
if object_id?(parent_key)
- value.map! { |v| Plucky.to_object_id(v) }
+ value.map { |v| Plucky.to_object_id(v) }
elsif NestingOperators.include?(key)
value.map { |v| CriteriaHash.new(v, options).to_hash }
elsif parent_key == key
@@ -145,4 +145,4 @@ def normalized_value(parent_key, key, value)
end
end
end
-end
+end
@@ -260,12 +260,17 @@ class CriteriaHashTest < Test::Unit::TestCase
setup do
@id1 = BSON::ObjectId.new
@id2 = BSON::ObjectId.new
- @criteria = CriteriaHash.new({:_id => {'$in' => [@id1.to_s, @id2.to_s]}}, :object_ids => [:_id])
+ @ids = [@id1.to_s, @id2.to_s]
+ @criteria = CriteriaHash.new({:_id => {'$in' => @ids}}, :object_ids => [:_id])
end
should "convert strings to object ids" do
@criteria[:_id].should == {'$in' => [@id1, @id2]}
end
+
+ should "not modify original array of string ids" do
+ @ids.should == [@id1.to_s, @id2.to_s]
+ end
end
context "#merge" do
@@ -347,4 +352,4 @@ class CriteriaHashTest < Test::Unit::TestCase
end
end
end
-end
+end

0 comments on commit 0dd54de

Please sign in to comment.