aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authoryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-07-07 08:17:01 +0900
committeryuuji.yaginuma <yuuji.yaginuma@gmail.com>2017-07-07 12:16:53 +0900
commit32327eb12320087aaefb382a17e1c517207e1571 (patch)
tree59b6f901cce6147c2a96cd53bbd6c7934c7ebee6 /railties
parentc8ce3459648ce0f86646b564ce1c0bb16a4b48eb (diff)
downloadrails-32327eb12320087aaefb382a17e1c517207e1571.tar.gz
rails-32327eb12320087aaefb382a17e1c517207e1571.tar.bz2
rails-32327eb12320087aaefb382a17e1c517207e1571.zip
Do not update `secrets.yml.enc` when secretes do not change
Currently, if open a file with `secrets:edit` command, `secrets.yml.enc` will be changed even if its contents do not change. Therefore, even if only want to check secrets, the difference will come out. This is a little inconvenient. As a fix to the above problem, when content does not change, `secrets.yml.ecn` is fixed so that it is not changed.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/secrets.rb4
-rw-r--r--railties/test/secrets_test.rb18
2 files changed, 21 insertions, 1 deletions
diff --git a/railties/lib/rails/secrets.rb b/railties/lib/rails/secrets.rb
index c7a8676d7b..955ab096e8 100644
--- a/railties/lib/rails/secrets.rb
+++ b/railties/lib/rails/secrets.rb
@@ -105,7 +105,9 @@ module Rails
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
diff --git a/railties/test/secrets_test.rb b/railties/test/secrets_test.rb
index 36c8ef1fd9..321b654ae3 100644
--- a/railties/test/secrets_test.rb
+++ b/railties/test/secrets_test.rb
@@ -111,6 +111,24 @@ class Rails::SecretsTest < ActiveSupport::TestCase
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