RUBY-118
This commit is contained in:
parent
fc1edd215e
commit
2e78eb6c66
4
Rakefile
4
Rakefile
@ -100,11 +100,11 @@ namespace :test do
|
||||
|
||||
task :drop_databases do |t|
|
||||
puts "Dropping test database..."
|
||||
require File.join(File.dirname(__FILE__), 'lib', 'mongo')
|
||||
require File.join(File.dirname(__FILE__), 'test', 'test_helper')
|
||||
include Mongo
|
||||
con = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
|
||||
con.drop_database('ruby-mongo-test')
|
||||
con.drop_database(MONGO_TEST_DB)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -2,7 +2,7 @@ require 'test/test_helper'
|
||||
|
||||
class TestCollection < Test::Unit::TestCase
|
||||
@@connection ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
|
||||
@@db = @@connection.db('ruby-mongo-test')
|
||||
@@db = @@connection.db(MONGO_TEST_DB)
|
||||
@@test = @@db.collection("test")
|
||||
@@version = @@connection.server_version
|
||||
|
||||
@ -18,7 +18,7 @@ class TestCollection < Test::Unit::TestCase
|
||||
|
||||
# Create a db with a pk_factory.
|
||||
@db = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test', :pk => Object.new)
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db(MONGO_TEST_DB, :pk => Object.new)
|
||||
@coll = @db.collection('coll-with-pk')
|
||||
assert @coll.pk_factory.is_a?(Object)
|
||||
|
||||
@ -192,7 +192,7 @@ class TestCollection < Test::Unit::TestCase
|
||||
|
||||
def test_mocked_safe_remove
|
||||
@conn = Connection.new
|
||||
@db = @conn['mongo-ruby-test']
|
||||
@db = @conn[MONGO_TEST_DB]
|
||||
@test = @db['test-safe-remove']
|
||||
@test.save({:a => 20})
|
||||
@conn.stubs(:receive).returns([[{'ok' => 0, 'err' => 'failed'}], 1, 0])
|
||||
@ -205,7 +205,7 @@ class TestCollection < Test::Unit::TestCase
|
||||
|
||||
def test_safe_remove
|
||||
@conn = Connection.new
|
||||
@db = @conn['mongo-ruby-test']
|
||||
@db = @conn[MONGO_TEST_DB]
|
||||
@test = @db['test-safe-remove']
|
||||
@test.save({:a => 50})
|
||||
@test.remove({}, :safe => true)
|
||||
|
@ -16,7 +16,7 @@ class TestConnection < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def teardown
|
||||
@mongo.db('ruby-mongo-test').error
|
||||
@mongo.db(MONGO_TEST_DB).error
|
||||
end
|
||||
|
||||
def test_server_info
|
||||
@ -41,16 +41,16 @@ class TestConnection < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_database_info
|
||||
@mongo.drop_database('ruby-mongo-info-test')
|
||||
@mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
|
||||
@mongo.drop_database(MONGO_TEST_DB)
|
||||
@mongo.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
|
||||
|
||||
info = @mongo.database_info
|
||||
assert_not_nil info
|
||||
assert_kind_of Hash, info
|
||||
assert_not_nil info['ruby-mongo-info-test']
|
||||
assert info['ruby-mongo-info-test'] > 0
|
||||
assert_not_nil info[MONGO_TEST_DB]
|
||||
assert info[MONGO_TEST_DB] > 0
|
||||
|
||||
@mongo.drop_database('ruby-mongo-info-test')
|
||||
@mongo.drop_database(MONGO_TEST_DB)
|
||||
end
|
||||
|
||||
def test_copy_database
|
||||
@ -79,21 +79,21 @@ class TestConnection < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_database_names
|
||||
@mongo.drop_database('ruby-mongo-info-test')
|
||||
@mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
|
||||
@mongo.drop_database(MONGO_TEST_DB)
|
||||
@mongo.db(MONGO_TEST_DB).collection('info-test').insert('a' => 1)
|
||||
|
||||
names = @mongo.database_names
|
||||
assert_not_nil names
|
||||
assert_kind_of Array, names
|
||||
assert names.length >= 1
|
||||
assert names.include?('ruby-mongo-info-test')
|
||||
assert names.include?(MONGO_TEST_DB)
|
||||
end
|
||||
|
||||
def test_logging
|
||||
output = StringIO.new
|
||||
logger = Logger.new(output)
|
||||
logger.level = Logger::DEBUG
|
||||
db = Connection.new(@host, @port, :logger => logger).db('ruby-mongo-test')
|
||||
db = Connection.new(@host, @port, :logger => logger).db(MONGO_TEST_DB)
|
||||
assert output.string.include?("admin['$cmd'].find")
|
||||
end
|
||||
|
||||
@ -175,7 +175,7 @@ class TestConnection < Test::Unit::TestCase
|
||||
context "Connection exceptions" do
|
||||
setup do
|
||||
@conn = Mongo::Connection.new('localhost', 27017, :pool_size => 10, :timeout => 10)
|
||||
@coll = @conn['mongo-ruby-test']['test-connection-exceptions']
|
||||
@coll = @conn[MONGO_TEST_DB]['test-connection-exceptions']
|
||||
end
|
||||
|
||||
should "release connection if an exception is raised on send_message" do
|
||||
|
@ -8,14 +8,14 @@ class CursorTest < Test::Unit::TestCase
|
||||
|
||||
@@connection = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
|
||||
@@db = @@connection.db('ruby-mongo-test')
|
||||
@@db = @@connection.db(MONGO_TEST_DB)
|
||||
@@coll = @@db.collection('test')
|
||||
@@version = @@connection.server_version
|
||||
|
||||
def setup
|
||||
@@coll.remove
|
||||
@@coll.insert('a' => 1) # collection not created until it's used
|
||||
@@coll_full_name = 'ruby-mongo-test.test'
|
||||
@@coll_full_name = "#{MONGO_TEST_DB}.test"
|
||||
end
|
||||
|
||||
def test_explain
|
||||
|
@ -6,7 +6,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||
|
||||
@@conn = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
|
||||
@@db = @@conn.db("ruby-mongo-test")
|
||||
@@db = @@conn.db(MONGO_TEST_DB)
|
||||
@@coll = @@db.collection('test')
|
||||
@@version = @@conn.server_version
|
||||
|
||||
@ -14,7 +14,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||
@@coll.remove
|
||||
@r1 = {'a' => 1}
|
||||
@@coll.insert(@r1) # collection not created until it's used
|
||||
@@coll_full_name = 'ruby-mongo-test.test'
|
||||
@@coll_full_name = "#{MONGO_TEST_DB}.test"
|
||||
end
|
||||
|
||||
def teardown
|
||||
@ -240,7 +240,7 @@ class DBAPITest < Test::Unit::TestCase
|
||||
names = @@db.collection_names
|
||||
assert names.length >= 2
|
||||
assert names.include?(@@coll.name)
|
||||
assert names.include?('ruby-mongo-test.test2')
|
||||
assert names.include?('mongo-ruby-test.test2')
|
||||
ensure
|
||||
@@db.drop_collection('test2')
|
||||
end
|
||||
|
@ -8,7 +8,7 @@ class DBConnectionTest < Test::Unit::TestCase
|
||||
def test_no_exceptions
|
||||
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
||||
db = Connection.new(host, port).db('ruby-mongo-demo')
|
||||
db = Connection.new(host, port).db(MONGO_TEST_DB)
|
||||
coll = db.collection('test')
|
||||
coll.remove
|
||||
db.error
|
||||
|
@ -18,7 +18,7 @@ class DBTest < Test::Unit::TestCase
|
||||
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
||||
@@conn = Connection.new(@@host, @@port)
|
||||
@@db = @@conn.db('ruby-mongo-test')
|
||||
@@db = @@conn.db(MONGO_TEST_DB)
|
||||
@@users = @@db.collection('system.users')
|
||||
|
||||
def test_close
|
||||
@ -30,7 +30,7 @@ class DBTest < Test::Unit::TestCase
|
||||
rescue => ex
|
||||
assert_match /NilClass/, ex.to_s
|
||||
ensure
|
||||
@@db = Connection.new(@@host, @@port).db('ruby-mongo-test')
|
||||
@@db = Connection.new(@@host, @@port).db(MONGO_TEST_DB)
|
||||
@@users = @@db.collection('system.users')
|
||||
end
|
||||
end
|
||||
@ -48,7 +48,7 @@ class DBTest < Test::Unit::TestCase
|
||||
|
||||
def test_full_coll_name
|
||||
coll = @@db.collection('test')
|
||||
assert_equal 'ruby-mongo-test.test', @@db.full_collection_name(coll.name)
|
||||
assert_equal "#{MONGO_TEST_DB}.test", @@db.full_collection_name(coll.name)
|
||||
end
|
||||
|
||||
def test_collection_names
|
||||
@ -79,18 +79,18 @@ class DBTest < Test::Unit::TestCase
|
||||
@@conn.close
|
||||
@@users = nil
|
||||
@@conn = Connection.new({:left => "this-should-fail", :right => [@@host, @@port]})
|
||||
@@db = @@conn['ruby-mongo-test']
|
||||
@@db = @@conn[MONGO_TEST_DB]
|
||||
assert @@conn.connected?
|
||||
ensure
|
||||
unless @@conn.connected?
|
||||
@@conn = Connection.new(@@host, @@port)
|
||||
@@db = @@conn.db('ruby-mongo-test')
|
||||
@@db = @@conn.db(MONGO_TEST_DB)
|
||||
end
|
||||
@@users = @@db.collection('system.users')
|
||||
end
|
||||
|
||||
def test_pk_factory
|
||||
db = Connection.new(@@host, @@port).db('ruby-mongo-test', :pk => TestPKFactory.new)
|
||||
db = Connection.new(@@host, @@port).db(MONGO_TEST_DB, :pk => TestPKFactory.new)
|
||||
coll = db.collection('test')
|
||||
coll.remove
|
||||
|
||||
@ -114,7 +114,7 @@ class DBTest < Test::Unit::TestCase
|
||||
|
||||
def test_pk_factory_reset
|
||||
conn = Connection.new(@@host, @@port)
|
||||
db = conn.db('ruby-mongo-test')
|
||||
db = conn.db(MONGO_TEST_DB)
|
||||
db.pk_factory = Object.new # first time
|
||||
begin
|
||||
db.pk_factory = Object.new
|
||||
@ -202,7 +202,7 @@ class DBTest < Test::Unit::TestCase
|
||||
|
||||
def test_text_port_number_raises_no_errors
|
||||
conn = Connection.new(@@host, @@port.to_s)
|
||||
db = conn['ruby-mongo-test']
|
||||
db = conn[MONGO_TEST_DB]
|
||||
assert db.collection('users').remove
|
||||
end
|
||||
|
||||
@ -222,7 +222,7 @@ class DBTest < Test::Unit::TestCase
|
||||
|
||||
context "database profiling" do
|
||||
setup do
|
||||
@db = @@conn['ruby-mongo-test-admin-functions']
|
||||
@db = @@conn[MONGO_TEST_DB]
|
||||
@coll = @db['test']
|
||||
@coll.remove
|
||||
@r1 = @coll.insert('a' => 1) # collection not created until it's used
|
||||
|
@ -6,7 +6,7 @@ class GridFileSystemTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@con = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT)
|
||||
@db = @con.db('mongo-ruby-test')
|
||||
@db = @con.db(MONGO_TEST_DB)
|
||||
end
|
||||
|
||||
teardown do
|
||||
|
@ -6,7 +6,7 @@ class GridIOTest < Test::Unit::TestCase
|
||||
context "GridIO" do
|
||||
setup do
|
||||
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db(MONGO_TEST_DB)
|
||||
@files = @db.collection('fs.files')
|
||||
@chunks = @db.collection('fs.chunks')
|
||||
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]])
|
||||
|
@ -5,7 +5,7 @@ class GridTest < Test::Unit::TestCase
|
||||
context "Tests:" do
|
||||
setup do
|
||||
@db ||= Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db('ruby-mongo-test')
|
||||
ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT).db(MONGO_TEST_DB)
|
||||
@files = @db.collection('test-fs.files')
|
||||
@chunks = @db.collection('test-fs.chunks')
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ class ObjectIDTest < Test::Unit::TestCase
|
||||
def test_save_and_restore
|
||||
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
||||
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
||||
db = Connection.new(host, port).db('ruby-mongo-test')
|
||||
db = Connection.new(host, port).db(MONGO_TEST_DB)
|
||||
coll = db.collection('test')
|
||||
|
||||
coll.remove
|
||||
|
@ -21,6 +21,8 @@ end
|
||||
|
||||
require 'bson_ext/cbson' if ENV['C_EXT']
|
||||
|
||||
MONGO_TEST_DB = 'mongo-ruby-test'
|
||||
|
||||
# NOTE: most tests assume that MongoDB is running.
|
||||
class Test::Unit::TestCase
|
||||
include Mongo
|
||||
|
@ -6,7 +6,7 @@ class TestThreadingLargePool < Test::Unit::TestCase
|
||||
|
||||
include Mongo
|
||||
|
||||
@@db = Connection.new('localhost', 27017, :pool_size => 50, :timeout => 60).db('ruby-mongo-test')
|
||||
@@db = Connection.new('localhost', 27017, :pool_size => 50, :timeout => 60).db(MONGO_TEST_DB)
|
||||
@@coll = @@db.collection('thread-test-collection')
|
||||
|
||||
def set_up_safe_data
|
||||
|
@ -4,7 +4,7 @@ class TestThreading < Test::Unit::TestCase
|
||||
|
||||
include Mongo
|
||||
|
||||
@@db = Connection.new('localhost', 27017, :pool_size => 1, :timeout => 30).db('ruby-mongo-test')
|
||||
@@db = Connection.new('localhost', 27017, :pool_size => 1, :timeout => 30).db(MONGO_TEST_DB)
|
||||
@@coll = @@db.collection('thread-test-collection')
|
||||
|
||||
def set_up_safe_data
|
||||
|
Loading…
Reference in New Issue
Block a user