log messages read like valid ruby driver code

This commit is contained in:
Kyle Banker 2010-03-23 22:33:53 -07:00
parent bca5daa87b
commit bff177f3e2
4 changed files with 13 additions and 13 deletions

View File

@ -265,13 +265,13 @@ module Mongo
if opts[:safe]
@connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name,
"db.#{@db.name}.remove(#{selector.inspect})")
"#{@db.name}['#{@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
true
else
@connection.send_message(Mongo::Constants::OP_DELETE, message,
"db.#{@db.name}.remove(#{selector.inspect})")
"#{@db.name}['#{@name}'].remove(#{selector.inspect})")
end
end
@ -307,10 +307,10 @@ module Mongo
message.put_array(BSON.serialize(document, false, true).to_a)
if options[:safe]
@connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
"#{@db.name}['#{@name}'].update(#{selector.inspect}, #{document.inspect})")
else
@connection.send_message(Mongo::Constants::OP_UPDATE, message,
"db.#{@name}.update(#{selector.inspect}, #{document.inspect})")
"#{@db.name}['#{@name}'].update(#{selector.inspect}, #{document.inspect})")
end
end
@ -634,10 +634,10 @@ module Mongo
documents.each { |doc| message.put_array(BSON.serialize(doc, check_keys, true).to_a) }
if safe
@connection.send_message_with_safe_check(Mongo::Constants::OP_INSERT, message, @db.name,
"db.#{collection_name}.insert(#{documents.inspect})")
"#{@db.name}['#{collection_name}'].insert(#{documents.inspect})")
else
@connection.send_message(Mongo::Constants::OP_INSERT, message,
"db.#{collection_name}.insert(#{documents.inspect})")
"#{@db.name}['#{collection_name}'].insert(#{documents.inspect})")
end
documents.collect { |o| o[:_id] || o['_id'] }
end

View File

@ -230,7 +230,7 @@ module Mongo
message = ByteBuffer.new([0, 0, 0, 0])
message.put_int(1)
message.put_long(@cursor_id)
@connection.send_message(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close()")
@connection.send_message(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close")
end
@cursor_id = 0
@closed = true
@ -362,7 +362,7 @@ module Mongo
end
def query_log_message
"#{@admin ? 'admin' : @db.name}.#{@collection.name}.find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
"#{@admin ? 'admin' : @db.name}['#{@collection.name}'].find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}" +
"#{@order ? ('.sort(' + @order.inspect + ')') : ''}"
end

View File

@ -93,7 +93,7 @@ class TestConnection < Test::Unit::TestCase
logger = Logger.new(output)
logger.level = Logger::DEBUG
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
assert output.string.include?("admin.$cmd.find")
assert output.string.include?("admin['$cmd'].find")
end
def test_connection_logger

View File

@ -12,7 +12,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message).with do |op, msg, log|
op == 2001 && log.include?("db.books.update")
op == 2001 && log.include?("testing['books'].update")
end
@coll.update({}, {:title => 'Moby Dick'})
end
@ -22,7 +22,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message).with do |op, msg, log|
op == 2002 && log.include?("db.books.insert")
op == 2002 && log.include?("testing['books'].insert")
end
@coll.insert({:title => 'Moby Dick'})
end
@ -53,7 +53,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
op == 2001 && log.include?("db.books.update")
op == 2001 && log.include?("testing['books'].update")
end
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
end
@ -63,7 +63,7 @@ class CollectionTest < Test::Unit::TestCase
@db = @conn['testing']
@coll = @db.collection('books')
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
op == 2001 && log.include?("db.books.update")
op == 2001 && log.include?("testing['books'].update")
end
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
end