From 537a342a8307ebe1d5e69a7e81495f137ae571a4 Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Wed, 11 May 2016 13:37:14 -0400 Subject: remove_connection should not remove parent connection When calling remove_connection in a subclass, that should not fallback to the parent, otherwise it will remove the parent connection from the handler. --- activerecord/lib/active_record/connection_handling.rb | 3 ++- .../test/cases/connection_adapters/connection_handler_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_handling.rb b/activerecord/lib/active_record/connection_handling.rb index 25306d6945..f932deb18d 100644 --- a/activerecord/lib/active_record/connection_handling.rb +++ b/activerecord/lib/active_record/connection_handling.rb @@ -132,7 +132,8 @@ module ActiveRecord connection_handler.connected?(connection_specification_name) end - def remove_connection(name = connection_specification_name) + def remove_connection(name = nil) + name ||= @connection_specification_name if defined?(@connection_specification_name) # if removing a connection that have a pool, we reset the # connection_specification_name so it will use the parent # pool. diff --git a/activerecord/test/cases/connection_adapters/connection_handler_test.rb b/activerecord/test/cases/connection_adapters/connection_handler_test.rb index 2d3c411479..50f942f5aa 100644 --- a/activerecord/test/cases/connection_adapters/connection_handler_test.rb +++ b/activerecord/test/cases/connection_adapters/connection_handler_test.rb @@ -112,6 +112,13 @@ module ActiveRecord klassA.connection_specification_name = "readonly" assert_equal "readonly", klassB.connection_specification_name end + + def test_remove_connection_should_not_remove_parent + klass2 = Class.new(Base) { def self.name; 'klass2'; end } + klass2.remove_connection + refute_nil ActiveRecord::Base.connection.object_id + assert_equal klass2.connection.object_id, ActiveRecord::Base.connection.object_id + end end end end -- cgit v1.2.3