diff options
author | Micaël Bergeron <mbergeron@gitlab.com> | 2018-01-31 10:59:35 -0500 |
---|---|---|
committer | Micaël Bergeron <mbergeron@gitlab.com> | 2018-02-06 08:48:56 -0500 |
commit | 939391af7bc471f1588ab75ab0cf08d8e4286a05 (patch) | |
tree | 54bdc9b0ef372395373d765f69ce00ecff26a4c6 | |
parent | b176b2ca8d87ac7a090dd4b67f6a9e87c8753389 (diff) | |
download | gitlab-ce-14256-upload-destroy-removes-file.tar.gz |
improvements from feedback14256-upload-destroy-removes-file
-rw-r--r-- | app/models/upload.rb | 2 | ||||
-rw-r--r-- | spec/models/upload_spec.rb | 12 | ||||
-rw-r--r-- | spec/uploaders/file_uploader_spec.rb | 2 |
3 files changed, 14 insertions, 2 deletions
diff --git a/app/models/upload.rb b/app/models/upload.rb index 1bbcc4e381d..99ad37dc892 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -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 diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 0dcaa026332..36b8e5d304f 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -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 diff --git a/spec/uploaders/file_uploader_spec.rb b/spec/uploaders/file_uploader_spec.rb index 80af2a206af..6a92e7fae51 100644 --- a/spec/uploaders/file_uploader_spec.rb +++ b/spec/uploaders/file_uploader_spec.rb @@ -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 |