mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 09:42:36 +02:00
delete nested site_files when directory is deleted
This commit is contained in:
parent
e6aaba74fb
commit
fbe00f6f9c
3 changed files with 23 additions and 4 deletions
|
@ -659,6 +659,11 @@ class Site < Sequel::Model
|
||||||
begin
|
begin
|
||||||
FileUtils.rm files_path(path)
|
FileUtils.rm files_path(path)
|
||||||
rescue Errno::EISDIR
|
rescue Errno::EISDIR
|
||||||
|
site_files.each do |site_file|
|
||||||
|
if site_file.path.match /^#{path}\//
|
||||||
|
site_file.destroy
|
||||||
|
end
|
||||||
|
end
|
||||||
FileUtils.remove_dir files_path(path), true
|
FileUtils.remove_dir files_path(path), true
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ describe '/' do
|
||||||
@another_site = Fabricate :site
|
@another_site = Fabricate :site
|
||||||
@followed_site.toggle_follow @another_site
|
@followed_site.toggle_follow @another_site
|
||||||
visit '/'
|
visit '/'
|
||||||
find('.news-item', match: :first).text.must_match /#{@followed_site.username} followed #{@another_site.username}/i
|
find('.news-item', match: :first).text.must_match /#{@followed_site.username} started following the site of #{@another_site.username}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'loads my activities only' do
|
it 'loads my activities only' do
|
||||||
|
@ -37,7 +37,7 @@ describe '/' do
|
||||||
@followed_site = Fabricate :site
|
@followed_site = Fabricate :site
|
||||||
@site.toggle_follow @followed_site
|
@site.toggle_follow @followed_site
|
||||||
visit "/?event_id=#{@followed_site.events.first.id}"
|
visit "/?event_id=#{@followed_site.events.first.id}"
|
||||||
find('.news-item').text.must_match /you followed #{@followed_site.username}/i
|
find('.news-item').text.must_match /you started following the site of #{@followed_site.username}/i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,20 @@ describe 'site_files' do
|
||||||
File.exists?(file_path).must_equal false
|
File.exists?(file_path).must_equal false
|
||||||
SiteFile[site_id: @site.id, path: 'test.jpg'].must_be_nil
|
SiteFile[site_id: @site.id, path: 'test.jpg'].must_be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'deletes all files in a directory' do
|
||||||
|
upload(
|
||||||
|
'dir' => 'test',
|
||||||
|
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||||
|
)
|
||||||
|
upload(
|
||||||
|
'dir' => '',
|
||||||
|
'files[]' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||||
|
)
|
||||||
|
delete_file filename: 'test'
|
||||||
|
@site.site_files.select {|f| f.path =~ /^test\//}.length.must_equal 0
|
||||||
|
@site.site_files.select {|f| f.path =~ /^test/}.length.must_equal 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'upload' do
|
describe 'upload' do
|
||||||
|
|
Loading…
Add table
Reference in a new issue