aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorclaudiob <claudiob@users.noreply.github.com>2018-02-12 21:48:24 -0800
committerclaudiob <claudiob@users.noreply.github.com>2018-02-12 22:10:28 -0800
commitb77861d0c9f9ff941e70b38a920a6084627c0713 (patch)
treec28ed970784d85a436292740154a13cc6c13a0f6 /railties
parentb9ed1fa4442633e1328dcde5a37a472b22003a6f (diff)
downloadrails-b77861d0c9f9ff941e70b38a920a6084627c0713.tar.gz
rails-b77861d0c9f9ff941e70b38a920a6084627c0713.tar.bz2
rails-b77861d0c9f9ff941e70b38a920a6084627c0713.zip
Don't overwrite config/master.key even on --force
See https://github.com/rails/rails/pull/31957#issuecomment-364817423 The purpose of `--force` is not to have any prompt whether a file should be kept or overwritten. In general, all existing files should be overwritten. However, `config/master.key` is special because it is git-ignored, and overwriting it will cause the app not to run (since there won't be a way to decrypt the credentials). As a result, it's probably better to keep the existing config/master.key.
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/generators/rails/master_key/master_key_generator.rb4
-rw-r--r--railties/test/generators/app_generator_test.rb3
2 files changed, 5 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/rails/master_key/master_key_generator.rb b/railties/lib/rails/generators/rails/master_key/master_key_generator.rb
index 82968985dc..21664ea86d 100644
--- a/railties/lib/rails/generators/rails/master_key/master_key_generator.rb
+++ b/railties/lib/rails/generators/rails/master_key/master_key_generator.rb
@@ -27,7 +27,9 @@ module Rails
end
def add_master_key_file_silently(key = nil)
- key_file_generator.add_key_file_silently(MASTER_KEY_PATH, key)
+ unless MASTER_KEY_PATH.exist?
+ key_file_generator.add_key_file_silently(MASTER_KEY_PATH, key)
+ end
end
def ignore_master_key_file
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 23e6371a79..cc4a376d31 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -653,10 +653,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_empty output
end
- def test_force_option
+ def test_force_option_overwrites_every_file_except_master_key
run_generator [File.join(destination_root, "myapp")]
output = run_generator [File.join(destination_root, "myapp"), "--force"]
assert_match(/force/, output)
+ assert_no_match("force config/master.key", output)
end
def test_application_name_with_spaces