From 9627908bc10a672d090452bf68078cbf776818f5 Mon Sep 17 00:00:00 2001 From: Jim Menard Date: Tue, 9 Dec 2008 13:00:14 -0500 Subject: [PATCH 1/2] to-do item --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 1d14de3..35f5839 100644 --- a/README +++ b/README @@ -52,6 +52,9 @@ type = To Do +* Tests that prove that this driver's ObjectID and Geir's Java version do the + same thing. + * Capped collection support. * Implement order_by (right now, sort order is ignored) From 6c481c617d77151a92af5118732afbdbc5f05411 Mon Sep 17 00:00:00 2001 From: Jim Menard Date: Tue, 9 Dec 2008 13:48:38 -0500 Subject: [PATCH 2/2] Fixed BSON (de)serialization of object ids. New test that saves/restores oid to the database. --- lib/mongo/util/bson.rb | 11 ++--------- tests/test_objectid.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/mongo/util/bson.rb b/lib/mongo/util/bson.rb index 8f866fb..82af042 100644 --- a/lib/mongo/util/bson.rb +++ b/lib/mongo/util/bson.rb @@ -184,10 +184,7 @@ class BSON end def deserialize_oid_data(buf) - high_bytes = buf.get_long - low_bytes = buf.get_int - hexval = (high_bytes << 32) + low_bytes - XGen::Mongo::Driver::ObjectID.new('%012x' % hexval) + XGen::Mongo::Driver::ObjectID.new(buf.get(12)) end def serialize_eoo_element(buf) @@ -254,11 +251,7 @@ class BSON buf.put(OID) self.class.serialize_cstr(buf, key) - hexval = val.to_s.hex - high_bytes = hexval >> 32 - low_bytes = hexval && 0xffffffff - buf.put_long(high_bytes) - buf.put_int(low_bytes) + buf.put_array(val.to_a) end def serialize_string_element(buf, key, val, type) diff --git a/tests/test_objectid.rb b/tests/test_objectid.rb index d32e319..37bf306 100644 --- a/tests/test_objectid.rb +++ b/tests/test_objectid.rb @@ -51,4 +51,18 @@ class ObjectIDTest < Test::Unit::TestCase assert_equal 24, $1.length end + def test_save_and_restore + host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost' + port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT + db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test') + coll = db.collection('test') + + coll.clear + coll << {'a' => 1, '_id' => @o} + + row = coll.find().collect.first + assert_equal 1, row['a'] + assert_equal @o, row['_id'] + end + end