From b77861d0c9f9ff941e70b38a920a6084627c0713 Mon Sep 17 00:00:00 2001 From: claudiob Date: Mon, 12 Feb 2018 21:48:24 -0800 Subject: [PATCH] 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. --- .../rails/generators/rails/master_key/master_key_generator.rb | 4 +++- railties/test/generators/app_generator_test.rb | 3 ++- 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