diff --git a/lib/mongo/util/bson.rb b/lib/mongo/util/bson.rb index 107dec8..e262ff0 100644 --- a/lib/mongo/util/bson.rb +++ b/lib/mongo/util/bson.rb @@ -87,7 +87,7 @@ class BSON while @buf.more? type = @buf.get case type - when STRING + when STRING, CODE key = deserialize_element_name(@buf) doc[key] = deserialize_string_data(@buf) when NUMBER diff --git a/tests/test_bson.rb b/tests/test_bson.rb index f3c9431..d2d96a2 100644 --- a/tests/test_bson.rb +++ b/tests/test_bson.rb @@ -10,7 +10,13 @@ class BSONTest < Test::Unit::TestCase end def test_object_encoding - doc = {'doc' => {'age' => 41.2, 'name' => 'Spongebob'}} + doc = {'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}} + @b.serialize(doc) + assert_equal doc, @b.deserialize + end + + def test_code_encoding + doc = {'$where' => 'this.a.b < this.b'} @b.serialize(doc) assert_equal doc, @b.deserialize end