Commit 939391af authored by Micaël Bergeron's avatar Micaël Bergeron

improvements from feedback

parent b176b2ca
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment