2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
shared_examples_for '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-02-15 15:39:39 +05:30
|
|
|
context 'with not mounted uploads', :sidekiq, skip: !supports_fileuploads do
|
|
|
|
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
|
|
|
|
expect_any_instance_of(Uploads::Fog).to receive(:delete_keys).with(uploads.map(&:path))
|
|
|
|
|
|
|
|
model_object.destroy
|
|
|
|
end
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|