diff --git a/lib/mongo/repl_set_connection.rb b/lib/mongo/repl_set_connection.rb index d70a041..414caa7 100644 --- a/lib/mongo/repl_set_connection.rb +++ b/lib/mongo/repl_set_connection.rb @@ -85,14 +85,26 @@ module Mongo else opts = {} end - + unless args.length > 0 raise MongoArgumentError, "A ReplSetConnection requires at least one seed node." end + + # This is temporary until support for the old format is dropped + @seeds = [] + if args.first.last.is_a?(Integer) + warn "Initiating a ReplSetConnection with seeds passed as individual [host, port] array arguments is deprecated." + warn "Please specify hosts as 'host:port' strings; the old format will be removed in v2.0" + @seeds = args + else + args.first.map do |host_port| + seed = host_port.split(":") + seed[1] = seed[1].to_i + seeds << seed + end + end - # The original, immutable list of seed node. # TODO: add a method for replacing this list of node. - @seeds = args @seeds.freeze # TODO: get rid of this diff --git a/test/replica_sets/connect_test.rb b/test/replica_sets/connect_test.rb index 45c2290..cf41aa2 100644 --- a/test/replica_sets/connect_test.rb +++ b/test/replica_sets/connect_test.rb @@ -108,6 +108,11 @@ class ConnectTest < Test::Unit::TestCase assert @conn.is_a?(ReplSetConnection) assert @conn.connected? end + + def test_connect_with_new_seed_format + @conn = ReplSetConnection.new(["#{@rs.host}:#{@rs.ports[0]}','#{@rs.host}:#{@rs.ports[1]}','#{@rs.host}:#{@rs.ports[2]}"]) + assert @conn.connected? + end def test_connect_with_full_connection_string @conn = Connection.from_uri("mongodb://#{@rs.host}:#{@rs.ports[0]},#{@rs.host}:#{@rs.ports[1]}?replicaset=#{@rs.name};safe=true;w=2;fsync=true;slaveok=true")