Skip to content

Commit

Permalink
Merge pull request #29705 from y-yagi/do_not_update_secrets_yml_enc
Browse files Browse the repository at this point in the history
Do not update `secrets.yml.enc` when secretes do not change
  • Loading branch information
matthewd committed Jul 8, 2017
2 parents 8fdc166 + 32327eb commit 7147e52
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion railties/lib/rails/secrets.rb
Expand Up @@ -105,7 +105,9 @@ def writing(contents)

yield tmp_path

write(File.read(tmp_path))
updated_contents = File.read(tmp_path)

write(updated_contents) if updated_contents != contents
ensure
FileUtils.rm(tmp_path) if File.exist?(tmp_path)
end
Expand Down
18 changes: 18 additions & 0 deletions railties/test/secrets_test.rb
Expand Up @@ -111,6 +111,24 @@ def teardown
end
end

test "do not update secrets.yml.enc when secretes do not change" do
run_secrets_generator do
Dir.chdir(app_path) do
Rails::Secrets.read_for_editing do |tmp_path|
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
end

FileUtils.cp("config/secrets.yml.enc", "config/secrets.yml.enc.bk")

Rails::Secrets.read_for_editing do |tmp_path|
File.write(tmp_path, "Empty streets, empty nights. The Downtown Lights.")
end

assert_equal File.read("config/secrets.yml.enc.bk"), File.read("config/secrets.yml.enc")
end
end
end

private
def run_secrets_generator
Dir.chdir(app_path) do
Expand Down

0 comments on commit 7147e52

Please sign in to comment.