improvements from feedback
This commit is contained in:
parent
b176b2ca8d
commit
939391af7b
3 changed files with 14 additions and 2 deletions
|
@ -14,7 +14,7 @@ class Upload < ActiveRecord::Base
|
|||
|
||||
# as the FileUploader is not mounted, the default CarrierWave ActiveRecord
|
||||
# hooks are not executed and the file will not be deleted
|
||||
after_commit :delete_file!, on: :destroy, if: -> { uploader_class <= FileUploader }
|
||||
after_destroy :delete_file!, if: -> { uploader_class <= FileUploader }
|
||||
|
||||
def self.hexdigest(path)
|
||||
Digest::SHA256.file(path).hexdigest
|
||||
|
|
|
@ -43,6 +43,18 @@ describe Upload do
|
|||
.to(a_string_matching(/\A\h{64}\z/))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'after_destroy' do
|
||||
context 'uploader is FileUploader-based' do
|
||||
subject { create(:upload, :issuable_upload) }
|
||||
|
||||
it 'calls delete_file!' do
|
||||
is_expected.to receive(:delete_file!)
|
||||
|
||||
subject.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#absolute_path' do
|
||||
|
|
|
@ -66,7 +66,7 @@ describe FileUploader do
|
|||
|
||||
it 'prune the store directory' do
|
||||
expect { uploader.remove! }
|
||||
.to change { File.exists?(store_dir) }.from(true).to(false)
|
||||
.to change { File.exist?(store_dir) }.from(true).to(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue