save returns _id as well

This commit is contained in:
Mike Dirolf 2009-07-28 12:08:29 -04:00
parent ddf7fdf6a2
commit 7da51cc317
2 changed files with 5 additions and 3 deletions

View File

@ -77,6 +77,7 @@ module XGen
def save(object)
if id = object[:_id] || object['_id']
repsert({:_id => id}, object)
id
else
insert(object)
end

View File

@ -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"]