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

migrate_rake_spec.rb « uploads « gitlab « tasks « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8ea0a98a1dc1f98fc3ff05a11dc44707e63c85f1 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# frozen_string_literal: true

require 'rake_helper'

describe 'gitlab:uploads:migrate and migrate_to_local rake tasks' do
  let(:model_class) { nil }
  let(:uploader_class) { nil }
  let(:mounted_as) { nil }
  let(:batch_size) { 3 }

  before do
    stub_env('MIGRATION_BATCH_SIZE', batch_size.to_s)
    stub_uploads_object_storage(uploader_class)
    Rake.application.rake_require 'tasks/gitlab/uploads/migrate'

    allow(ObjectStorage::MigrateUploadsWorker).to receive(:perform_async)
  end

  context "for AvatarUploader" do
    let(:uploader_class) { AvatarUploader }
    let(:mounted_as) { :avatar }

    context "for Project" do
      let(:model_class) { Project }
      let!(:projects) { create_list(:project, 10, :with_avatar) }

      it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
    end

    context "for Group" do
      let(:model_class) { Group }

      before do
        create_list(:group, 10, :with_avatar)
      end

      it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
    end

    context "for User" do
      let(:model_class) { User }

      before do
        create_list(:user, 10, :with_avatar)
      end

      it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
    end
  end

  context "for AttachmentUploader" do
    let(:uploader_class) { AttachmentUploader }

    context "for Note" do
      let(:model_class) { Note }
      let(:mounted_as) { :attachment }

      before do
        create_list(:note, 10, :with_attachment)
      end

      it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
    end

    context "for Appearance" do
      let(:model_class) { Appearance }
      let(:mounted_as) { :logo }

      before do
        create(:appearance, :with_logos)
      end

      %i(logo header_logo).each do |mount|
        it_behaves_like 'enqueue upload migration jobs in batch', batch: 1 do
          let(:mounted_as) { mount }
        end
      end
    end
  end

  context "for FileUploader" do
    let(:uploader_class) { FileUploader }
    let(:model_class) { Project }

    before do
      create_list(:project, 10) do |model|
        uploader_class.new(model)
          .store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
      end
    end

    it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
  end

  context "for PersonalFileUploader" do
    let(:uploader_class) { PersonalFileUploader }
    let(:model_class) { PersonalSnippet }

    before do
      create_list(:personal_snippet, 10) do |model|
        uploader_class.new(model)
          .store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
      end
    end

    it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
  end

  context "for NamespaceFileUploader" do
    let(:uploader_class) { NamespaceFileUploader }
    let(:model_class) { Snippet }

    before do
      create_list(:snippet, 10) do |model|
        uploader_class.new(model)
          .store!(fixture_file_upload('spec/fixtures/doc_sample.txt'))
      end
    end

    it_behaves_like 'enqueue upload migration jobs in batch', batch: 4
  end
end