File tree Expand file tree Collapse file tree 4 files changed +40
-20
lines changed Expand file tree Collapse file tree 4 files changed +40
-20
lines changed Original file line number Diff line number Diff line change @@ -36,14 +36,7 @@ def edit
36
36
ensure_credentials_have_been_added
37
37
ensure_diffing_driver_is_configured
38
38
39
- catch_editing_exceptions do
40
- change_credentials_in_system_editor
41
- end
42
-
43
- say "File encrypted and saved."
44
- warn_if_credentials_are_invalid
45
- rescue ActiveSupport ::MessageEncryptor ::InvalidMessage
46
- say "Couldn't decrypt #{ content_path } . Perhaps you passed the wrong key?"
39
+ change_credentials_in_system_editor
47
40
end
48
41
49
42
def show
@@ -99,9 +92,16 @@ def ensure_credentials_have_been_added
99
92
end
100
93
101
94
def change_credentials_in_system_editor
102
- credentials . change do |tmp_path |
103
- system ( *Shellwords . split ( ENV [ "EDITOR" ] ) , tmp_path . to_s )
95
+ catch_editing_exceptions do
96
+ credentials . change do |tmp_path |
97
+ system ( *Shellwords . split ( ENV [ "EDITOR" ] ) , tmp_path . to_s )
98
+ end
99
+
100
+ say "File encrypted and saved."
101
+ warn_if_credentials_are_invalid
104
102
end
103
+ rescue ActiveSupport ::MessageEncryptor ::InvalidMessage
104
+ say "Couldn't decrypt #{ content_path } . Perhaps you passed the wrong key?"
105
105
end
106
106
107
107
def warn_if_credentials_are_invalid
Original file line number Diff line number Diff line change @@ -27,14 +27,7 @@ def edit(*)
27
27
ensure_encryption_key_has_been_added
28
28
ensure_encrypted_configuration_has_been_added
29
29
30
- catch_editing_exceptions do
31
- change_encrypted_configuration_in_system_editor
32
- end
33
-
34
- say "File encrypted and saved."
35
- warn_if_encrypted_configuration_is_invalid
36
- rescue ActiveSupport ::MessageEncryptor ::InvalidMessage
37
- say "Couldn't decrypt #{ content_path } . Perhaps you passed the wrong key?"
30
+ change_encrypted_configuration_in_system_editor
38
31
end
39
32
40
33
def show ( *)
@@ -67,9 +60,16 @@ def ensure_encrypted_configuration_has_been_added
67
60
end
68
61
69
62
def change_encrypted_configuration_in_system_editor
70
- encrypted_configuration . change do |tmp_path |
71
- system ( "#{ ENV [ "EDITOR" ] } #{ tmp_path } " )
63
+ catch_editing_exceptions do
64
+ encrypted_configuration . change do |tmp_path |
65
+ system ( "#{ ENV [ "EDITOR" ] } #{ tmp_path } " )
66
+ end
67
+
68
+ say "File encrypted and saved."
69
+ warn_if_encrypted_configuration_is_invalid
72
70
end
71
+ rescue ActiveSupport ::MessageEncryptor ::InvalidMessage
72
+ say "Couldn't decrypt #{ content_path } . Perhaps you passed the wrong key?"
73
73
end
74
74
75
75
def warn_if_encrypted_configuration_is_invalid
Original file line number Diff line number Diff line change @@ -142,6 +142,16 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase
142
142
assert_match %r/provides_secret_key_base: true/ , run_edit_command
143
143
end
144
144
145
+ test "edit command does not display save confirmation message if interrupted" do
146
+ assert_match %r/file encrypted and saved/i , run_edit_command
147
+
148
+ interrupt_command_process = %(ruby -e "Process.kill 'INT', Process.ppid")
149
+ output = run_edit_command ( editor : interrupt_command_process )
150
+
151
+ assert_no_match %r/file encrypted and saved/i , output
152
+ assert_match %r/nothing saved/i , output
153
+ end
154
+
145
155
test "edit command preserves user's content even if it contains invalid YAML" do
146
156
write_invalid_yaml = %(ruby -e "File.write ARGV[0], 'foo: bar: bad'")
147
157
Original file line number Diff line number Diff line change @@ -82,6 +82,16 @@ class Rails::Command::EncryptedCommandTest < ActiveSupport::TestCase
82
82
assert_match ( /access_key_id: 123/ , run_edit_command ( key : "config/tokens.key" ) )
83
83
end
84
84
85
+ test "edit command does not display save confirmation message if interrupted" do
86
+ assert_match %r/file encrypted and saved/i , run_edit_command
87
+
88
+ interrupt_command_process = %(exec ruby -e "Process.kill 'INT', Process.ppid")
89
+ output = run_edit_command ( editor : interrupt_command_process )
90
+
91
+ assert_no_match %r/file encrypted and saved/i , output
92
+ assert_match %r/nothing saved/i , output
93
+ end
94
+
85
95
test "edit command preserves user's content even if it contains invalid YAML" do
86
96
write_invalid_yaml = %(ruby -e "File.write ARGV[0], 'foo: bar: bad'")
87
97
You can’t perform that action at this time.
0 commit comments