diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/connection_specification.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handler_test.rb | 34 |
2 files changed, 23 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index 5a18e95bcd..f8cdf3ca0c 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -164,7 +164,7 @@ module ActiveRecord # spec.config # # => { "host" => "localhost", "database" => "foo", "adapter" => "sqlite3" } # - def spec(config, id = "primary") + def spec(config, id = nil) spec = resolve(config).symbolize_keys raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter) @@ -179,6 +179,13 @@ module ActiveRecord end adapter_method = "#{spec[:adapter]}_connection" + + id ||= + if config.is_a?(Symbol) + config.to_s + else + "primary" + end ConnectionSpecification.new(id, spec, adapter_method) end diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index c3cdb29380..47e8486ded 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -6,10 +6,19 @@ module ActiveRecord def setup @handler = ConnectionHandler.new resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new Base.configurations - spec = resolver.spec(:arunit) - @spec_id = "primary" - @pool = @handler.establish_connection(spec) + @pool = @handler.establish_connection(resolver.spec(:arunit, @spec_id)) + end + + def test_establish_connection_uses_spec_id + config = {"readonly" => {"adapter" => 'sqlite3'}} + resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new(config) + spec = resolver.spec(:readonly) + @handler.establish_connection(spec) + + assert_not_nil @handler.retrieve_connection_pool('readonly') + ensure + @handler.remove_connection('readonly') end def test_retrieve_connection @@ -24,31 +33,18 @@ module ActiveRecord assert !@handler.active_connections? end -# def test_retrieve_connection_pool_with_ar_base -# assert_nil @handler.retrieve_connection_pool(ActiveRecord::Base) -# end - def test_retrieve_connection_pool assert_not_nil @handler.retrieve_connection_pool(@spec_id) end -# def test_retrieve_connection_pool_uses_superclass_when_no_subclass_connection -# assert_not_nil @handler.retrieve_connection_pool(@subklass) -# end - -# def test_retrieve_connection_pool_uses_superclass_pool_after_subclass_establish_and_remove -# sub_pool = @handler.establish_connection(@subklass, Base.connection_pool.spec) -# assert_same sub_pool, @handler.retrieve_connection_pool(@subklass) -# -# @handler.remove_connection @subklass -# assert_same @pool, @handler.retrieve_connection_pool(@subklass) -# end + def test_retrieve_connection_pool_with_invalid_id + assert_nil @handler.retrieve_connection_pool("foo") + end def test_connection_pools assert_equal([@pool], @handler.connection_pools) end - # TODO if Process.respond_to?(:fork) def test_connection_pool_per_pid object_id = ActiveRecord::Base.connection.object_id |