diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 359945a..508ccbc 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -395,7 +395,7 @@ module Mongo end def query_log_message - "db.#{@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 + ')') : ''}" end diff --git a/test/test_connection.rb b/test/test_connection.rb index a047ee0..03dfb7c 100644 --- a/test/test_connection.rb +++ b/test/test_connection.rb @@ -72,7 +72,7 @@ class TestConnection < Test::Unit::TestCase logger.level = Logger::DEBUG db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test') - assert output.string.include?("2004") + assert output.string.include?("$cmd.find") end def test_connection_logger diff --git a/test/unit/collection_test.rb b/test/unit/collection_test.rb new file mode 100644 index 0000000..cb1b792 --- /dev/null +++ b/test/unit/collection_test.rb @@ -0,0 +1,36 @@ +require 'test/test_helper' + +class CollectionTest < Test::Unit::TestCase + + class MockDB < DB + def connect_to_master + true + end + end + + context "Basic operations: " do + setup do + @logger = mock() + end + + should "send update message" do + @db = MockDB.new("testing", ['localhost', 27017], :logger => @logger) + @coll = @db.collection('books') + @db.expects(:send_message_with_operation).with do |op, msg, log| + op == 2001 && log.include?("db.books.update") + end + @coll.update({}, {:title => 'Moby Dick'}) + end + + should "send insert message" do + @db = MockDB.new("testing", ['localhost', 27017], :logger => @logger) + @coll = @db.collection('books') + @db.expects(:send_message_with_operation).with do |op, msg, log| + op == 2002 && log.include?("db.books.insert") + end + @coll.insert({:title => 'Moby Dick'}) + end + end +end + +