fixed bug on safe remove; style fixes

This commit is contained in:
Kyle Banker 2010-02-17 16:48:23 -05:00
parent f176a45a20
commit 5d1d110280
4 changed files with 14 additions and 4 deletions

View File

@ -264,7 +264,7 @@ module Mongo
message.put_array(BSON.serialize(selector, false).to_a)
if opts[:safe]
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message,
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name,
"db.#{@db.name}.remove(#{selector.inspect})")
# the return value of send_message_with_safe_check isn't actually meaningful --
# only the fact that it didn't raise an error is -- so just return true

View File

@ -152,10 +152,11 @@ module Mongo
chunk['n'] = n
chunk['files_id'] = @files_id
chunk['data'] = ''
@chunk_position = 0
@chunk_position = 0
chunk
end
# TODO: Perhaps use an upsert here instead?
def save_chunk(chunk)
@chunks.remove('_id' => chunk['_id'])
@chunks.insert(chunk)

View File

@ -191,7 +191,7 @@ class TestCollection < Test::Unit::TestCase
end
end
def test_safe_remove
def test_mocked_safe_remove
@conn = Connection.new
@db = @conn['mongo-ruby-test']
@test = @db['test-safe-remove']
@ -204,6 +204,15 @@ class TestCollection < Test::Unit::TestCase
@test.drop
end
def test_safe_remove
@conn = Connection.new
@db = @conn['mongo-ruby-test']
@test = @db['test-safe-remove']
@test.save({:a => 50})
@test.remove({}, :safe => true)
@test.drop
end
def test_count
@@test.drop

View File

@ -204,8 +204,8 @@ class DBTest < Test::Unit::TestCase
def test_user_management
@@db.add_user("bob", "secret")
@@db.logout
assert @@db.authenticate("bob", "secret")
@@db.logout
assert @@db.remove_user("bob")
assert !@@db.authenticate("bob", "secret")
end