From bff177f3e2a3486d28f1b1d42bda96f0488e2f05 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 23 Mar 2010 22:33:53 -0700 Subject: [PATCH] log messages read like valid ruby driver code --- lib/mongo/collection.rb | 12 ++++++------ lib/mongo/cursor.rb | 4 ++-- test/connection_test.rb | 2 +- test/unit/collection_test.rb | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 68fd053..b27623c 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -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 diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index a235998..02255ce 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -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 diff --git a/test/connection_test.rb b/test/connection_test.rb index 4a9312c..d107aad 100644 --- a/test/connection_test.rb +++ b/test/connection_test.rb @@ -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 diff --git a/test/unit/collection_test.rb b/test/unit/collection_test.rb index 4e9b184..aa44d38 100644 --- a/test/unit/collection_test.rb +++ b/test/unit/collection_test.rb @@ -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