minor: Initial collection unit tests. Logging message update.

This commit is contained in:
Kyle Banker 2009-11-02 15:50:16 -05:00
parent 95f3686119
commit 68bb1d2060
3 changed files with 38 additions and 2 deletions

View File

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

View File

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

View File

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