From 6fc83f8efeb1637af5d17b0d7b0c4b2e3db3c001 Mon Sep 17 00:00:00 2001 From: Yoong Kang Lim Date: Tue, 26 May 2015 20:47:36 +1000 Subject: `rake restart` should work without a `tmp` folder In restart.rake, the creation of tmp/restart.txt would fail if the tmp folder does not exist in the app. This is a problem because apps cloned using git would not have the tmp folder, as the folder is in .gitignore. This commit creates the tmp folder if it does not exist. Fixes #20299 [Yoong Kang Lim, Sunny Juneja] --- railties/test/application/rake/restart_test.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'railties/test') 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 -- cgit v1.2.3 From f06ce4c12a396795a3b2c1812951d9277bcb3a82 Mon Sep 17 00:00:00 2001 From: Yoong Kang Lim Date: Tue, 26 May 2015 21:52:10 +1000 Subject: Generate a `.keep` file in `tmp` folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A lot of scripts assumes the existence of this folder and most would fail if it is absent. One example of this is `rake restart` (before the previous commit) – it tries to `touch tmp/restart.txt`, which would fail if `tmp` does not exist, which was the case for a freshly-cloned project as `tmp` is `.gitignored` by default. See #20299. [Yoong Kang Lim, Sunny Juneja] --- railties/test/generators/app_generator_test.rb | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'railties/test') 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/ -- cgit v1.2.3 From 0cb327c549282548639696f86aeac97a4e48e9f1 Mon Sep 17 00:00:00 2001 From: Yoong Kang Lim Date: Tue, 26 May 2015 22:09:22 +1000 Subject: Add test to ensure tmp:clear works when tmp is missing See #20299. --- railties/test/application/rake_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') 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 -- cgit v1.2.3