Fix for cache purging for subdir default indexes

This commit is contained in:
Kyle Drake 2017-01-29 00:00:25 -08:00
parent 46b402a633
commit 0428a1246e
3 changed files with 15 additions and 6 deletions

View file

@ -634,6 +634,7 @@ class Site < Sequel::Model
PurgeCacheOrderWorker.perform_async username, relative_path
purge_file_path = Pathname(relative_path).dirname.to_s
purge_file_path += '/' if purge_file_path != '/'
PurgeCacheOrderWorker.perform_async username, '/?surf=1' if purge_file_path == '/'
PurgeCacheOrderWorker.perform_async username, purge_file_path

View file

@ -217,6 +217,14 @@ describe 'site_files' do
@site.reload.title.must_equal title
end
it 'purges cache for /subdir/' do # (not /subdir which is just a redirect to /subdir/)
upload(
'dir' => 'subdir',
'files[]' => Rack::Test::UploadedFile.new('./tests/files/index.html', 'text/html')
)
PurgeCacheOrderWorker.jobs.select {|j| j['args'].last == '/subdir/'}.length.must_equal 1
end
it 'succeeds with valid file' do
initial_space_used = @site.space_used
uploaded_file = Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')

View file

@ -6,7 +6,7 @@ describe PurgeCacheWorker do
end
it 'handles 404 without exception' do
stub_request(:head, "http://#{@test_ip}/test.jpg").
stub_request(:head, "https://#{@test_ip}/test.jpg").
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
.to_return(status: 404)
@ -15,23 +15,23 @@ describe PurgeCacheWorker do
end
it 'sends a purge request' do
stub_request(:head, "http://#{@test_ip}/test.jpg").
stub_request(:head, "https://#{@test_ip}/test.jpg").
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
.to_return(status: 200)
worker = PurgeCacheWorker.new
worker.perform @test_ip, 'kyledrake', '/test.jpg'
assert_requested :head, "http://#{@test_ip}/test.jpg"
assert_requested :head, "https://#{@test_ip}/test.jpg"
end
it 'handles spaces correctly' do
stub_request(:head, "http://#{@test_ip}/te st.jpg").
stub_request(:head, "https://#{@test_ip}/te st.jpg").
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
.to_return(status: 200)
url = Addressable::URI.encode_component(
"http://#{@test_ip}/te st.jpg",
"https://#{@test_ip}/te st.jpg",
Addressable::URI::CharacterClasses::QUERY
)
@ -42,7 +42,7 @@ describe PurgeCacheWorker do
end
it 'works without forward slash' do
stub_request(:head, "http://#{@test_ip}/test.jpg").
stub_request(:head, "https://#{@test_ip}/test.jpg").
with(headers: {'Host' => 'kyledrake.neocities.org', 'Cache-Purge' => '1'})
.to_return(status: 200)