From 0f0c0e569d067418c6bd48d9128d851718aa5cf5 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 22 Oct 2009 16:12:42 -0500 Subject: [PATCH] minor: test for duplicate _id (as string and symbol) --- test/test_bson.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/test_bson.rb b/test/test_bson.rb index 786c72d..5dfd682 100644 --- a/test/test_bson.rb +++ b/test/test_bson.rb @@ -265,4 +265,18 @@ class BSONTest < Test::Unit::TestCase assert val.keys.include?(:_id) end + # note we only test for _id here because in the general case we will + # write duplicates for :key and "key". _id is a special case because + # we call has_key? to check for it's existance rather than just iterating + # over it like we do for the rest of the keys. thus, things like + # HashWithIndifferentAccess can cause problems for _id but not for other + # keys. rather than require rails to test with HWIA directly, we do this + # somewhat hacky test. + def test_no_duplicate_id + dup = {"_id" => "foo", :_id => "foo"} + one = {"_id" => "foo"} + + assert_equal @b.serialize(one).to_a, @b.serialize(dup).to_a + end + end