Welcome to mirror list, hosted at ThFree Co, Russian Federation.

with_uploads_shared_examples.rb « models « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c930ec1fce32cef6cd0b9abb76e7f5f927888c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true

RSpec.shared_examples 'model with uploads' do |supports_fileuploads|
  describe '.destroy' do
    before do
      stub_uploads_object_storage(uploader_class)

      model_object.public_send(upload_attribute).migrate!(ObjectStorage::Store::REMOTE)
    end

    context 'with mounted uploader' do
      it 'deletes remote uploads' do
        expect_any_instance_of(CarrierWave::Storage::Fog::File).to receive(:delete).and_call_original

        expect { model_object.destroy! }.to change { Upload.count }.by(-1)
      end
    end

    context 'with not mounted uploads', :sidekiq_might_not_need_inline, skip: !supports_fileuploads do
      context 'with local files' do
        let!(:uploads) { create_list(:upload, 2, 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 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
          expected_array = array_including(*uploads.map(&:path))
          expect_any_instance_of(Uploads::Fog).to receive(:delete_keys).with(expected_array)

          model_object.destroy!
        end
      end
    end
  end
end