diff options
author | Arthur Neves <arthurnn@gmail.com> | 2016-05-11 13:37:14 -0400 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2016-05-11 13:39:26 -0400 |
commit | 537a342a8307ebe1d5e69a7e81495f137ae571a4 (patch) | |
tree | 0be0087446c5f14beaf8156bdd9a604a1629234e /activerecord | |
parent | 59d252196b36f6afaafd231756d69ea21537cf5d (diff) | |
download | rails-537a342a8307ebe1d5e69a7e81495f137ae571a4.tar.gz rails-537a342a8307ebe1d5e69a7e81495f137ae571a4.tar.bz2 rails-537a342a8307ebe1d5e69a7e81495f137ae571a4.zip |
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.
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 |