提交 d7cbdbef 编写于 作者: G Godfrey Chan

Merge pull request #20370 from manishspuri/master

Add tmp directory before touching
* 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 * `config.static_index` configures directory `index.html` filename
Set `config.static_index` to serve a static directory index file not named Set `config.static_index` to serve a static directory index file not named
......
...@@ -141,6 +141,7 @@ def test ...@@ -141,6 +141,7 @@ def test
end end
def tmp def tmp
empty_directory_with_keep_file "tmp"
empty_directory "tmp/cache" empty_directory "tmp/cache"
empty_directory "tmp/cache/assets" empty_directory "tmp/cache/assets"
end end
......
...@@ -25,5 +25,5 @@ chdir APP_ROOT do ...@@ -25,5 +25,5 @@ chdir APP_ROOT do
system 'ruby bin/rake log:clear tmp:clear' system 'ruby bin/rake log:clear tmp:clear'
puts "\n== Restarting application server ==" puts "\n== Restarting application server =="
touch 'tmp/restart.txt' system 'ruby bin/rake restart'
end end
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
<% end -%> <% end -%>
# Ignore all logfiles and tempfiles. # Ignore all logfiles and tempfiles.
/log/* /log/*
/tmp/*
<% if keeps? -%> <% if keeps? -%>
!/log/.keep !/log/.keep
!/tmp/.keep
<% end -%> <% end -%>
/tmp
desc "Restart app by touching tmp/restart.txt" desc "Restart app by touching tmp/restart.txt"
task :restart do task :restart do
FileUtils.mkdir_p('tmp')
FileUtils.touch('tmp/restart.txt') FileUtils.touch('tmp/restart.txt')
end end
...@@ -13,12 +13,12 @@ def setup ...@@ -13,12 +13,12 @@ def setup
def teardown def teardown
teardown_app teardown_app
end end
test 'rake restart touches tmp/restart.txt' do test 'rake restart touches tmp/restart.txt' do
Dir.chdir(app_path) do Dir.chdir(app_path) do
`rake restart` `rake restart`
assert File.exist?("tmp/restart.txt") assert File.exist?("tmp/restart.txt")
prev_mtime = File.mtime("tmp/restart.txt") prev_mtime = File.mtime("tmp/restart.txt")
sleep(1) sleep(1)
`rake restart` `rake restart`
...@@ -26,6 +26,14 @@ def teardown ...@@ -26,6 +26,14 @@ def teardown
assert_not_equal prev_mtime, curr_mtime assert_not_equal prev_mtime, curr_mtime
end end
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 end
end end
...@@ -285,5 +285,12 @@ def test_template_load_initializers ...@@ -285,5 +285,12 @@ def test_template_load_initializers
assert_match(/Hello, World!/, output) assert_match(/Hello, World!/, output)
end 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
end end
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
vendor/assets vendor/assets
vendor/assets/stylesheets vendor/assets/stylesheets
vendor/assets/javascripts vendor/assets/javascripts
tmp
tmp/cache tmp/cache
tmp/cache/assets tmp/cache/assets
) )
...@@ -606,6 +607,32 @@ def test_gitignore_when_non_sqlite3_db ...@@ -606,6 +607,32 @@ def test_gitignore_when_non_sqlite3_db
end end
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 def test_psych_gem
run_generator run_generator
gem_regex = /gem 'psych',\s+'~> 2.0',\s+platforms: :rbx/ gem_regex = /gem 'psych',\s+'~> 2.0',\s+platforms: :rbx/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册