提交 ed9d220c 编写于 作者: A Akira Matsuda

Tell the user which file is missing when config/database.yml was not found

Since cc03675d30b58e28f585720dad14e947a57ff5b the error message became like
"Could not load database configuration. No such file -"
which doesn't really tell what's actually missing.
上级 9e1a7398
......@@ -93,9 +93,10 @@ def paths
# Loads and returns the entire raw configuration of database from
# values stored in `config/database.yml`.
def database_configuration
yaml = Pathname.new(paths["config/database"].existent.first || "")
path = paths["config/database"].existent.first
yaml = Pathname.new(path) if path
config = if yaml.exist?
config = if yaml && yaml.exist?
require "yaml"
require "erb"
YAML.load(ERB.new(yaml.read).result) || {}
......@@ -104,7 +105,7 @@ def database_configuration
# by Active Record.
{}
else
raise "Could not load database configuration. No such file - #{yaml}"
raise "Could not load database configuration. No such file - #{paths["config/database"].instance_variable_get(:@paths)}"
end
config
......
......@@ -980,6 +980,15 @@ def index
assert_kind_of Hash, Rails.application.config.database_configuration
end
test 'raises with proper error message if no database configuration found' do
FileUtils.rm("#{app_path}/config/database.yml")
require "#{app_path}/config/environment"
err = assert_raises RuntimeError do
Rails.application.config.database_configuration
end
assert_match 'config/database', err.message
end
test 'config.action_mailer.show_previews defaults to true in development' do
Rails.env = "development"
require "#{app_path}/config/environment"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册