Made tests that were different same as upstream
This commit is contained in:
parent
3aac974f13
commit
0550945aa4
|
@ -1,5 +1,4 @@
|
||||||
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
||||||
|
|
||||||
require 'mongo'
|
require 'mongo'
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
|
||||||
|
@ -12,7 +11,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
||||||
@coll = @db.collection('test')
|
@coll = @db.collection('test')
|
||||||
@coll.clear
|
@coll.clear
|
||||||
@r1 = @coll.insert('_id' => new_oid, 'a' => 1) # collection not created until it's used
|
@r1 = @coll.insert('a' => 1) # collection not created until it's used
|
||||||
@coll_full_name = 'ruby-mongo-test.test'
|
@coll_full_name = 'ruby-mongo-test.test'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -27,8 +26,8 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_insert
|
def test_insert
|
||||||
@coll.insert('_id' => new_oid, 'a' => 2)
|
@coll.insert('a' => 2)
|
||||||
@coll.insert('_id' => new_oid, 'b' => 3)
|
@coll.insert('b' => 3)
|
||||||
|
|
||||||
assert_equal 3, @coll.count
|
assert_equal 3, @coll.count
|
||||||
docs = @coll.find().collect
|
docs = @coll.find().collect
|
||||||
|
@ -43,30 +42,14 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
assert docs.detect { |row| row['b'] == 4 }
|
assert docs.detect { |row| row['b'] == 4 }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inserted_id
|
|
||||||
doc = @coll.find().collect.first
|
|
||||||
assert_equal @r1['_id'], doc['_id']
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_find_simple
|
def test_find_simple
|
||||||
@r2 = @coll.insert('_id' => new_oid, 'a' => 2)
|
@r2 = @coll.insert('a' => 2)
|
||||||
@r3 = @coll.insert('_id' => new_oid, 'b' => 3)
|
@r3 = @coll.insert('b' => 3)
|
||||||
# Check sizes
|
# Check sizes
|
||||||
docs = @coll.find().map
|
docs = @coll.find().map
|
||||||
assert_equal 3, docs.size
|
assert_equal 3, docs.size
|
||||||
assert_equal 3, @coll.count
|
assert_equal 3, @coll.count
|
||||||
# Find by id
|
|
||||||
docs = @coll.find('_id' => @r1['_id']).map
|
|
||||||
assert_equal 1, docs.size
|
|
||||||
doc = docs.first
|
|
||||||
assert_equal doc['_id'], @r1['_id']
|
|
||||||
assert_equal doc['a'], @r1['a']
|
|
||||||
# Find by id (same id again)
|
|
||||||
docs = @coll.find('_id' => @r1['_id']).map
|
|
||||||
assert_equal 1, docs.size
|
|
||||||
doc = docs.first
|
|
||||||
assert_equal doc['_id'], @r1['_id']
|
|
||||||
assert_equal doc['a'], @r1['a']
|
|
||||||
# Find by other value
|
# Find by other value
|
||||||
docs = @coll.find('a' => @r1['a']).map
|
docs = @coll.find('a' => @r1['a']).map
|
||||||
assert_equal 1, docs.size
|
assert_equal 1, docs.size
|
||||||
|
@ -76,8 +59,8 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_find_advanced
|
def test_find_advanced
|
||||||
@r2 = @coll.insert('_id' => new_oid, 'a' => 2)
|
@coll.insert('a' => 2)
|
||||||
@r3 = @coll.insert('_id' => new_oid, 'b' => 3)
|
@coll.insert('b' => 3)
|
||||||
|
|
||||||
# Find by advanced query (less than)
|
# Find by advanced query (less than)
|
||||||
docs = @coll.find('a' => { '$lt' => 10 }).map
|
docs = @coll.find('a' => { '$lt' => 10 }).map
|
||||||
|
@ -151,8 +134,6 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
assert_equal 2, docs.first['a']
|
assert_equal 2, docs.first['a']
|
||||||
end
|
end
|
||||||
|
|
||||||
# def test_
|
|
||||||
|
|
||||||
def test_close
|
def test_close
|
||||||
@db.close
|
@db.close
|
||||||
assert @db.socket.closed?
|
assert @db.socket.closed?
|
||||||
|
@ -218,6 +199,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
@db.create_index(@coll.name, 'index_name', ['a'])
|
@db.create_index(@coll.name, 'index_name', ['a'])
|
||||||
list = @db.index_information(@coll.name)
|
list = @db.index_information(@coll.name)
|
||||||
assert_equal 1, list.length
|
assert_equal 1, list.length
|
||||||
|
|
||||||
info = list[0]
|
info = list[0]
|
||||||
assert_equal 'index_name', info[:name]
|
assert_equal 'index_name', info[:name]
|
||||||
assert_equal 1, info[:keys]['a']
|
assert_equal 1, info[:keys]['a']
|
||||||
|
@ -284,9 +266,4 @@ class DBAPITest < Test::Unit::TestCase
|
||||||
assert @db.master?
|
assert @db.master?
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def new_oid
|
|
||||||
XGen::Mongo::Driver::ObjectID.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class DBConnectionTest < Test::Unit::TestCase
|
||||||
def test_no_exceptions
|
def test_no_exceptions
|
||||||
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||||
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
|
||||||
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
|
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-demo')
|
||||||
coll = db.collection('test')
|
coll = db.collection('test')
|
||||||
coll.clear
|
coll.clear
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue