diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-05-30 01:00:49 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-05-30 01:00:49 -0700 |
commit | d7cbdbef1857f1359201234e02933ba3bfed2a14 (patch) | |
tree | 68892974178b78cc3566578438862934266feffc /railties | |
parent | 109e71d2bb6d2305a091fe7ea96d4f6e9c7cd52d (diff) | |
parent | 0cb327c549282548639696f86aeac97a4e48e9f1 (diff) | |
download | rails-d7cbdbef1857f1359201234e02933ba3bfed2a14.tar.gz rails-d7cbdbef1857f1359201234e02933ba3bfed2a14.tar.bz2 rails-d7cbdbef1857f1359201234e02933ba3bfed2a14.zip |
Merge pull request #20370 from manishspuri/master
Add tmp directory before touching
Diffstat (limited to 'railties')
-rw-r--r-- | railties/CHANGELOG.md | 7 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/app_generator.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/bin/setup | 2 | ||||
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/gitignore | 3 | ||||
-rw-r--r-- | railties/lib/rails/tasks/restart.rake | 1 | ||||
-rw-r--r-- | railties/test/application/rake/restart_test.rb | 12 | ||||
-rw-r--r-- | railties/test/application/rake_test.rb | 7 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 27 |
8 files changed, 56 insertions, 4 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 02fdaf09e0..d2662d61da 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* Generator a `.keep` file in the `tmp` folder by default as many scripts + assume the existence of this folder and most would fail if it is absent. + + See #20299. + + *Yoong Kang Lim*, *Sunny Juneja* + * `config.static_index` configures directory `index.html` filename Set `config.static_index` to serve a static directory index file not named diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 1047a2c429..152c26860e 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -141,6 +141,7 @@ module Rails end def tmp + empty_directory_with_keep_file "tmp" empty_directory "tmp/cache" empty_directory "tmp/cache/assets" end diff --git a/railties/lib/rails/generators/rails/app/templates/bin/setup b/railties/lib/rails/generators/rails/app/templates/bin/setup index 3a5a2cc1e3..0d41f2fe4c 100644 --- a/railties/lib/rails/generators/rails/app/templates/bin/setup +++ b/railties/lib/rails/generators/rails/app/templates/bin/setup @@ -25,5 +25,5 @@ chdir APP_ROOT do system 'ruby bin/rake log:clear tmp:clear' puts "\n== Restarting application server ==" - touch 'tmp/restart.txt' + system 'ruby bin/rake restart' end diff --git a/railties/lib/rails/generators/rails/app/templates/gitignore b/railties/lib/rails/generators/rails/app/templates/gitignore index e4a00ad181..1b8cf8a9fa 100644 --- a/railties/lib/rails/generators/rails/app/templates/gitignore +++ b/railties/lib/rails/generators/rails/app/templates/gitignore @@ -15,7 +15,8 @@ <% end -%> # Ignore all logfiles and tempfiles. /log/* +/tmp/* <% if keeps? -%> !/log/.keep +!/tmp/.keep <% end -%> -/tmp diff --git a/railties/lib/rails/tasks/restart.rake b/railties/lib/rails/tasks/restart.rake index 1e8940b675..f36c86d81b 100644 --- a/railties/lib/rails/tasks/restart.rake +++ b/railties/lib/rails/tasks/restart.rake @@ -1,4 +1,5 @@ desc "Restart app by touching tmp/restart.txt" task :restart do + FileUtils.mkdir_p('tmp') FileUtils.touch('tmp/restart.txt') end diff --git a/railties/test/application/rake/restart_test.rb b/railties/test/application/rake/restart_test.rb index 35099913fb..4cae199e6b 100644 --- a/railties/test/application/rake/restart_test.rb +++ b/railties/test/application/rake/restart_test.rb @@ -13,12 +13,12 @@ module ApplicationTests def teardown teardown_app end - + test 'rake restart touches tmp/restart.txt' do Dir.chdir(app_path) do `rake restart` assert File.exist?("tmp/restart.txt") - + prev_mtime = File.mtime("tmp/restart.txt") sleep(1) `rake restart` @@ -26,6 +26,14 @@ module ApplicationTests assert_not_equal prev_mtime, curr_mtime end end + + test 'rake restart should work even if tmp folder does not exist' do + Dir.chdir(app_path) do + FileUtils.remove_dir('tmp') + `rake restart` + assert File.exist?('tmp/restart.txt') + end + end end end end diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb index de14f269df..dd26ec867d 100644 --- a/railties/test/application/rake_test.rb +++ b/railties/test/application/rake_test.rb @@ -285,5 +285,12 @@ module ApplicationTests assert_match(/Hello, World!/, output) end + + def test_tmp_clear_should_work_if_folder_missing + FileUtils.remove_dir("#{app_path}/tmp") + errormsg = Dir.chdir(app_path) { `bundle exec rake tmp:clear` } + assert_predicate $?, :success? + assert_empty errormsg + end end end diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 2bfa05a0b8..af1c05cab1 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -44,6 +44,7 @@ DEFAULT_APP_FILES = %w( vendor/assets vendor/assets/stylesheets vendor/assets/javascripts + tmp tmp/cache tmp/cache/assets ) @@ -606,6 +607,32 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_create_keeps + run_generator + folders_with_keep = %w( + app/assets/images + app/mailers + app/models + app/controllers/concerns + app/models/concerns + lib/tasks + lib/assets + log + test/fixtures + test/fixtures/files + test/controllers + test/mailers + test/models + test/helpers + test/integration + tmp + vendor/assets/stylesheets + ) + folders_with_keep.each do |folder| + assert_file("#{folder}/.keep") + end + end + def test_psych_gem run_generator gem_regex = /gem 'psych',\s+'~> 2.0',\s+platforms: :rbx/ |