2009-11-02 20:50:16 +00:00
|
|
|
require 'test/test_helper'
|
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
class CollectionTest < Test::Unit::TestCase
|
2009-11-02 20:50:16 +00:00
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
context "Basic operations: " do
|
|
|
|
setup do
|
|
|
|
@logger = mock()
|
2009-11-02 20:50:16 +00:00
|
|
|
end
|
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
should "send update message" do
|
|
|
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
|
|
|
@db = @conn['testing']
|
|
|
|
@coll = @db.collection('books')
|
|
|
|
@conn.expects(:send_message).with do |op, msg, log|
|
2010-03-24 05:33:53 +00:00
|
|
|
op == 2001 && log.include?("testing['books'].update")
|
2010-02-22 20:49:04 +00:00
|
|
|
end
|
|
|
|
@coll.update({}, {:title => 'Moby Dick'})
|
2009-11-02 20:50:16 +00:00
|
|
|
end
|
2009-11-05 20:14:48 +00:00
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
should "send insert message" do
|
|
|
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
|
|
|
@db = @conn['testing']
|
|
|
|
@coll = @db.collection('books')
|
|
|
|
@conn.expects(:send_message).with do |op, msg, log|
|
2010-03-24 05:33:53 +00:00
|
|
|
op == 2002 && log.include?("testing['books'].insert")
|
2010-02-22 20:49:04 +00:00
|
|
|
end
|
|
|
|
@coll.insert({:title => 'Moby Dick'})
|
2010-02-08 18:48:18 +00:00
|
|
|
end
|
|
|
|
|
2010-03-15 15:51:22 +00:00
|
|
|
should "send sort data" do
|
|
|
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
|
|
|
@db = @conn['testing']
|
|
|
|
@coll = @db.collection('books')
|
|
|
|
@conn.expects(:receive_message).with do |op, msg, log, sock|
|
|
|
|
op == 2004 && log.include?("sort")
|
|
|
|
end.returns([[], 0, 0])
|
|
|
|
@coll.find({:title => 'Moby Dick'}).sort([['title', 1], ['author', 1]]).next_document
|
|
|
|
end
|
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
should "not log binary data" do
|
|
|
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
|
|
|
@db = @conn['testing']
|
|
|
|
@coll = @db.collection('books')
|
|
|
|
data = Mongo::Binary.new(("BINARY " * 1000).unpack("c*"))
|
|
|
|
@conn.expects(:send_message).with do |op, msg, log|
|
|
|
|
op == 2002 && log.include?("Mongo::Binary")
|
|
|
|
end
|
|
|
|
@coll.insert({:data => data})
|
|
|
|
end
|
|
|
|
|
|
|
|
should "send safe update message" do
|
|
|
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
|
|
|
@db = @conn['testing']
|
|
|
|
@coll = @db.collection('books')
|
|
|
|
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
2010-03-24 05:33:53 +00:00
|
|
|
op == 2001 && log.include?("testing['books'].update")
|
2010-02-22 20:49:04 +00:00
|
|
|
end
|
|
|
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
2009-11-05 20:14:48 +00:00
|
|
|
end
|
|
|
|
|
2010-02-22 20:49:04 +00:00
|
|
|
should "send safe insert message" do
|
|
|
|
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
|
|
|
|
@db = @conn['testing']
|
|
|
|
@coll = @db.collection('books')
|
|
|
|
@conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
|
2010-03-24 05:33:53 +00:00
|
|
|
op == 2001 && log.include?("testing['books'].update")
|
2010-02-22 20:49:04 +00:00
|
|
|
end
|
|
|
|
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
|
2009-11-05 20:14:48 +00:00
|
|
|
end
|
2009-11-02 20:50:16 +00:00
|
|
|
end
|
|
|
|
end
|