diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-11-16 07:41:14 +0900 |
---|---|---|
committer | Yuji Yaginuma <yuuji.yaginuma@gmail.com> | 2017-11-16 08:31:58 +0900 |
commit | f27319a72a4ccfbffc575b752e4d91136f23725e (patch) | |
tree | 085af53a507a1aa156615bdd3a61b4b6c9822025 | |
parent | 376094caa44b1d641e3ed62466f085f6d8500999 (diff) | |
download | rails-f27319a72a4ccfbffc575b752e4d91136f23725e.tar.gz rails-f27319a72a4ccfbffc575b752e4d91136f23725e.tar.bz2 rails-f27319a72a4ccfbffc575b752e4d91136f23725e.zip |
Add master key to `gitignore` on `rails new`
We generate master key on `rails new`.
Therefore, if do not add master key to `.gitginore` on `rails new`as
well, there is a possibility that the master key will be committed
accidentally.
4 files changed, 19 insertions, 1 deletions
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index a99037576d..1fdfc3ca52 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -162,7 +162,9 @@ module Rails return if options[:pretend] || options[:dummy_app] require "rails/generators/rails/master_key/master_key_generator" - Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet]).add_master_key_file_silently + master_key_generator = Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet]) + master_key_generator.add_master_key_file_silently + master_key_generator.ignore_master_key_file_silently end def credentials diff --git a/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb b/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb index dd0d0c6c66..a396a9661f 100644 --- a/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb +++ b/railties/lib/rails/generators/rails/encryption_key_file/encryption_key_file_generator.rb @@ -44,6 +44,10 @@ module Rails end end + def ignore_key_file_silently(key_path, ignore: key_ignore(key_path)) + append_to_file ".gitignore", ignore if File.exist?(".gitignore") + end + private def key_ignore(key_path) [ "", "/#{key_path}", "" ].join("\n") 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 de65146a8e..7f57340c11 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 @@ -34,6 +34,10 @@ module Rails key_file_generator.ignore_key_file(MASTER_KEY_PATH, ignore: key_ignore) end + def ignore_master_key_file_silently + key_file_generator.ignore_key_file_silently(MASTER_KEY_PATH, ignore: key_ignore) + end + private def key_file_generator EncryptionKeyFileGenerator.new([], options) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 78962ee30b..fddfab172e 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -838,6 +838,14 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_equal 5, @sequence_step end + def test_gitignore + run_generator + + assert_file ".gitignore" do |content| + assert_match(/config\/master\.key/, content) + end + end + def test_system_tests_directory_generated run_generator |