forked from e621ng/e621ng
posts: fix expunging posts not deleting files.
Fix expungement to ignore the "file still in use" check.
This commit is contained in:
parent
24ad435067
commit
a844a1daf4
1
Gemfile
1
Gemfile
@ -74,4 +74,5 @@ group :test do
|
||||
gem "simplecov", :require => false
|
||||
gem "timecop"
|
||||
gem "fakeweb"
|
||||
gem "test_after_commit" # XXX remove me after upgrading to rails 5.
|
||||
end
|
||||
|
@ -337,6 +337,8 @@ GEM
|
||||
rest-client (~> 1.4)
|
||||
term-ansicolor (1.3.2)
|
||||
tins (~> 1.0)
|
||||
test_after_commit (1.1.0)
|
||||
activerecord (>= 3.2)
|
||||
therubyracer (0.12.3)
|
||||
libv8 (~> 3.16.14.15)
|
||||
ref
|
||||
@ -433,6 +435,7 @@ DEPENDENCIES
|
||||
streamio-ffmpeg
|
||||
stripe
|
||||
term-ansicolor
|
||||
test_after_commit
|
||||
therubyracer
|
||||
timecop
|
||||
twitter
|
||||
@ -443,4 +446,4 @@ DEPENDENCIES
|
||||
whenever
|
||||
|
||||
BUNDLED WITH
|
||||
1.14.5
|
||||
1.14.6
|
||||
|
@ -65,11 +65,13 @@ class Post < ActiveRecord::Base
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
module ClassMethods
|
||||
def delete_files(post_id, file_path, large_file_path, preview_file_path)
|
||||
post = Post.find(post_id)
|
||||
def delete_files(post_id, file_path, large_file_path, preview_file_path, force: false)
|
||||
unless force
|
||||
post = Post.find(post_id)
|
||||
|
||||
if post.file_path == file_path || post.large_file_path == large_file_path || post.preview_file_path == preview_file_path
|
||||
raise DeletionError.new("Files still in use; skipping deletion.")
|
||||
if post.file_path == file_path || post.large_file_path == large_file_path || post.preview_file_path == preview_file_path
|
||||
raise DeletionError.new("Files still in use; skipping deletion.")
|
||||
end
|
||||
end
|
||||
|
||||
# the large file and the preview don't necessarily exist. if so errors will be ignored.
|
||||
@ -84,7 +86,7 @@ class Post < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def delete_files
|
||||
Post.delete_files(id, file_path, large_file_path, preview_file_path)
|
||||
Post.delete_files(id, file_path, large_file_path, preview_file_path, force: true)
|
||||
end
|
||||
|
||||
def distribute_files
|
||||
|
@ -48,6 +48,7 @@ class ActionController::TestCase
|
||||
end
|
||||
|
||||
Delayed::Worker.delay_jobs = false
|
||||
TestAfterCommit.enabled = false
|
||||
|
||||
require "helpers/reportbooru_helper"
|
||||
class ActiveSupport::TestCase
|
||||
|
@ -33,7 +33,23 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "Deletion:" do
|
||||
context "Expunging a post" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:post)
|
||||
@upload = FactoryGirl.create(:jpg_upload)
|
||||
@upload.process!
|
||||
@post = @upload.post
|
||||
end
|
||||
|
||||
should "delete the files" do
|
||||
assert_equal(true, File.exists?(@post.preview_file_path))
|
||||
assert_equal(true, File.exists?(@post.large_file_path))
|
||||
assert_equal(true, File.exists?(@post.file_path))
|
||||
|
||||
TestAfterCommit.with_commits(true) do
|
||||
@post.expunge!
|
||||
end
|
||||
|
||||
assert_equal(false, File.exists?(@post.preview_file_path))
|
||||
assert_equal(false, File.exists?(@post.large_file_path))
|
||||
assert_equal(false, File.exists?(@post.file_path))
|
||||
end
|
||||
|
||||
context "that is status locked" do
|
||||
|
Loading…
Reference in New Issue
Block a user