improvements from feedback

This commit is contained in:
Micaël Bergeron 2018-01-31 10:59:35 -05:00
parent b176b2ca8d
commit 939391af7b
3 changed files with 14 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -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