Skip to content

Loading…

Here are the tests for Pull Request #329 #350

Closed
wants to merge 2 commits into from

2 participants

@RyanScottLewis

We also changed the options to the format you requested.

@bkeepers bkeepers closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2011
  1. @RyanScottLewis

    Added option fix

    RyanScottLewis committed
Commits on Nov 18, 2011
  1. Adds specs for Mongo::Connection options

    Enable Labs [dev_pairing_4] committed
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 2 deletions.
  1. +12 −1 lib/mongo_mapper/connection.rb
  2. +9 −1 test/unit/test_mongo_mapper.rb
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)
Something went wrong with that request. Please try again.