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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporter, feature_category: :importers do
subject(:importer) { described_class.new(project, client) }
let_it_be(:project) { create(:project) }
let(:client) { instance_double(Gitlab::GithubImport::Client) }
describe '#sequential_import', :clean_gitlab_redis_cache do
let_it_be(:mr) { create(:merge_request, source_project: project, target_branch: 'feature1') }
let_it_be(:mr_with_attachment) do
create(:merge_request,
source_project: project,
target_branch: 'feature2',
description: "![image](https://user-images.githubusercontent.com/1/uuid-1.png)"
)
end
it 'selects both merge requests, and selects only properties it needs' do
stubbed_collection = class_double(MergeRequest, each_batch: [])
expect(project.merge_requests).to receive(:id_not_in).with([]).and_return(stubbed_collection)
expect(stubbed_collection).to receive(:select).with(:id, :description, :iid).and_return(stubbed_collection)
importer.sequential_import
end
it 'executes importer only for the merge request with an attachment' do
expect_next_instance_of(
Gitlab::GithubImport::Importer::NoteAttachmentsImporter,
have_attributes(record_db_id: mr_with_attachment.id),
project,
client
) do |importer|
expect(importer).to receive(:execute)
end
importer.sequential_import
end
context 'when merge request has already been processed' do
before do
importer.mark_as_imported(mr_with_attachment)
end
it 'does not select merge requests that were processed' do
expect(project.merge_requests).to receive(:id_not_in).with([mr_with_attachment.id.to_s]).and_call_original
importer.sequential_import
end
it 'does not execute importer for the merge request with an attachment' do
expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).not_to receive(:new)
importer.sequential_import
end
end
end
describe '#sidekiq_worker_class' do
it { expect(importer.sidekiq_worker_class).to eq(Gitlab::GithubImport::Attachments::ImportMergeRequestWorker) }
end
describe '#collection_method' do
it { expect(importer.collection_method).to eq(:merge_request_attachments) }
end
describe '#object_type' do
it { expect(importer.object_type).to eq(:merge_request_attachment) }
end
describe '#id_for_already_imported_cache' do
let(:merge_request) { build_stubbed(:merge_request) }
it { expect(importer.id_for_already_imported_cache(merge_request)).to eq(merge_request.id) }
end
end
|