Skip to content

Commit e150024

Browse files
authored
Merge pull request rails#46161 from eikes/use-active-support-configuration-file-in-load-database-yaml
Use ActiveSupport::ConfigurationFile in load_database_yaml
2 parents b205dc4 + d9f5bfa commit e150024

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

railties/lib/rails/application/configuration.rb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -384,26 +384,14 @@ def paths
384384
def load_database_yaml # :nodoc:
385385
if path = paths["config/database"].existent.first
386386
require "rails/application/dummy_config"
387-
388387
original_rails_config = Rails.application.config
389-
dummy_config = DummyConfig.new(original_rails_config)
390-
database_config = {}
391388

392389
begin
393-
Rails.application.config = dummy_config
394-
395-
yaml = ERB.new(Pathname.new(path).read).result
396-
397-
if YAML.respond_to?(:unsafe_load)
398-
database_config = YAML.unsafe_load(yaml) || {}
399-
else
400-
database_config = YAML.load(yaml) || {}
401-
end
390+
Rails.application.config = DummyConfig.new(original_rails_config)
391+
ActiveSupport::ConfigurationFile.parse(Pathname.new(path))
402392
ensure
403393
Rails.application.config = original_rails_config
404394
end
405-
406-
database_config
407395
else
408396
{}
409397
end

railties/test/application/configuration_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,6 +2012,12 @@ def index
20122012
assert_equal({}, Rails.application.config.load_database_yaml)
20132013
end
20142014

2015+
test "load_database_yaml returns blank hash if no database configuration is found" do
2016+
remove_file "config/database.yml"
2017+
app "development"
2018+
assert_equal({}, Rails.application.config.load_database_yaml)
2019+
end
2020+
20152021
test "setup_initial_database_yaml does not print a warning if config.active_record.suppress_multiple_database_warning is true" do
20162022
app_file "config/database.yml", <<-YAML
20172023
<%= Rails.env %>:

0 commit comments

Comments
 (0)