aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorigor04 <igor.s04g@gmail.com>2019-07-12 19:22:36 +0300
committerigor04 <igor.s04g@gmail.com>2019-07-12 19:23:09 +0300
commit0fa41f72fcb773bd32c7ce77f9df33e328ff0e44 (patch)
tree86703a55c6185d04f5da1e2bf4b4f41088d09a8a /railties
parent141b30630cc9ec15dd5aa88e062383adedd335de (diff)
downloadrails-0fa41f72fcb773bd32c7ce77f9df33e328ff0e44.tar.gz
rails-0fa41f72fcb773bd32c7ce77f9df33e328ff0e44.tar.bz2
rails-0fa41f72fcb773bd32c7ce77f9df33e328ff0e44.zip
Prevent exception of loading database yaml with blank config file [closes: #36661]
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/application/configuration.rb2
-rw-r--r--railties/test/application/configuration_test.rb5
2 files changed, 6 insertions, 1 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index f5456f4916..5b3e96cbd4 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -209,7 +209,7 @@ module Rails
yaml = Pathname.new(path)
erb = DummyERB.new(yaml.read)
- YAML.load(erb.result)
+ YAML.load(erb.result) || {}
else
{}
end
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index f6bec3242a..a05d86f738 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -1793,6 +1793,11 @@ module ApplicationTests
assert_equal [X, D], C.descendants
end
+ test "load_database_yaml returns blank hash if configuration file is blank" do
+ app_file "config/database.yml", ""
+ app "development"
+ assert_equal({}, Rails.application.config.load_database_yaml)
+ end
test "raises with proper error message if no database configuration found" do
FileUtils.rm("#{app_path}/config/database.yml")