1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Arthur Neves 2016-05-11 13:37:14 -04:00
parent 59d252196b
commit 537a342a83
No known key found for this signature in database
GPG key ID: 04A390FB1E433E17
2 changed files with 9 additions and 1 deletions

View file

@ -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.

View file

@ -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