diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_handling.rb | 3 | ||||
-rw-r--r-- | activerecord/test/cases/connection_adapters/connection_handler_test.rb | 7 |
2 files changed, 9 insertions, 1 deletions
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 |