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