summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/github_import/importer
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/github_import/importer')
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb28
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb61
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb61
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb58
-rw-r--r--spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb57
-rw-r--r--spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb14
-rw-r--r--spec/lib/gitlab/github_import/importer/issues_importer_spec.rb33
-rw-r--r--spec/lib/gitlab/github_import/importer/labels_importer_spec.rb6
-rw-r--r--spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb7
-rw-r--r--spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb10
-rw-r--r--spec/lib/gitlab/github_import/importer/note_attachments_importer_spec.rb85
-rw-r--r--spec/lib/gitlab/github_import/importer/note_importer_spec.rb7
-rw-r--r--spec/lib/gitlab/github_import/importer/notes_importer_spec.rb14
-rw-r--r--spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb218
-rw-r--r--spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb6
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb15
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb50
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb10
-rw-r--r--spec/lib/gitlab/github_import/importer/release_attachments_importer_spec.rb57
-rw-r--r--spec/lib/gitlab/github_import/importer/releases_attachments_importer_spec.rb74
-rw-r--r--spec/lib/gitlab/github_import/importer/releases_importer_spec.rb27
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb32
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb4
26 files changed, 707 insertions, 237 deletions
diff --git a/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb
new file mode 100644
index 00000000000..5e60be44621
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/attachments/base_importer_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Attachments::BaseImporter do
+ subject(:importer) { importer_class.new(project, client) }
+
+ let(:project) { instance_double(Project, id: 1) }
+ let(:client) { instance_double(Gitlab::GithubImport::Client) }
+ let(:importer_class) do
+ Class.new(described_class) do
+ private
+
+ def collection_method
+ 'test'
+ end
+ end
+ end
+
+ describe '#each_object_to_import' do
+ context 'with not implemented #collection interface' do
+ it 'raises NotImplementedError' do
+ expect { importer.each_object_to_import }
+ .to raise_error(Gitlab::GithubImport::Exceptions::NotImplementedError, '#collection')
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb
new file mode 100644
index 00000000000..85bc67376d3
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/attachments/issues_importer_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Attachments::IssuesImporter 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(:issue_1) { create(:issue, project: project) }
+ let_it_be(:issue_2) { create(:issue, project: project) }
+
+ let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
+ let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+
+ it 'imports each project issue attachments' do
+ expect_next_instances_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2, false, *importer_attrs
+ ) do |note_attachments_importer|
+ expect(note_attachments_importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+
+ context 'when issue is already processed' do
+ it "doesn't import this issue attachments" do
+ importer.mark_as_imported(issue_1)
+
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter, *importer_attrs
+ ) do |note_attachments_importer|
+ expect(note_attachments_importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+ end
+ end
+
+ describe '#sidekiq_worker_class' do
+ it { expect(importer.sidekiq_worker_class).to eq(Gitlab::GithubImport::Attachments::ImportIssueWorker) }
+ end
+
+ describe '#collection_method' do
+ it { expect(importer.collection_method).to eq(:issue_attachments) }
+ end
+
+ describe '#object_type' do
+ it { expect(importer.object_type).to eq(:issue_attachment) }
+ end
+
+ describe '#id_for_already_imported_cache' do
+ let(:issue) { build_stubbed(:issue) }
+
+ it { expect(importer.id_for_already_imported_cache(issue)).to eq(issue.id) }
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb
new file mode 100644
index 00000000000..e4718c2d17c
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/attachments/merge_requests_importer_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Attachments::MergeRequestsImporter 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(:merge_request_1) { create(:merge_request, source_project: project, target_branch: 'feature1') }
+ let_it_be(:merge_request_2) { create(:merge_request, source_project: project, target_branch: 'feature2') }
+
+ let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
+ let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+
+ it 'imports each project merge request attachments' do
+ expect_next_instances_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter, 2, false, *importer_attrs
+ ) do |note_attachments_importer|
+ expect(note_attachments_importer).to receive(:execute)
+ end
+
+ importer.sequential_import
+ end
+
+ context 'when merge request is already processed' do
+ it "doesn't import this merge request attachments" do
+ importer.mark_as_imported(merge_request_1)
+
+ expect_next_instance_of(
+ Gitlab::GithubImport::Importer::NoteAttachmentsImporter, *importer_attrs
+ ) do |note_attachments_importer|
+ expect(note_attachments_importer).to receive(:execute)
+ end
+
+ 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
diff --git a/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb
new file mode 100644
index 00000000000..7ed353e1b71
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/attachments/notes_importer_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Attachments::NotesImporter 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(:note_1) { create(:note, project: project) }
+ let_it_be(:note_2) { create(:note, project: project) }
+ let_it_be(:system_note) { create(:note, :system, project: project) }
+
+ let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
+ let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+
+ it 'imports each project user note' do
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
+ .with(*importer_attrs).twice.and_return(importer_stub)
+ expect(importer_stub).to receive(:execute).twice
+
+ importer.sequential_import
+ end
+
+ context 'when note is already processed' do
+ it "doesn't import this note" do
+ importer.mark_as_imported(note_1)
+
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
+ .with(*importer_attrs).once.and_return(importer_stub)
+ expect(importer_stub).to receive(:execute).once
+
+ importer.sequential_import
+ end
+ end
+ end
+
+ describe '#sidekiq_worker_class' do
+ it { expect(importer.sidekiq_worker_class).to eq(Gitlab::GithubImport::Attachments::ImportNoteWorker) }
+ end
+
+ describe '#collection_method' do
+ it { expect(importer.collection_method).to eq(:note_attachments) }
+ end
+
+ describe '#object_type' do
+ it { expect(importer.object_type).to eq(:note_attachment) }
+ end
+
+ describe '#id_for_already_imported_cache' do
+ let(:note) { build_stubbed(:note) }
+
+ it { expect(importer.id_for_already_imported_cache(note)).to eq(note.id) }
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb
new file mode 100644
index 00000000000..b989345ae09
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/attachments/releases_importer_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::Attachments::ReleasesImporter 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(:release_1) { create(:release, project: project) }
+ let_it_be(:release_2) { create(:release, project: project) }
+
+ let(:importer_stub) { instance_double('Gitlab::GithubImport::Importer::NoteAttachmentsImporter') }
+ let(:importer_attrs) { [instance_of(Gitlab::GithubImport::Representation::NoteText), project, client] }
+
+ it 'imports each project release' do
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
+ .with(*importer_attrs).twice.and_return(importer_stub)
+ expect(importer_stub).to receive(:execute).twice
+
+ importer.sequential_import
+ end
+
+ context 'when note is already processed' do
+ it "doesn't import this release" do
+ importer.mark_as_imported(release_1)
+
+ expect(Gitlab::GithubImport::Importer::NoteAttachmentsImporter).to receive(:new)
+ .with(*importer_attrs).once.and_return(importer_stub)
+ expect(importer_stub).to receive(:execute).once
+
+ importer.sequential_import
+ end
+ end
+ end
+
+ describe '#sidekiq_worker_class' do
+ it { expect(importer.sidekiq_worker_class).to eq(Gitlab::GithubImport::Attachments::ImportReleaseWorker) }
+ end
+
+ describe '#collection_method' do
+ it { expect(importer.collection_method).to eq(:release_attachments) }
+ end
+
+ describe '#object_type' do
+ it { expect(importer.object_type).to eq(:release_attachment) }
+ end
+
+ describe '#id_for_already_imported_cache' do
+ let(:release) { build_stubbed(:release) }
+
+ it { expect(importer.id_for_already_imported_cache(release)).to eq(release.id) }
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb
index 6eb92cdeab9..a8dd6b4725d 100644
--- a/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/diff_notes_importer_spec.rb
@@ -7,14 +7,13 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter do
let(:client) { double(:client) }
let(:github_comment) do
- double(
- :response,
+ {
html_url: 'https://github.com/foo/bar/pull/42',
path: 'README.md',
commit_id: '123abc',
original_commit_id: 'original123abc',
diff_hunk: "@@ -1 +1 @@\n-Hello\n+Hello world",
- user: double(:user, id: 4, login: 'alice'),
+ user: { id: 4, login: 'alice' },
created_at: Time.zone.now,
updated_at: Time.zone.now,
line: 23,
@@ -29,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter do
sug1
```
BODY
- )
+ }
end
describe '#parallel?' do
@@ -98,9 +97,10 @@ RSpec.describe Gitlab::GithubImport::Importer::DiffNotesImporter do
.to receive(:each_object_to_import)
.and_yield(github_comment)
- expect(Gitlab::GithubImport::ImportDiffNoteWorker).to receive(:bulk_perform_in).with(1.second, [
- [project.id, an_instance_of(Hash), an_instance_of(String)]
- ], batch_size: 1000, batch_delay: 1.minute)
+ expect(Gitlab::GithubImport::ImportDiffNoteWorker).to receive(:bulk_perform_in)
+ .with(1.second, [
+ [project.id, an_instance_of(Hash), an_instance_of(String)]
+ ], batch_size: 1000, batch_delay: 1.minute)
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb b/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb
index 6b807bdf098..308b8185589 100644
--- a/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/issues_importer_spec.rb
@@ -9,20 +9,19 @@ RSpec.describe Gitlab::GithubImport::Importer::IssuesImporter do
let(:updated_at) { Time.new(2017, 1, 1, 12, 15) }
let(:github_issue) do
- double(
- :response,
+ {
number: 42,
title: 'My Issue',
body: 'This is my issue',
- milestone: double(:milestone, number: 4),
+ milestone: { number: 4 },
state: 'open',
- assignees: [double(:user, id: 4, login: 'alice')],
- labels: [double(:label, name: 'bug')],
- user: double(:user, id: 4, login: 'alice'),
+ assignees: [{ id: 4, login: 'alice' }],
+ labels: [{ name: 'bug' }],
+ user: { id: 4, login: 'alice' },
created_at: created_at,
updated_at: updated_at,
pull_request: false
- )
+ }
end
describe '#parallel?' do
@@ -110,4 +109,24 @@ RSpec.describe Gitlab::GithubImport::Importer::IssuesImporter do
.to eq(42)
end
end
+
+ describe '#increment_object_counter?' do
+ let(:importer) { described_class.new(project, client) }
+
+ context 'when issue is a pull request' do
+ let(:github_issue) { { pull_request: { url: 'some_url' } } }
+
+ it 'returns false' do
+ expect(importer).not_to be_increment_object_counter(github_issue)
+ end
+ end
+
+ context 'when issue is a regular issue' do
+ let(:github_issue) { {} }
+
+ it 'returns true' do
+ expect(importer).to be_increment_object_counter(github_issue)
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb b/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb
index ca9d3e1e21c..81d534c566f 100644
--- a/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_red
describe '#build_labels' do
it 'returns an Array containnig label rows' do
- label = double(:label, name: 'bug', color: 'ffffff')
+ label = { name: 'bug', color: 'ffffff' }
expect(importer).to receive(:each_label).and_return([label])
@@ -41,7 +41,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_red
it 'does not create labels that already exist' do
create(:label, project: project, title: 'bug')
- label = double(:label, name: 'bug', color: 'ffffff')
+ label = { name: 'bug', color: 'ffffff' }
expect(importer).to receive(:each_label).and_return([label])
expect(importer.build_labels).to be_empty
@@ -60,7 +60,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_red
describe '#build' do
let(:label_hash) do
- importer.build(double(:label, name: 'bug', color: 'ffffff'))
+ importer.build({ name: 'bug', color: 'ffffff' })
end
it 'returns the attributes of the label as a Hash' do
diff --git a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
index 251829b83a0..99536588718 100644
--- a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb
@@ -118,9 +118,10 @@ RSpec.describe Gitlab::GithubImport::Importer::LfsObjectsImporter do
expect(service).to receive(:execute).and_return([lfs_download_object])
end
- expect(Gitlab::GithubImport::ImportLfsObjectWorker).to receive(:bulk_perform_in).with(1.second, [
- [project.id, an_instance_of(Hash), an_instance_of(String)]
- ], batch_size: 1000, batch_delay: 1.minute)
+ expect(Gitlab::GithubImport::ImportLfsObjectWorker).to receive(:bulk_perform_in)
+ .with(1.second, [
+ [project.id, an_instance_of(Hash), an_instance_of(String)]
+ ], batch_size: 1000, batch_delay: 1.minute)
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb b/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
index dad1efc5a8d..04d76bd1f06 100644
--- a/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb
@@ -11,8 +11,7 @@ RSpec.describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab
let(:updated_at) { Time.new(2017, 1, 1, 12, 15) }
let(:milestone) do
- double(
- :milestone,
+ {
number: 1,
title: '1.0',
description: 'The first release',
@@ -20,12 +19,11 @@ RSpec.describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab
due_on: due_on,
created_at: created_at,
updated_at: updated_at
- )
+ }
end
let(:milestone2) do
- double(
- :milestone,
+ {
number: 1,
title: '1.0',
description: 'The first release',
@@ -33,7 +31,7 @@ RSpec.describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab
due_on: nil,
created_at: created_at,
updated_at: updated_at
- )
+ }
end
describe '#execute' do
diff --git a/spec/lib/gitlab/github_import/importer/note_attachments_importer_spec.rb b/spec/lib/gitlab/github_import/importer/note_attachments_importer_spec.rb
new file mode 100644
index 00000000000..7d4e3c3bcce
--- /dev/null
+++ b/spec/lib/gitlab/github_import/importer/note_attachments_importer_spec.rb
@@ -0,0 +1,85 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubImport::Importer::NoteAttachmentsImporter do
+ subject(:importer) { described_class.new(note_text, project, client) }
+
+ let_it_be(:project) { create(:project) }
+
+ let(:note_text) { Gitlab::GithubImport::Representation::NoteText.from_db_record(record) }
+ let(:client) { instance_double('Gitlab::GithubImport::Client') }
+
+ let(:doc_url) { 'https://github.com/nickname/public-test-repo/files/9020437/git-cheat-sheet.txt' }
+ let(:image_url) { 'https://user-images.githubusercontent.com/6833842/0cf366b61ef2.jpeg' }
+ let(:image_tag_url) { 'https://user-images.githubusercontent.com/6833842/0cf366b61ea5.jpeg' }
+ let(:text) do
+ <<-TEXT.split("\n").map(&:strip).join("\n")
+ Some text...
+
+ [special-doc](#{doc_url})
+ ![image.jpeg](#{image_url})
+ <img width=\"248\" alt=\"tag-image\" src="#{image_tag_url}">
+ TEXT
+ end
+
+ shared_examples 'updates record description' do
+ it do
+ importer.execute
+
+ record.reload
+ expect(record.description).to start_with("Some text...\n\n[special-doc](/uploads/")
+ expect(record.description).to include('![image.jpeg](/uploads/')
+ expect(record.description).to include('<img width="248" alt="tag-image" src="/uploads')
+ end
+ end
+
+ describe '#execute' do
+ let(:downloader_stub) { instance_double(Gitlab::GithubImport::AttachmentsDownloader) }
+ let(:tmp_stub_doc) { Tempfile.create('attachment_download_test.txt') }
+ let(:tmp_stub_image) { Tempfile.create('image.jpeg') }
+ let(:tmp_stub_image_tag) { Tempfile.create('image-tag.jpeg') }
+
+ before do
+ allow(Gitlab::GithubImport::AttachmentsDownloader).to receive(:new).with(doc_url)
+ .and_return(downloader_stub)
+ allow(Gitlab::GithubImport::AttachmentsDownloader).to receive(:new).with(image_url)
+ .and_return(downloader_stub)
+ allow(Gitlab::GithubImport::AttachmentsDownloader).to receive(:new).with(image_tag_url)
+ .and_return(downloader_stub)
+ allow(downloader_stub).to receive(:perform).and_return(tmp_stub_doc, tmp_stub_image, tmp_stub_image_tag)
+ allow(downloader_stub).to receive(:delete).exactly(3).times
+ end
+
+ context 'when importing release attachments' do
+ let(:record) { create(:release, project: project, description: text) }
+
+ it_behaves_like 'updates record description'
+ end
+
+ context 'when importing issue attachments' do
+ let(:record) { create(:issue, project: project, description: text) }
+
+ it_behaves_like 'updates record description'
+ end
+
+ context 'when importing merge request attachments' do
+ let(:record) { create(:merge_request, source_project: project, description: text) }
+
+ it_behaves_like 'updates record description'
+ end
+
+ context 'when importing note attachments' do
+ let(:record) { create(:note, project: project, note: text) }
+
+ it 'updates note text with new attachment urls' do
+ importer.execute
+
+ record.reload
+ expect(record.note).to start_with("Some text...\n\n[special-doc](/uploads/")
+ expect(record.note).to include('![image.jpeg](/uploads/')
+ expect(record.note).to include('<img width="248" alt="tag-image" src="/uploads')
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer/note_importer_spec.rb b/spec/lib/gitlab/github_import/importer/note_importer_spec.rb
index 165f543525d..c60ecd85e92 100644
--- a/spec/lib/gitlab/github_import/importer/note_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/note_importer_spec.rb
@@ -160,6 +160,13 @@ RSpec.describe Gitlab::GithubImport::Importer::NoteImporter do
expect(project.notes.take).to be_valid
end
+
+ # rubocop:disable RSpec/AnyInstanceOf
+ it 'skips markdown field cache callback' do
+ expect_any_instance_of(Note).not_to receive(:refresh_markdown_cache)
+ importer.execute
+ end
+ # rubocop:enable RSpec/AnyInstanceOf
end
describe '#find_noteable_id' do
diff --git a/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb
index 3b4fe652da8..ca4560b6a1a 100644
--- a/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb
@@ -7,15 +7,14 @@ RSpec.describe Gitlab::GithubImport::Importer::NotesImporter do
let(:client) { double(:client) }
let(:github_comment) do
- double(
- :response,
+ {
html_url: 'https://github.com/foo/bar/issues/42',
- user: double(:user, id: 4, login: 'alice'),
+ user: { id: 4, login: 'alice' },
body: 'Hello world',
created_at: Time.zone.now,
updated_at: Time.zone.now,
id: 1
- )
+ }
end
describe '#parallel?' do
@@ -84,9 +83,10 @@ RSpec.describe Gitlab::GithubImport::Importer::NotesImporter do
.to receive(:each_object_to_import)
.and_yield(github_comment)
- expect(Gitlab::GithubImport::ImportNoteWorker).to receive(:bulk_perform_in).with(1.second, [
- [project.id, an_instance_of(Hash), an_instance_of(String)]
- ], batch_size: 1000, batch_delay: 1.minute)
+ expect(Gitlab::GithubImport::ImportNoteWorker).to receive(:bulk_perform_in)
+ .with(1.second, [
+ [project.id, an_instance_of(Hash), an_instance_of(String)]
+ ], batch_size: 1000, batch_delay: 1.minute)
waiter = importer.parallel_import
diff --git a/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb b/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
index 6dc6db739f4..027b2ac422e 100644
--- a/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/protected_branch_importer_spec.rb
@@ -5,11 +5,21 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
subject(:importer) { described_class.new(github_protected_branch, project, client) }
+ let(:branch_name) { 'protection' }
let(:allow_force_pushes_on_github) { true }
+ let(:required_conversation_resolution) { false }
+ let(:required_signatures) { false }
+ let(:required_pull_request_reviews) { false }
+ let(:expected_push_access_level) { Gitlab::Access::MAINTAINER }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+ let(:expected_allow_force_push) { true }
let(:github_protected_branch) do
Gitlab::GithubImport::Representation::ProtectedBranch.new(
- id: 'protection',
- allow_force_pushes: allow_force_pushes_on_github
+ id: branch_name,
+ allow_force_pushes: allow_force_pushes_on_github,
+ required_conversation_resolution: required_conversation_resolution,
+ required_signatures: required_signatures,
+ required_pull_request_reviews: required_pull_request_reviews
)
end
@@ -23,8 +33,8 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
let(:expected_ruleset) do
{
name: 'protection',
- push_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }],
- merge_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINER }],
+ push_access_levels_attributes: [{ access_level: expected_push_access_level }],
+ merge_access_levels_attributes: [{ access_level: expected_merge_access_level }],
allow_force_push: expected_allow_force_push
}
end
@@ -47,6 +57,18 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
end
end
+ shared_examples 'does not change project attributes' do
+ it 'does not change only_allow_merge_if_all_discussions_are_resolved' do
+ expect { importer.execute }.not_to change(project, :only_allow_merge_if_all_discussions_are_resolved)
+ end
+
+ it 'does not change push_rule for the project' do
+ expect(project).not_to receive(:push_rule)
+
+ importer.execute
+ end
+ end
+
context 'when branch is protected on GitLab' do
before do
create(
@@ -87,5 +109,193 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchImporter do
it_behaves_like 'create branch protection by the strictest ruleset'
end
+
+ context "when branch is default" do
+ before do
+ allow(project).to receive(:default_branch).and_return(branch_name)
+ end
+
+ context 'when required_conversation_resolution rule is enabled' do
+ let(:required_conversation_resolution) { true }
+
+ it 'changes project settings' do
+ expect { importer.execute }.to change(project, :only_allow_merge_if_all_discussions_are_resolved).to(true)
+ end
+ end
+
+ context 'when required_conversation_resolution rule is disabled' do
+ let(:required_conversation_resolution) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+
+ context 'when required_signatures rule is enabled' do
+ let(:required_signatures) { true }
+ let(:push_rules_feature_available?) { true }
+
+ before do
+ stub_licensed_features(push_rules: push_rules_feature_available?)
+ end
+
+ context 'when the push_rules feature is available', if: Gitlab.ee? do
+ context 'when project push_rules did previously exist' do
+ before do
+ create(:push_rule, project: project)
+ end
+
+ it 'updates push_rule reject_unsigned_commits attribute' do
+ expect { importer.execute }.to change { project.reload.push_rule.reject_unsigned_commits }.to(true)
+ end
+ end
+
+ context 'when project push_rules did not previously exist' do
+ it 'creates project push_rule with the enabled reject_unsigned_commits attribute' do
+ expect { importer.execute }.to change(project, :push_rule).from(nil)
+ expect(project.push_rule.reject_unsigned_commits).to be_truthy
+ end
+ end
+ end
+
+ context 'when the push_rules feature is not available' do
+ let(:push_rules_feature_available?) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+ end
+
+ context 'when required_signatures rule is disabled' do
+ let(:required_signatures) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+ end
+
+ context 'when branch is not default' do
+ context 'when required_conversation_resolution rule is enabled' do
+ let(:required_conversation_resolution) { true }
+
+ it_behaves_like 'does not change project attributes'
+ end
+
+ context 'when required_conversation_resolution rule is disabled' do
+ let(:required_conversation_resolution) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+
+ context 'when required_signatures rule is enabled' do
+ let(:required_signatures) { true }
+
+ it_behaves_like 'does not change project attributes'
+ end
+
+ context 'when required_signatures rule is disabled' do
+ let(:required_signatures) { false }
+
+ it_behaves_like 'does not change project attributes'
+ end
+ end
+
+ context 'when required_pull_request_reviews rule is enabled on GitHub' do
+ let(:required_pull_request_reviews) { true }
+ let(:expected_push_access_level) { Gitlab::Access::NO_ACCESS }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+
+ context 'when required_pull_request_reviews rule is disabled on GitHub' do
+ let(:required_pull_request_reviews) { false }
+
+ context 'when branch is default' do
+ before do
+ allow(project).to receive(:default_branch).and_return(branch_name)
+ end
+
+ context 'when default branch protection = Gitlab::Access::PROTECTION_DEV_CAN_PUSH' do
+ before do
+ stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_PUSH)
+ end
+
+ let(:expected_push_access_level) { Gitlab::Access::DEVELOPER }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+
+ context 'when default branch protection = Gitlab::Access::PROTECTION_DEV_CAN_MERGE' do
+ before do
+ stub_application_setting(default_branch_protection: Gitlab::Access::PROTECTION_DEV_CAN_MERGE)
+ end
+
+ let(:expected_push_access_level) { Gitlab::Access::MAINTAINER }
+ let(:expected_merge_access_level) { Gitlab::Access::DEVELOPER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+ end
+
+ context 'when branch is protected on GitLab' do
+ let(:protected_branch) do
+ create(
+ :protected_branch,
+ project: project,
+ name: 'protect*',
+ allow_force_push: true
+ )
+ end
+
+ let(:push_access_level) { protected_branch.push_access_levels.first }
+ let(:merge_access_level) { protected_branch.merge_access_levels.first }
+
+ context 'when there is branch protection rule for the role' do
+ context 'when No one can merge' do
+ before do
+ merge_access_level.update_column(:access_level, Gitlab::Access::NO_ACCESS)
+ end
+
+ let(:expected_push_access_level) { push_access_level.access_level }
+ let(:expected_merge_access_level) { Gitlab::Access::NO_ACCESS }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+
+ context 'when Maintainers and Developers can merge' do
+ before do
+ merge_access_level.update_column(:access_level, Gitlab::Access::DEVELOPER)
+ end
+
+ let(:gitlab_push_access_level) { push_access_level.access_level }
+ let(:gitlab_merge_access_level) { merge_access_level.access_level }
+ let(:expected_push_access_level) { gitlab_push_access_level }
+ let(:expected_merge_access_level) { [gitlab_merge_access_level, github_default_merge_access_level].max }
+ let(:github_default_merge_access_level) do
+ Gitlab::GithubImport::Importer::ProtectedBranchImporter::GITHUB_DEFAULT_MERGE_ACCESS_LEVEL
+ end
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+ end
+
+ context 'when there is no branch protection rule for the role' do
+ before do
+ push_access_level.update_column(:user_id, project.owner.id)
+ merge_access_level.update_column(:user_id, project.owner.id)
+ end
+
+ let(:expected_push_access_level) { ProtectedBranch::PushAccessLevel::GITLAB_DEFAULT_ACCESS_LEVEL }
+ let(:expected_merge_access_level) { Gitlab::Access::MAINTAINER }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+ end
+
+ context 'when branch is neither default nor protected on GitLab' do
+ let(:expected_push_access_level) { ProtectedBranch::PushAccessLevel::GITLAB_DEFAULT_ACCESS_LEVEL }
+ let(:expected_merge_access_level) { ProtectedBranch::MergeAccessLevel::GITLAB_DEFAULT_ACCESS_LEVEL }
+
+ it_behaves_like 'create branch protection by the strictest ruleset'
+ end
+ end
end
end
diff --git a/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb b/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb
index 4e9208be985..a0ced456391 100644
--- a/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/protected_branches_importer_spec.rb
@@ -23,11 +23,13 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchesImporter do
let(:github_protection_rule) do
response = Struct.new(:name, :url, :required_signatures, :enforce_admins, :required_linear_history,
:allow_force_pushes, :allow_deletion, :block_creations, :required_conversation_resolution,
+ :required_pull_request_reviews,
keyword_init: true
)
required_signatures = Struct.new(:url, :enabled, keyword_init: true)
enforce_admins = Struct.new(:url, :enabled, keyword_init: true)
allow_option = Struct.new(:enabled, keyword_init: true)
+ required_pull_request_reviews = Struct.new(:url, :dismissal_restrictions, keyword_init: true)
response.new(
name: 'main',
url: 'https://example.com/branches/main/protection',
@@ -53,6 +55,10 @@ RSpec.describe Gitlab::GithubImport::Importer::ProtectedBranchesImporter do
),
required_conversation_resolution: allow_option.new(
enabled: false
+ ),
+ required_pull_request_reviews: required_pull_request_reviews.new(
+ url: 'https://example.com/branches/main/protection/required_pull_request_reviews',
+ dismissal_restrictions: {}
)
)
end
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb
index 016f6e5377b..f3a9bbac785 100644
--- a/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_request_merged_by_importer_spec.rb
@@ -7,15 +7,16 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestMergedByImporter, :cle
let(:project) { merge_request.project }
let(:merged_at) { Time.new(2017, 1, 1, 12, 00).utc }
- let(:client_double) { double(user: double(id: 999, login: 'merger', email: 'merger@email.com')) }
- let(:merger_user) { double(id: 999, login: 'merger') }
+ let(:client_double) { double(user: { id: 999, login: 'merger', email: 'merger@email.com' } ) }
+ let(:merger_user) { { id: 999, login: 'merger' } }
let(:pull_request) do
- instance_double(
- Gitlab::GithubImport::Representation::PullRequest,
- iid: merge_request.iid,
- merged_at: merged_at,
- merged_by: merger_user
+ Gitlab::GithubImport::Representation::PullRequest.from_api_response(
+ {
+ number: merge_request.iid,
+ merged_at: merged_at,
+ merged_by: merger_user
+ }
)
end
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb
index a6da40f47f1..fb6024d0952 100644
--- a/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_request_review_importer_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestReviewImporter, :clean
let_it_be(:merge_request) { create(:merge_request) }
let(:project) { merge_request.project }
- let(:client_double) { double(user: double(id: 999, login: 'author', email: 'author@email.com')) }
+ let(:client_double) { double(user: { id: 999, login: 'author', email: 'author@email.com' }) }
let(:submitted_at) { Time.new(2017, 1, 1, 12, 00).utc }
subject { described_class.new(review, project, client_double) }
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
index c5846fa7a87..aa92abdb110 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests_importer_spec.rb
@@ -8,33 +8,30 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
let(:client) { double(:client) }
let(:pull_request) do
- double(
- :response,
+ {
number: 42,
title: 'My Pull Request',
body: 'This is my pull request',
state: 'closed',
- head: double(
- :head,
+ head: {
sha: '123abc',
ref: 'my-feature',
- repo: double(:repo, id: 400),
- user: double(:user, id: 4, login: 'alice')
- ),
- base: double(
- :base,
+ repo: { id: 400 },
+ user: { id: 4, login: 'alice' }
+ },
+ base: {
sha: '456def',
ref: 'master',
- repo: double(:repo, id: 200)
- ),
- milestone: double(:milestone, number: 4),
- user: double(:user, id: 4, login: 'alice'),
- assignee: double(:user, id: 4, login: 'alice'),
- merged_by: double(:user, id: 4, login: 'alice'),
+ repo: { id: 200 }
+ },
+ milestone: { number: 4 },
+ user: { id: 4, login: 'alice' },
+ assignee: { id: 4, login: 'alice' },
+ merged_by: { id: 4, login: 'alice' },
created_at: 1.second.ago,
updated_at: 1.second.ago,
merged_at: 1.second.ago
- )
+ }
end
describe '#parallel?' do
@@ -184,12 +181,11 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
context 'when the pull request was updated after the last update' do
let(:pr) do
- double(
- :pr,
+ {
updated_at: Time.zone.now,
- head: double(:head, sha: '123'),
- base: double(:base, sha: '456')
- )
+ head: { sha: '123' },
+ base: { sha: '456' }
+ }
end
before do
@@ -201,7 +197,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
it 'returns true when the head SHA is not present' do
expect(importer)
.to receive(:commit_exists?)
- .with(pr.head.sha)
+ .with('123')
.and_return(false)
expect(importer.update_repository?(pr)).to eq(true)
@@ -210,12 +206,12 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
it 'returns true when the base SHA is not present' do
expect(importer)
.to receive(:commit_exists?)
- .with(pr.head.sha)
+ .with('123')
.and_return(true)
expect(importer)
.to receive(:commit_exists?)
- .with(pr.base.sha)
+ .with('456')
.and_return(false)
expect(importer.update_repository?(pr)).to eq(true)
@@ -224,12 +220,12 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
it 'returns false if both the head and base SHAs are present' do
expect(importer)
.to receive(:commit_exists?)
- .with(pr.head.sha)
+ .with('123')
.and_return(true)
expect(importer)
.to receive(:commit_exists?)
- .with(pr.base.sha)
+ .with('456')
.and_return(true)
expect(importer.update_repository?(pr)).to eq(false)
@@ -238,7 +234,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsImporter do
context 'when the pull request was updated before the last update' do
it 'returns false' do
- pr = double(:pr, updated_at: 1.year.ago)
+ pr = { updated_at: 1.year.ago }
allow(project)
.to receive(:last_repository_updated_at)
diff --git a/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb
index 0eb86feb040..5f9c73cbfff 100644
--- a/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_requests_reviews_importer_spec.rb
@@ -23,7 +23,7 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsReviewsImporter do
end
describe '#id_for_already_imported_cache' do
- it { expect(subject.id_for_already_imported_cache(double(id: 1))).to eq(1) }
+ it { expect(subject.id_for_already_imported_cache({ id: 1 })).to eq(1) }
end
describe '#each_object_to_import', :clean_gitlab_redis_cache do
@@ -36,15 +36,11 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsReviewsImporter do
)
end
- let(:review) { double(id: 1) }
+ let(:review) { { id: 1 } }
it 'fetches the pull requests reviews data' do
page = double(objects: [review], number: 1)
- expect(review)
- .to receive(:merge_request_id=)
- .with(merge_request.id)
-
expect(client)
.to receive(:each_page)
.exactly(:once) # ensure to be cached on the second call
@@ -55,6 +51,8 @@ RSpec.describe Gitlab::GithubImport::Importer::PullRequestsReviewsImporter do
.to yield_with_args(review)
subject.each_object_to_import {}
+
+ expect(review[:merge_request_id]).to eq(merge_request.id)
end
it 'skips cached pages' do
diff --git a/spec/lib/gitlab/github_import/importer/release_attachments_importer_spec.rb b/spec/lib/gitlab/github_import/importer/release_attachments_importer_spec.rb
deleted file mode 100644
index 4779f9c8982..00000000000
--- a/spec/lib/gitlab/github_import/importer/release_attachments_importer_spec.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter do
- subject(:importer) { described_class.new(release_attachments, project, client) }
-
- let_it_be(:project) { create(:project) }
-
- let(:client) { instance_double('Gitlab::GithubImport::Client') }
- let(:release) { create(:release, project: project, description: description) }
- let(:release_attachments) do
- Gitlab::GithubImport::Representation::ReleaseAttachments
- .from_json_hash(release_db_id: release.id, description: release.description)
- end
-
- let(:doc_url) { 'https://github.com/nickname/public-test-repo/files/9020437/git-cheat-sheet.txt' }
- let(:image_url) { 'https://user-images.githubusercontent.com/6833842/0cf366b61ef2.jpeg' }
- let(:description) do
- <<-TEXT.strip
- Some text...
-
- [special-doc](#{doc_url})
- ![image.jpeg](#{image_url})
- TEXT
- end
-
- describe '#execute' do
- let(:downloader_stub) { instance_double(Gitlab::GithubImport::AttachmentsDownloader) }
- let(:tmp_stub_doc) { Tempfile.create('attachment_download_test.txt') }
- let(:tmp_stub_image) { Tempfile.create('image.jpeg') }
-
- context 'when importing doc attachment' do
- before do
- allow(Gitlab::GithubImport::AttachmentsDownloader).to receive(:new).with(doc_url)
- .and_return(downloader_stub)
- allow(Gitlab::GithubImport::AttachmentsDownloader).to receive(:new).with(image_url)
- .and_return(downloader_stub)
- allow(downloader_stub).to receive(:perform).and_return(tmp_stub_doc, tmp_stub_image)
- allow(downloader_stub).to receive(:delete).twice
-
- allow(UploadService).to receive(:new)
- .with(project, tmp_stub_doc, FileUploader).and_call_original
- allow(UploadService).to receive(:new)
- .with(project, tmp_stub_image, FileUploader).and_call_original
- end
-
- it 'updates release description with new attachment url' do
- importer.execute
-
- release.reload
- expect(release.description).to start_with("Some text...\n\n [special-doc](/uploads/")
- expect(release.description).to include('![image.jpeg](/uploads/')
- end
- end
- end
-end
diff --git a/spec/lib/gitlab/github_import/importer/releases_attachments_importer_spec.rb b/spec/lib/gitlab/github_import/importer/releases_attachments_importer_spec.rb
deleted file mode 100644
index 1aeb3462cd5..00000000000
--- a/spec/lib/gitlab/github_import/importer/releases_attachments_importer_spec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::GithubImport::Importer::ReleasesAttachmentsImporter do
- subject { described_class.new(project, client) }
-
- let_it_be(:project) { create(:project) }
-
- let(:client) { instance_double(Gitlab::GithubImport::Client) }
-
- describe '#each_object_to_import', :clean_gitlab_redis_cache do
- let!(:release_1) { create(:release, project: project) }
- let!(:release_2) { create(:release, project: project) }
-
- it 'iterates each project release' do
- list = []
- subject.each_object_to_import do |object|
- list << object
- end
- expect(list).to contain_exactly(release_1, release_2)
- end
-
- context 'when release is already processed' do
- it "doesn't process this release" do
- subject.mark_as_imported(release_1)
-
- list = []
- subject.each_object_to_import do |object|
- list << object
- end
- expect(list).to contain_exactly(release_2)
- end
- end
- end
-
- describe '#representation_class' do
- it { expect(subject.representation_class).to eq(Gitlab::GithubImport::Representation::ReleaseAttachments) }
- end
-
- describe '#importer_class' do
- it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::ReleaseAttachmentsImporter) }
- end
-
- describe '#sidekiq_worker_class' do
- it { expect(subject.sidekiq_worker_class).to eq(Gitlab::GithubImport::ImportReleaseAttachmentsWorker) }
- end
-
- describe '#collection_method' do
- it { expect(subject.collection_method).to eq(:release_attachments) }
- end
-
- describe '#object_type' do
- it { expect(subject.object_type).to eq(:release_attachment) }
- end
-
- describe '#id_for_already_imported_cache' do
- let(:release) { build_stubbed(:release) }
-
- it { expect(subject.id_for_already_imported_cache(release)).to eq(release.id) }
- end
-
- describe '#object_representation' do
- let(:release) { build_stubbed(:release) }
-
- it 'returns release attachments representation' do
- representation = subject.object_representation(release)
-
- expect(representation.class).to eq subject.representation_class
- expect(representation.release_db_id).to eq release.id
- expect(representation.description).to eq release.description
- end
- end
-end
diff --git a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb
index b0f553dbef7..84d639a09ef 100644
--- a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb
@@ -10,22 +10,21 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
let(:created_at) { Time.new(2017, 1, 1, 12, 00) }
let(:released_at) { Time.new(2017, 1, 1, 12, 00) }
let(:author) do
- double(
+ {
login: 'User A',
id: 1
- )
+ }
end
let(:github_release) do
- double(
- :github_release,
+ {
tag_name: '1.0',
name: github_release_name,
body: 'This is my release',
created_at: created_at,
published_at: released_at,
author: author
- )
+ }
end
def stub_email_for_github_username(user_name = 'User A', user_email = 'user@example.com')
@@ -56,7 +55,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
end
it 'imports draft releases' do
- release_double = double(
+ release_double = {
name: 'Test',
body: 'This is description',
tag_name: '1.0',
@@ -65,7 +64,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
updated_at: created_at,
published_at: nil,
author: author
- )
+ }
expect(importer).to receive(:each_release).and_return([release_double])
@@ -101,7 +100,7 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
end
it 'uses a default release description if none is provided' do
- expect(github_release).to receive(:body).and_return('')
+ github_release[:body] = nil
expect(importer).to receive(:each_release).and_return([github_release])
release = importer.build_releases.first
@@ -110,10 +109,10 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
end
it 'does not create releases that have a NULL tag' do
- null_tag_release = double(
+ null_tag_release = {
name: 'NULL Test',
tag_name: nil
- )
+ }
expect(importer).to receive(:each_release).and_return([null_tag_release])
expect(importer.build_releases).to be_empty
@@ -179,13 +178,13 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
end
it 'returns ghost user when author is empty in Github release' do
- allow(github_release).to receive(:author).and_return(nil)
+ github_release[:author] = nil
expect(release_hash[:author_id]).to eq(Gitlab::GithubImport.ghost_user_id)
end
context 'when Github author is not found in Gitlab' do
- let(:author) { double(login: 'octocat', id: 1 ) }
+ let(:author) { { login: 'octocat', id: 1 } }
before do
# Stub user email which does not match a Gitlab user.
@@ -222,11 +221,11 @@ RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter do
describe '#description_for' do
it 'returns the description when present' do
- expect(importer.description_for(github_release)).to eq(github_release.body)
+ expect(importer.description_for(github_release)).to eq(github_release[:body])
end
it 'returns a generated description when one is not present' do
- allow(github_release).to receive(:body).and_return('')
+ github_release[:body] = nil
expect(importer.description_for(github_release)).to eq('Release for tag 1.0')
end
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb
index 471302cb31b..081d08edfb3 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_diff_notes_importer_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointDiffNotesImporter d
it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::DiffNoteImporter) }
it { expect(subject.collection_method).to eq(:pull_request_comments) }
it { expect(subject.object_type).to eq(:diff_note) }
- it { expect(subject.id_for_already_imported_cache(double(id: 1))).to eq(1) }
+ it { expect(subject.id_for_already_imported_cache({ id: 1 })).to eq(1) }
describe '#each_object_to_import', :clean_gitlab_redis_cache do
let(:merge_request) do
@@ -26,7 +26,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointDiffNotesImporter d
)
end
- let(:note) { double(id: 1) }
+ let(:note) { { id: 1 } }
let(:page) { double(objects: [note], number: 1) }
it 'fetches data' do
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb
index 4ed01fd7e0b..dde730d46d2 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_events_importer_spec.rb
@@ -40,7 +40,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
end
describe '#id_for_already_imported_cache' do
- let(:event) { instance_double('Event', id: 1) }
+ let(:event) { { id: 1 } }
it { expect(subject.id_for_already_imported_cache(event)).to eq(1) }
end
@@ -88,7 +88,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
describe '#each_object_to_import', :clean_gitlab_redis_cache do
let(:issue_event) do
struct = Struct.new(:id, :event, :created_at, :issue, keyword_init: true)
- struct.new(id: rand(10), event: 'closed', created_at: '2022-04-26 18:30:53 UTC')
+ struct.new(id: 1, event: 'closed', created_at: '2022-04-26 18:30:53 UTC')
end
let(:page) do
@@ -115,9 +115,17 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
it 'imports each issue event page by page' do
counter = 0
subject.each_object_to_import do |object|
- expect(object).to eq issue_event
- expect(issue_event.issue['number']).to eq issuable.iid
- expect(issue_event.issue['pull_request']).to eq false
+ expect(object).to eq(
+ {
+ id: 1,
+ event: 'closed',
+ created_at: '2022-04-26 18:30:53 UTC',
+ issue: {
+ number: issuable.iid,
+ pull_request: false
+ }
+ }
+ )
counter += 1
end
expect(counter).to eq 1
@@ -130,9 +138,17 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter
it 'imports each merge request event page by page' do
counter = 0
subject.each_object_to_import do |object|
- expect(object).to eq issue_event
- expect(issue_event.issue['number']).to eq issuable.iid
- expect(issue_event.issue['pull_request']).to eq true
+ expect(object).to eq(
+ {
+ id: 1,
+ event: 'closed',
+ created_at: '2022-04-26 18:30:53 UTC',
+ issue: {
+ number: issuable.iid,
+ pull_request: true
+ }
+ }
+ )
counter += 1
end
expect(counter).to eq 1
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb
index d769f4fdcf5..e1f65546e1d 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_issue_notes_importer_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueNotesImporter
it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::NoteImporter) }
it { expect(subject.collection_method).to eq(:issue_comments) }
it { expect(subject.object_type).to eq(:note) }
- it { expect(subject.id_for_already_imported_cache(double(id: 1))).to eq(1) }
+ it { expect(subject.id_for_already_imported_cache({ id: 1 })).to eq(1) }
describe '#each_object_to_import', :clean_gitlab_redis_cache do
let(:issue) do
@@ -25,7 +25,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueNotesImporter
)
end
- let(:note) { double(id: 1) }
+ let(:note) { { id: 1 } }
let(:page) { double(objects: [note], number: 1) }
it 'fetches data' do
diff --git a/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb
index 1dcc466d34c..5523b97acc3 100644
--- a/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/single_endpoint_merge_request_notes_importer_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointMergeRequestNotesIm
it { expect(subject.importer_class).to eq(Gitlab::GithubImport::Importer::NoteImporter) }
it { expect(subject.collection_method).to eq(:issue_comments) }
it { expect(subject.object_type).to eq(:note) }
- it { expect(subject.id_for_already_imported_cache(double(id: 1))).to eq(1) }
+ it { expect(subject.id_for_already_imported_cache({ id: 1 })).to eq(1) }
describe '#each_object_to_import', :clean_gitlab_redis_cache do
let(:merge_request) do
@@ -26,7 +26,7 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointMergeRequestNotesIm
)
end
- let(:note) { double(id: 1) }
+ let(:note) { { id: 1 } }
let(:page) { double(objects: [note], number: 1) }
it 'fetches data' do