From 7da51cc31720bd5cddbcb0dfeb56a6218f5ec4ff Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Tue, 28 Jul 2009 12:08:29 -0400 Subject: [PATCH] save returns _id as well --- lib/mongo/collection.rb | 1 + tests/test_db_api.rb | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 9d2c54c..7e63fa0 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -77,6 +77,7 @@ module XGen def save(object) if id = object[:_id] || object['_id'] repsert({:_id => id}, object) + id else insert(object) end diff --git a/tests/test_db_api.rb b/tests/test_db_api.rb index 39b8f5e..18d6ada 100644 --- a/tests/test_db_api.rb +++ b/tests/test_db_api.rb @@ -48,7 +48,7 @@ class DBAPITest < Test::Unit::TestCase def test_insert_multiple ids = @@coll.insert({'a' => 2}, {'b' => 3}) - + ids.each do |i| assert_kind_of ObjectID, i end @@ -619,10 +619,11 @@ class DBAPITest < Test::Unit::TestCase a = {"hello" => "world"} - assert_kind_of ObjectID, @@coll.save(a) + id = @@coll.save(a) + assert_kind_of ObjectID, id assert_equal 1, @@coll.count - @@coll.save(@@coll.find_first) + assert_equal id, @@coll.save(@@coll.find_first) assert_equal 1, @@coll.count assert_equal "world", @@coll.find_first()["hello"]