Added options for host:port through ENV to connect to the server

This commit is contained in:
Adrian Madrid 2008-12-06 13:27:02 -07:00
parent 66c3ed3b6e
commit 4c7873f3db
2 changed files with 7 additions and 2 deletions

View File

@ -1,4 +1,5 @@
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
require 'mongo'
require 'test/unit'
@ -6,7 +7,9 @@ require 'test/unit'
class DBAPITest < Test::Unit::TestCase
def setup
@db = XGen::Mongo::Driver::Mongo.new.db('ruby-mongo-test')
host = ENV['HOST'] || ENV['host'] || 'localhost'
port = ENV['PORT'] || ENV['port'] || 27017
@db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
@coll = @db.collection('test')
@coll.clear
@coll.insert('a' => 1) # collection not created until it's used

View File

@ -6,7 +6,9 @@ require 'test/unit'
class DBConnectionTest < Test::Unit::TestCase
def test_no_exceptions
db = XGen::Mongo::Driver::Mongo.new.db('ruby-mongo-demo')
host = ENV['HOST'] || ENV['host'] || 'localhost'
port = ENV['PORT'] || ENV['port'] || 27017
db = XGen::Mongo::Driver::Mongo.new(host, port).db('ruby-mongo-test')
coll = db.collection('test')
coll.clear
end