1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Do not overwrite by default if credentials already exists

Fixes #31286
This commit is contained in:
yuuji.yaginuma 2017-11-30 08:01:21 +09:00 committed by Yuji Yaginuma
parent d2aca50bbd
commit f7e3c68668
2 changed files with 12 additions and 2 deletions

View file

@ -8,7 +8,7 @@ module Rails
module Generators
class CredentialsGenerator < Base
def add_credentials_file
unless credentials.exist?
unless credentials.content_path.exist?
template = credentials_template
say "Adding #{credentials.content_path} to store encrypted credentials."
@ -26,7 +26,9 @@ module Rails
end
def add_credentials_file_silently(template = nil)
credentials.write(credentials_template)
unless credentials.content_path.exist?
credentials.write(credentials_template)
end
end
private

View file

@ -39,6 +39,14 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
end
end
test "edit command does not overwrite by default if credentials already exists" do
run_edit_command(editor: "eval echo api_key: abc >")
assert_match(/api_key: abc/, run_show_command)
run_edit_command
assert_match(/api_key: abc/, run_show_command)
end
private
def run_edit_command(editor: "cat")
switch_env("EDITOR", editor) do