Skip to content

Commit

Permalink
Moving tests and tidy up. Fixes mongodb#782
Browse files Browse the repository at this point in the history
  • Loading branch information
KieranP committed Apr 23, 2011
1 parent 8ea0cd7 commit e1c8a43
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 70 deletions.
10 changes: 4 additions & 6 deletions lib/mongoid/config/replset_database.rb
Expand Up @@ -17,14 +17,14 @@ def configure
#yes, construction is weird but the driver wants "A list of host-port pairs ending with a hash containing any options"
#mongo likes symbols
options = self.inject({}) { |memo, (k, v)| memo[k.to_sym] = v; memo}
connection = Mongo::ReplSetConnection.new(*(self['hosts'] << options))
connection = Mongo::ReplSetConnection.new(*(hosts << options))

if authenticating?
connection.add_auth(database, username, password)
connection.apply_saved_authentication
end

[ connection.db(self['database']), nil ]
[ connection.db(database), nil ]
end

# Do we need to authenticate against the database?
Expand All @@ -34,7 +34,7 @@ def configure
#
# @return [ true, false ] True if auth is needed, false if not.
#
# @since 2.0.0.rc.7
# @since 2.0.2
def authenticating?
username || password
end
Expand All @@ -46,7 +46,7 @@ def authenticating?
#
# @return [ Object ] The value in the hash.
#
# @since 2.0.0.rc.7
# @since 2.0.2
def method_missing(name, *args, &block)
self[name.to_s]
end
Expand All @@ -71,8 +71,6 @@ def method_missing(name, *args, &block)
#
# @since 2.0.0.rc.5
def initialize(options = {})
self[:logger] = Mongoid::Logger.new

merge!(options)
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/config/mongoid.replset.yml
Expand Up @@ -18,3 +18,9 @@ test:
hosts: [ [localhost, 27017], [localhost, 27017] ]
database: multi_db_replset_test
reconnect_time: 5

authenticated:
<<: *defaults
database: mongoid_config_authenticated_test
username: mongoid
password: test
44 changes: 44 additions & 0 deletions spec/functional/mongoid/config/replset_database_spec.rb
Expand Up @@ -27,5 +27,49 @@
it "does not configure specific slaves" do
replica_set[1].should be_nil
end

context "without authentication details" do

let(:replica_set) do
described_class.new(options['test']).configure
end

let(:repl_set_connection) do
stub.quacks_like(Mongo::ReplSetConnection.allocate)
end

before do
Mongo::ReplSetConnection.stubs(:new).returns(repl_set_connection)
end

it "should not add authentication or apply" do
repl_set_connection.expects(:db)
repl_set_connection.expects(:add_auth).never
repl_set_connection.expects(:apply_saved_authentication).never
replica_set
end
end

context "with authentication details" do

let(:replica_set) do
described_class.new(options['authenticated']).configure
end

let(:repl_set_connection) do
stub.quacks_like(Mongo::ReplSetConnection.allocate)
end

before do
Mongo::ReplSetConnection.stubs(:new).returns(repl_set_connection)
end

it "should add authentication and apply" do
repl_set_connection.expects(:db)
repl_set_connection.expects(:add_auth).with(options['authenticated']['database'], options['authenticated']['username'], options['authenticated']['password'])
repl_set_connection.expects(:apply_saved_authentication)
replica_set
end
end
end
end
64 changes: 0 additions & 64 deletions spec/unit/mongoid/config/replset_database_spec.rb

This file was deleted.

0 comments on commit e1c8a43

Please sign in to comment.