Merge branch 'master' of git://github.com/jimm/mongo-ruby-driver

This commit is contained in:
Adrian Madrid 2009-01-05 14:32:30 -07:00
commit fbe3a12317
6 changed files with 21 additions and 13 deletions

View File

@ -22,7 +22,7 @@ module XGen
@buf = ByteBuffer.new
@buf.put_int(16) # holder for length
@buf.put_int(@@class_req_id += 1)
@buf.put_int(@request_id)
@buf.put_int(0) # response_to
@buf.put_int(op)
end

View File

@ -5,6 +5,8 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class BSONTest < Test::Unit::TestCase
include XGen::Mongo::Driver
def setup
@b = BSON.new
end
@ -40,7 +42,7 @@ class BSONTest < Test::Unit::TestCase
end
def test_oid
doc = {'doc' => XGen::Mongo::Driver::ObjectID.new}
doc = {'doc' => ObjectID.new}
@b.serialize(doc)
assert_equal doc, @b.deserialize
end

View File

@ -5,10 +5,12 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class DBAPITest < Test::Unit::TestCase
include XGen::Mongo::Driver
def setup
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
@db = Mongo.new(host, port).db('ruby-mongo-test')
@coll = @db.collection('test')
@coll.clear
@r1 = @coll.insert('a' => 1) # collection not created until it's used

View File

@ -5,10 +5,12 @@ require 'test/unit'
# NOTE: assumes Mongo is running
class DBConnectionTest < Test::Unit::TestCase
include XGen::Mongo::Driver
def test_no_exceptions
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-demo')
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
db = Mongo.new(host, port).db('ruby-mongo-demo')
coll = db.collection('test')
coll.clear
end

View File

@ -4,15 +4,17 @@ require 'test/unit'
class MessageTest < Test::Unit::TestCase
include XGen::Mongo::Driver
def setup
@msg = XGen::Mongo::Driver::Message.new(42)
@msg = Message.new(42)
end
def test_initial_info
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE, @msg.buf.length
assert_equal Message::HEADER_SIZE, @msg.buf.length
@msg.write_long(1029)
@msg.buf.rewind
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE + 8, @msg.buf.get_int
assert_equal Message::HEADER_SIZE + 8, @msg.buf.get_int
@msg.buf.get_int # skip message id
assert_equal 0, @msg.buf.get_int
assert_equal 42, @msg.buf.get_int
@ -22,12 +24,12 @@ class MessageTest < Test::Unit::TestCase
def test_update_length
@msg.update_message_length
@msg.buf.rewind
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE, @msg.buf.get_int
assert_equal Message::HEADER_SIZE, @msg.buf.get_int
end
def test_long_length
@msg.write_long(1027)
assert_equal XGen::Mongo::Driver::Message::HEADER_SIZE + 8, @msg.buf.length
assert_equal Message::HEADER_SIZE + 8, @msg.buf.length
end
end

View File

@ -53,8 +53,8 @@ class ObjectIDTest < Test::Unit::TestCase
def test_save_and_restore
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
db = Mongo.new(host, port).db('ruby-mongo-test')
coll = db.collection('test')
coll.clear