mirror of https://github.com/rails/rails
Merge pull request #48681 from eileencodes/deprecate-name-argument-in-remove_connection
Deprecate `name` argument in `remove_connection`
This commit is contained in:
commit
e79250cb26
|
@ -1,3 +1,9 @@
|
|||
* Deprecate `name` argument on `#remove_connection`.
|
||||
|
||||
The `name` argument is deprecated on `#remove_connection` without replacement. `#remove_connection` should be called directly on the class that established the connection.
|
||||
|
||||
*Eileen M. Uchitelle*
|
||||
|
||||
* Fix has_one through singular building with inverse.
|
||||
|
||||
Allows building of records from an association with a has_one through a
|
||||
|
|
|
@ -293,6 +293,14 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def remove_connection(name = nil)
|
||||
if name
|
||||
ActiveRecord.deprecator.warn(<<-MSG.squish)
|
||||
The name argument for `#remove_connection` is deprecated without replacement
|
||||
and will be removed in Rails 7.2. `#remove_connection` should always be called
|
||||
on the connection class directly, which makes the name argument obsolete.
|
||||
MSG
|
||||
end
|
||||
|
||||
name ||= @connection_specification_name if defined?(@connection_specification_name)
|
||||
# if removing a connection that has a pool, we reset the
|
||||
# connection_specification_name so it will use the parent
|
||||
|
|
|
@ -279,6 +279,20 @@ module ActiveRecord
|
|||
assert_same klass2.connection, ActiveRecord::Base.connection
|
||||
end
|
||||
|
||||
def test_remove_connection_with_name_argument_is_deprecated
|
||||
klass2 = Class.new(Base) { def self.name; "klass2"; end }
|
||||
|
||||
assert_same klass2.connection, ActiveRecord::Base.connection
|
||||
|
||||
pool = klass2.establish_connection(ActiveRecord::Base.connection_pool.db_config.configuration_hash)
|
||||
assert_same klass2.connection, pool.connection
|
||||
assert_not_same klass2.connection, ActiveRecord::Base.connection
|
||||
|
||||
assert_deprecated(ActiveRecord.deprecator) do
|
||||
ActiveRecord::Base.remove_connection("klass2")
|
||||
end
|
||||
end
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
self.abstract_class = true
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue