Skip to content

Commit

Permalink
Ensure that plucky is not destructive with array of id inputs.
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
jnunemaker committed Apr 20, 2012
1 parent 186c279 commit 0dd54de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/plucky/criteria_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -145,4 +145,4 @@ def normalized_value(parent_key, key, value)
end
end
end
end
end
9 changes: 7 additions & 2 deletions test/plucky/test_criteria_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -347,4 +352,4 @@ class CriteriaHashTest < Test::Unit::TestCase
end
end
end
end
end

0 comments on commit 0dd54de

Please sign in to comment.