mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fix and test purge cache
This commit is contained in:
parent
445ec92226
commit
3e4e85ceee
2 changed files with 12 additions and 2 deletions
|
@ -202,7 +202,7 @@ class Site < Sequel::Model
|
|||
|
||||
%w{index not_found}.each do |name|
|
||||
File.write files_path("#{name}.html"), render_template("#{name}.erb")
|
||||
purge_cache "#{name}.html"
|
||||
purge_cache "/#{name}.html"
|
||||
ScreenshotWorker.perform_async values[:username], "#{name}.html"
|
||||
end
|
||||
|
||||
|
@ -327,7 +327,8 @@ class Site < Sequel::Model
|
|||
end
|
||||
|
||||
def purge_cache(path)
|
||||
payload = {site: username, path: path}
|
||||
relative_path = path.gsub(base_files_path, '')
|
||||
payload = {site: username, path: relative_path}
|
||||
payload[:domain] = domain if !domain.empty?
|
||||
PurgeCacheWorker.perform_async payload
|
||||
end
|
||||
|
|
|
@ -11,16 +11,22 @@ describe 'site_files' do
|
|||
describe 'upload' do
|
||||
it 'succeeds with valid file' do
|
||||
site = Fabricate :site
|
||||
PurgeCacheWorker.jobs.clear
|
||||
post '/site_files/upload', {
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
|
||||
'csrf_token' => 'abcd'
|
||||
}, {'rack.session' => { 'id' => site.id, '_csrf_token' => 'abcd' }}
|
||||
last_response.body.must_match /successfully uploaded/i
|
||||
File.exists?(site.files_path('test.jpg')).must_equal true
|
||||
|
||||
queue_args = PurgeCacheWorker.jobs.first['args'].first
|
||||
queue_args['site'].must_equal site.username
|
||||
queue_args['path'].must_equal '/test.jpg'
|
||||
end
|
||||
|
||||
it 'works with directory path' do
|
||||
site = Fabricate :site
|
||||
PurgeCacheWorker.jobs.clear
|
||||
post '/site_files/upload', {
|
||||
'dir' => 'derpie/derptest',
|
||||
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
|
||||
|
@ -28,6 +34,9 @@ describe 'site_files' do
|
|||
}, {'rack.session' => { 'id' => site.id, '_csrf_token' => 'abcd' }}
|
||||
last_response.body.must_match /successfully uploaded/i
|
||||
File.exists?(site.files_path('derpie/derptest/test.jpg')).must_equal true
|
||||
|
||||
queue_args = PurgeCacheWorker.jobs.first['args'].first
|
||||
queue_args['path'].must_equal '/derpie/derptest/test.jpg'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue