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