mongo-ruby-driver/test/unit/collection_test.rb

53 lines
1.7 KiB
Ruby
Raw Normal View History

require 'test/test_helper'
class ConnectionTest < Test::Unit::TestCase
2009-12-16 19:03:15 +00:00
context "Basic operations: " do
setup do
@logger = mock()
end
2009-12-16 19:03:15 +00:00
should "send update message" do
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
@db = @conn['testing']
@coll = @db.collection('books')
2009-12-16 19:03:15 +00:00
@conn.expects(:send_message).with do |op, msg, log|
op == 2001 && log.include?("db.books.update")
end
@coll.update({}, {:title => 'Moby Dick'})
end
2009-12-16 19:03:15 +00:00
should "send insert message" do
@conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
@db = @conn['testing']
@coll = @db.collection('books')
2009-12-16 19:03:15 +00:00
@conn.expects(:send_message).with do |op, msg, log|
op == 2002 && log.include?("db.books.insert")
end
@coll.insert({:title => 'Moby Dick'})
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|
op == 2001 && log.include?("db.books.update")
end
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
end
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|
op == 2001 && log.include?("db.books.update")
end
@coll.update({}, {:title => 'Moby Dick'}, :safe => true)
end
end
end
2009-12-16 19:03:15 +00:00