mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
c8ce345964
commit
32327eb123
2 changed files with 21 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue