From 67a56b64ebbf3f956d6427e8419e0a1db2346a27 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Sat, 12 Jun 2010 10:11:29 -0400 Subject: [PATCH] fixed connection uri bug (Sunny Hirai) --- lib/mongo/connection.rb | 6 +++--- test/connection_test.rb | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/mongo/connection.rb b/lib/mongo/connection.rb index 41bcade..26dcd7c 100644 --- a/lib/mongo/connection.rb +++ b/lib/mongo/connection.rb @@ -522,11 +522,11 @@ module Mongo port = port.to_i db = matches[8] - if (uname || pwd || db) && !(uname && pwd && db) + if uname && pwd && db + add_auth(db, uname, pwd) + elsif uname || pwd || db raise MongoArgumentError, "MongoDB URI must include all three of username, password, " + "and db if any one of these is specified." - else - add_auth(db, uname, pwd) end nodes << [host, port] diff --git a/test/connection_test.rb b/test/connection_test.rb index 3816616..1dbb790 100644 --- a/test/connection_test.rb +++ b/test/connection_test.rb @@ -24,6 +24,12 @@ class TestConnection < Test::Unit::TestCase assert Mongo::Support.ok?(server_info) end + def test_connection_uri + con = Connection.from_uri("mongodb://localhost:27017") + assert_equal "localhost", con.host + assert_equal 27017, con.port + end + def test_server_version assert_match /\d\.\d+(\.\d+)?/, @mongo.server_version.to_s end