debian-mirror-gitlab/spec/support/shared_examples/models/with_uploads_shared_examples.rb

51 lines
1.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2020-03-13 15:44:24 +05:30
RSpec.shared_examples 'model with uploads' do |supports_fileuploads|
2018-11-08 19:23:39 +05:30
describe '.destroy' do
before do
stub_uploads_object_storage(uploader_class)
model_object.public_send(upload_attribute).migrate!(ObjectStorage::Store::REMOTE)
end
2019-02-15 15:39:39 +05:30
context 'with mounted uploader' do
it 'deletes remote uploads' do
expect_any_instance_of(CarrierWave::Storage::Fog::File).to receive(:delete).and_call_original
2018-11-08 19:23:39 +05:30
2019-02-15 15:39:39 +05:30
expect { model_object.destroy }.to change { Upload.count }.by(-1)
end
2018-11-08 19:23:39 +05:30
end
2019-12-26 22:10:19 +05:30
context 'with not mounted uploads', :sidekiq_might_not_need_inline, skip: !supports_fileuploads do
2019-02-15 15:39:39 +05:30
context 'with local files' do
let!(:uploads) { create_list(:upload, 2, uploader: FileUploader, model: model_object) }
2018-11-08 19:23:39 +05:30
2019-02-15 15:39:39 +05:30
it 'deletes any FileUploader uploads which are not mounted' do
expect { model_object.destroy }.to change { Upload.count }.by(-3)
end
it 'deletes local files' do
expect_any_instance_of(Uploads::Local).to receive(:delete_keys).with(uploads.map(&:absolute_path))
model_object.destroy
end
end
context 'with remote files' do
let!(:uploads) { create_list(:upload, 2, :object_storage, uploader: FileUploader, model: model_object) }
it 'deletes any FileUploader uploads which are not mounted' do
expect { model_object.destroy }.to change { Upload.count }.by(-3)
end
it 'deletes remote files' do
2019-12-21 20:55:43 +05:30
expected_array = array_including(*uploads.map(&:path))
expect_any_instance_of(Uploads::Fog).to receive(:delete_keys).with(expected_array)
2019-02-15 15:39:39 +05:30
model_object.destroy
end
end
2018-11-08 19:23:39 +05:30
end
end
end