Here are the tests for Pull Request #329 #350

Closed
wants to merge 2 commits into
from
View
13 lib/mongo_mapper/connection.rb
@@ -60,7 +60,18 @@ def config_for_environment(environment)
def connect(environment, options={})
raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
- env = config_for_environment(environment)
+ full_config = config_for_environment(environment)
+
+ env = {
+ 'hosts' => full_config.delete('hosts'),
+ 'host' => full_config.delete('host'),
+ 'port' => full_config.delete('port'),
+ 'database' => full_config.delete('database'),
+ 'username' => full_config.delete('username'),
+ 'password' => full_config.delete('password')
+ }
+
+ options = (full_config['options'] || {}).merge(options).symbolize_keys
MongoMapper.connection = if env['hosts']
Mongo::ReplSetConnection.new( *env['hosts'].push(options) )
View
10 test/unit/test_mongo_mapper.rb
@@ -65,6 +65,14 @@ class MongoMapperTest < Test::Unit::TestCase
MongoMapper.connect('development', :logger => logger)
end
+ should "work with options from environment" do
+ MongoMapper.config = {
+ 'development' => {'host' => '127.0.0.1', 'port' => 27017, 'database' => 'test', 'options' => {'pool_size' => 10} }
+ }
+ Mongo::Connection.expects(:new).with('127.0.0.1', 27017, :pool_size => 10)
+ MongoMapper.connect('development')
+ end
+
should "work with options using uri" do
MongoMapper.config = {
'development' => {'uri' => 'mongodb://127.0.0.1:27017/test'}
@@ -105,7 +113,7 @@ class MongoMapperTest < Test::Unit::TestCase
}
}
- Mongo::ReplSetConnection.expects(:new).with( ['127.0.0.1', 27017], ['localhost', 27017], {'read_secondary' => true} )
+ Mongo::ReplSetConnection.expects(:new).with( ['127.0.0.1', 27017], ['localhost', 27017], {:read_secondary => true} )
MongoMapper.expects(:database=).with('test')
Mongo::DB.any_instance.expects(:authenticate).never
MongoMapper.connect('development', 'read_secondary' => true)