mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36372 from instructure-bridge/6-0-stable
Don't break configurations.each, .first before the deprecation period
This commit is contained in:
parent
7067ee91fb
commit
344bed41d0
2 changed files with 21 additions and 8 deletions
|
@ -91,6 +91,19 @@ module ActiveRecord
|
|||
end
|
||||
alias :blank? :empty?
|
||||
|
||||
def each
|
||||
throw_getter_deprecation(:each)
|
||||
configurations.each { |config|
|
||||
yield [config.env_name, config.config]
|
||||
}
|
||||
end
|
||||
|
||||
def first
|
||||
throw_getter_deprecation(:first)
|
||||
config = configurations.first
|
||||
[config.env_name, config.config]
|
||||
end
|
||||
|
||||
private
|
||||
def env_with_configs(env = nil)
|
||||
if env
|
||||
|
@ -176,9 +189,6 @@ module ActiveRecord
|
|||
|
||||
def method_missing(method, *args, &blk)
|
||||
case method
|
||||
when :each, :first
|
||||
throw_getter_deprecation(method)
|
||||
configurations.send(method, *args, &blk)
|
||||
when :fetch
|
||||
throw_getter_deprecation(method)
|
||||
configs_for(env_name: args.first)
|
||||
|
|
|
@ -80,17 +80,20 @@ class LegacyDatabaseConfigurationsTest < ActiveRecord::TestCase
|
|||
|
||||
def test_each_is_deprecated
|
||||
assert_deprecated do
|
||||
ActiveRecord::Base.configurations.each do |db_config|
|
||||
assert_equal "primary", db_config.spec_name
|
||||
all_configs = ActiveRecord::Base.configurations.values
|
||||
ActiveRecord::Base.configurations.each do |env_name, config|
|
||||
assert_includes ["arunit", "arunit2", "arunit_without_prepared_statements"], env_name
|
||||
assert_includes all_configs, config
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_first_is_deprecated
|
||||
first_config = ActiveRecord::Base.configurations.values.first
|
||||
assert_deprecated do
|
||||
db_config = ActiveRecord::Base.configurations.first
|
||||
assert_equal "arunit", db_config.env_name
|
||||
assert_equal "primary", db_config.spec_name
|
||||
env_name, config = ActiveRecord::Base.configurations.first
|
||||
assert_equal "arunit", env_name
|
||||
assert_equal first_config, config
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue