1
0
Fork 0
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:
Rafael França 2019-07-26 12:58:55 -04:00 committed by Rafael Mendonça França
parent 7067ee91fb
commit 344bed41d0
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
2 changed files with 21 additions and 8 deletions

View file

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

View file

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