test fixes for move to bson gem
This commit is contained in:
parent
1e8e0c02fe
commit
63b0dfc6c9
@ -37,7 +37,6 @@ require 'mongo/connection'
|
|||||||
require 'mongo/cursor'
|
require 'mongo/cursor'
|
||||||
require 'mongo/db'
|
require 'mongo/db'
|
||||||
require 'mongo/exceptions'
|
require 'mongo/exceptions'
|
||||||
require 'mongo/gridfs'
|
|
||||||
require 'mongo/gridfs/grid'
|
require 'mongo/gridfs/grid'
|
||||||
require 'mongo/gridfs/grid_io'
|
require 'mongo/gridfs/grid_io'
|
||||||
require 'mongo/gridfs/grid_file_system'
|
require 'mongo/gridfs/grid_file_system'
|
||||||
|
@ -229,7 +229,7 @@ module Mongo
|
|||||||
# @return [Mongo::Collection]
|
# @return [Mongo::Collection]
|
||||||
def collection(name)
|
def collection(name)
|
||||||
return Collection.new(self, name, @pk_factory) if !strict? || collection_names.include?(name)
|
return Collection.new(self, name, @pk_factory) if !strict? || collection_names.include?(name)
|
||||||
raise MongoDBError, "Collection #{name} doesn't exist. Currently in strict mode."
|
raise Mongo::MongoDBError, "Collection #{name} doesn't exist. Currently in strict mode."
|
||||||
end
|
end
|
||||||
alias_method :[], :collection
|
alias_method :[], :collection
|
||||||
|
|
||||||
@ -325,8 +325,8 @@ module Mongo
|
|||||||
#
|
#
|
||||||
# @return [String] the return value of the function.
|
# @return [String] the return value of the function.
|
||||||
def eval(code, *args)
|
def eval(code, *args)
|
||||||
if not code.is_a? Code
|
if not code.is_a? BSON::Code
|
||||||
code = Code.new(code)
|
code = BSON::Code.new(code)
|
||||||
end
|
end
|
||||||
|
|
||||||
oh = OrderedHash.new
|
oh = OrderedHash.new
|
||||||
|
@ -7,6 +7,7 @@ require 'thread'
|
|||||||
class TestConnection < Test::Unit::TestCase
|
class TestConnection < Test::Unit::TestCase
|
||||||
|
|
||||||
include Mongo
|
include Mongo
|
||||||
|
include BSON
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||||
@ -31,12 +32,12 @@ class TestConnection < Test::Unit::TestCase
|
|||||||
def test_invalid_database_names
|
def test_invalid_database_names
|
||||||
assert_raise TypeError do @mongo.db(4) end
|
assert_raise TypeError do @mongo.db(4) end
|
||||||
|
|
||||||
assert_raise InvalidName do @mongo.db('') end
|
assert_raise Mongo::InvalidName do @mongo.db('') end
|
||||||
assert_raise InvalidName do @mongo.db('te$t') end
|
assert_raise Mongo::InvalidName do @mongo.db('te$t') end
|
||||||
assert_raise InvalidName do @mongo.db('te.t') end
|
assert_raise Mongo::InvalidName do @mongo.db('te.t') end
|
||||||
assert_raise InvalidName do @mongo.db('te\\t') end
|
assert_raise Mongo::InvalidName do @mongo.db('te\\t') end
|
||||||
assert_raise InvalidName do @mongo.db('te/t') end
|
assert_raise Mongo::InvalidName do @mongo.db('te/t') end
|
||||||
assert_raise InvalidName do @mongo.db('te st') end
|
assert_raise Mongo::InvalidName do @mongo.db('te st') end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_database_info
|
def test_database_info
|
||||||
|
@ -29,8 +29,8 @@ class DBAPITest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_insert
|
def test_insert
|
||||||
assert_kind_of ObjectID, @@coll.insert('a' => 2)
|
assert_kind_of BSON::ObjectID, @@coll.insert('a' => 2)
|
||||||
assert_kind_of ObjectID, @@coll.insert('b' => 3)
|
assert_kind_of BSON::ObjectID, @@coll.insert('b' => 3)
|
||||||
|
|
||||||
assert_equal 3, @@coll.count
|
assert_equal 3, @@coll.count
|
||||||
docs = @@coll.find().to_a
|
docs = @@coll.find().to_a
|
||||||
@ -62,7 +62,7 @@ class DBAPITest < Test::Unit::TestCase
|
|||||||
ids = @@coll.insert([{'a' => 2}, {'b' => 3}])
|
ids = @@coll.insert([{'a' => 2}, {'b' => 3}])
|
||||||
|
|
||||||
ids.each do |i|
|
ids.each do |i|
|
||||||
assert_kind_of ObjectID, i
|
assert_kind_of BSON::ObjectID, i
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal 3, @@coll.count
|
assert_equal 3, @@coll.count
|
||||||
@ -413,7 +413,7 @@ class DBAPITest < Test::Unit::TestCase
|
|||||||
@@db.collection('does-not-exist')
|
@@db.collection('does-not-exist')
|
||||||
fail "expected exception"
|
fail "expected exception"
|
||||||
rescue => ex
|
rescue => ex
|
||||||
assert_equal MongoDBError, ex.class
|
assert_equal Mongo::MongoDBError, ex.class
|
||||||
assert_equal "Collection does-not-exist doesn't exist. Currently in strict mode.", ex.to_s
|
assert_equal "Collection does-not-exist doesn't exist. Currently in strict mode.", ex.to_s
|
||||||
ensure
|
ensure
|
||||||
@@db.strict = false
|
@@db.strict = false
|
||||||
@ -433,7 +433,7 @@ class DBAPITest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Now the collection exists. This time we should see an exception.
|
# Now the collection exists. This time we should see an exception.
|
||||||
assert_raise MongoDBError do
|
assert_raise Mongo::MongoDBError do
|
||||||
@@db.create_collection('foobar')
|
@@db.create_collection('foobar')
|
||||||
end
|
end
|
||||||
@@db.strict = false
|
@@db.strict = false
|
||||||
@ -680,19 +680,19 @@ class DBAPITest < Test::Unit::TestCase
|
|||||||
assert_raise TypeError do
|
assert_raise TypeError do
|
||||||
@@db.collection(5)
|
@@db.collection(5)
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
@@db.collection("")
|
@@db.collection("")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
@@db.collection("te$t")
|
@@db.collection("te$t")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
@@db.collection(".test")
|
@@db.collection(".test")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
@@db.collection("test.")
|
@@db.collection("test.")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
@@db.collection("tes..t")
|
@@db.collection("tes..t")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -706,19 +706,19 @@ class DBAPITest < Test::Unit::TestCase
|
|||||||
assert_raise TypeError do
|
assert_raise TypeError do
|
||||||
a.rename(5)
|
a.rename(5)
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
a.rename("")
|
a.rename("")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
a.rename("te$t")
|
a.rename("te$t")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
a.rename(".test")
|
a.rename(".test")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
a.rename("test.")
|
a.rename("test.")
|
||||||
end
|
end
|
||||||
assert_raise InvalidName do
|
assert_raise Mongo::InvalidName do
|
||||||
a.rename("tes..t")
|
a.rename("tes..t")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ require 'logger'
|
|||||||
|
|
||||||
class TestPKFactory
|
class TestPKFactory
|
||||||
def create_pk(row)
|
def create_pk(row)
|
||||||
row['_id'] ||= Mongo::ObjectID.new
|
row['_id'] ||= BSON::ObjectID.new
|
||||||
row
|
row
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -101,7 +101,7 @@ class DBTest < Test::Unit::TestCase
|
|||||||
assert_not_nil oid
|
assert_not_nil oid
|
||||||
assert_equal insert_id, oid
|
assert_equal insert_id, oid
|
||||||
|
|
||||||
oid = ObjectID.new
|
oid = BSON::ObjectID.new
|
||||||
data = {'_id' => oid, 'name' => 'Barney', 'age' => 41}
|
data = {'_id' => oid, 'name' => 'Barney', 'age' => 41}
|
||||||
coll.insert(data)
|
coll.insert(data)
|
||||||
row = coll.find_one({'name' => data['name']})
|
row = coll.find_one({'name' => data['name']})
|
||||||
|
@ -9,7 +9,7 @@ class BinaryTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
should "not display actual data" do
|
should "not display actual data" do
|
||||||
binary = BSON::Binary.new(@data)
|
binary = BSON::Binary.new(@data)
|
||||||
assert_equal "<Mongo::Binary:#{binary.object_id}>", binary.inspect
|
assert_equal "<BSON::Binary:#{binary.object_id}>", binary.inspect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -272,7 +272,7 @@ class BSONTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_binary_byte_buffer
|
def test_binary_byte_buffer
|
||||||
bb = ByteBuffer.new
|
bb = Binary.new
|
||||||
5.times { |i| bb.put(i + 1) }
|
5.times { |i| bb.put(i + 1) }
|
||||||
|
|
||||||
doc = {'bin' => bb}
|
doc = {'bin' => bb}
|
||||||
|
Loading…
Reference in New Issue
Block a user