diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 7 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 9 |
2 files changed, 13 insertions, 3 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 2c16b83f8a..786dcee007 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -93,9 +93,10 @@ module Rails # 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 @@ module Rails # 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 diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index db2106aed3..f8b4ee30d8 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -980,6 +980,15 @@ module ApplicationTests 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" |