Permalink
Browse files

Merge pull request #14029 from senny/dont_crash_on_empty_secrets_yml

do not crash when `config/secrets.yml` is blank.
  • Loading branch information...
2 parents 6e61da2 + 37e30d2 commit 6a1b459ea13ec7854ed513618ec3e75b20d7e2b9 @guilleiguaran guilleiguaran committed Feb 13, 2014
Showing with 14 additions and 1 deletion.
  1. +4 −0 railties/CHANGELOG.md
  2. +2 −1 railties/lib/rails/application.rb
  3. +8 −0 railties/test/application/configuration_test.rb
View
@@ -1,3 +1,7 @@
+* Do not crash when `config/secrets.yml` is empty.
+
+ *Yves Senn*
+
* Set `dump_schema_after_migration` config values in production.
Set `config.active_record.dump_schema_after_migration` as false
@@ -308,7 +308,8 @@ def secrets #:nodoc:
yaml = config.paths["config/secrets"].first
if File.exist?(yaml)
require "erb"
- env_secrets = YAML.load(ERB.new(IO.read(yaml)).result)[Rails.env]
+ all_secrets = YAML.load(ERB.new(IO.read(yaml)).result) || {}
+ env_secrets = all_secrets[Rails.env]
secrets.merge!(env_secrets.symbolize_keys) if env_secrets
end
@@ -336,6 +336,14 @@ def index
assert_equal 'myamazonsecretaccesskey', app.secrets.aws_secret_access_key
end
+ test "blank config/secrets.yml does not crash the loading process" do
+ app_file 'config/secrets.yml', <<-YAML
+ YAML
+ require "#{app_path}/config/environment"
+
+ assert_nil app.secrets.not_defined
+ end
+
test "protect from forgery is the default in a new app" do
make_basic_app

0 comments on commit 6a1b459

Please sign in to comment.