diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-24 00:13:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-24 00:13:22 +0300 |
commit | 0978fc4c40151a0dccbcb3d348969a6920a58e09 (patch) | |
tree | fab4373e4cf815163c98f1dee35c095f35f839b8 /spec/lib/gitlab | |
parent | 3acaaf7231d0779a6ceb37fca693cd81e698ef90 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
22 files changed, 133 insertions, 157 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb index 8c4f7af0ef4..323bab89e6a 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb @@ -68,8 +68,10 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Seed do end context 'when refs policy is specified' do + let(:tag_name) { project.repository.tags.first.name } + let(:pipeline) do - build(:ci_pipeline, project: project, ref: 'feature', tag: true) + build(:ci_pipeline, project: project, ref: tag_name, tag: true) end let(:config) do 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..85d39df7c89 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 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..e08659f5bac 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 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/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/notes_importer_spec.rb b/spec/lib/gitlab/github_import/importer/notes_importer_spec.rb index 3b4fe652da8..2fcc4f623a2 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 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/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..15a0e15ae4d 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 @@ -116,8 +116,8 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter 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(issue_event[:issue]['number']).to eq issuable.iid + expect(issue_event[:issue]['pull_request']).to eq false counter += 1 end expect(counter).to eq 1 @@ -131,8 +131,8 @@ RSpec.describe Gitlab::GithubImport::Importer::SingleEndpointIssueEventsImporter 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(issue_event[:issue]['number']).to eq issuable.iid + expect(issue_event[:issue]['pull_request']).to eq 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 diff --git a/spec/lib/gitlab/github_import/representation/diff_note_spec.rb b/spec/lib/gitlab/github_import/representation/diff_note_spec.rb index fe3040c102b..a656cd0d056 100644 --- a/spec/lib/gitlab/github_import/representation/diff_note_spec.rb +++ b/spec/lib/gitlab/github_import/representation/diff_note_spec.rb @@ -28,7 +28,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote, :clean_gitlab_red let(:start_line) { nil } let(:end_line) { 23 } let(:note_body) { 'Hello world' } - let(:user_data) { { 'id' => 4, 'login' => 'alice' } } + let(:user_data) { { id: 4, login: 'alice' } } let(:side) { 'RIGHT' } let(:created_at) { Time.new(2017, 1, 1, 12, 00) } let(:updated_at) { Time.new(2017, 1, 1, 12, 15) } @@ -275,15 +275,14 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote, :clean_gitlab_red describe '.from_api_response' do it_behaves_like 'a DiffNote representation' do let(:response) do - double( - :response, + { id: note_id, html_url: 'https://github.com/foo/bar/pull/42', path: 'README.md', commit_id: '123abc', original_commit_id: 'original123abc', side: side, - user: user_data && double(:user, user_data), + user: user_data, diff_hunk: hunk, body: note_body, created_at: created_at, @@ -291,7 +290,7 @@ RSpec.describe Gitlab::GithubImport::Representation::DiffNote, :clean_gitlab_red line: end_line, start_line: start_line, in_reply_to_id: in_reply_to_id - ) + } end subject(:note) { described_class.from_api_response(response) } diff --git a/spec/lib/gitlab/github_import/representation/issue_spec.rb b/spec/lib/gitlab/github_import/representation/issue_spec.rb index 5898518343a..263ef8b1708 100644 --- a/spec/lib/gitlab/github_import/representation/issue_spec.rb +++ b/spec/lib/gitlab/github_import/representation/issue_spec.rb @@ -74,20 +74,19 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do describe '.from_api_response' do let(:response) 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 let(:additional_data) { { work_item_type_id: work_item_type_id } } @@ -97,9 +96,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Issue do end it 'does not set the user if the response did not include a user' do - allow(response) - .to receive(:user) - .and_return(nil) + response[:user] = nil issue = described_class.from_api_response(response, additional_data) diff --git a/spec/lib/gitlab/github_import/representation/note_spec.rb b/spec/lib/gitlab/github_import/representation/note_spec.rb index 9f416eb3c02..49126dbe9c5 100644 --- a/spec/lib/gitlab/github_import/representation/note_spec.rb +++ b/spec/lib/gitlab/github_import/representation/note_spec.rb @@ -48,15 +48,14 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do describe '.from_api_response' do let(:response) 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: created_at, updated_at: updated_at, id: 1 - ) + } end it_behaves_like 'a Note' do @@ -64,9 +63,7 @@ RSpec.describe Gitlab::GithubImport::Representation::Note do end it 'does not set the user if the response did not include a user' do - allow(response) - .to receive(:user) - .and_return(nil) + response[:user] = nil note = described_class.from_api_response(response) diff --git a/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb b/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb index d6e7a8172f7..0203da9f4fb 100644 --- a/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb +++ b/spec/lib/gitlab/github_import/representation/pull_request_review_spec.rb @@ -21,15 +21,14 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do describe '.from_api_response' do let(:response) do - double( - :response, + { id: 999, merge_request_id: 42, body: 'note', state: 'APPROVED', - user: double(:user, id: 4, login: 'alice'), + user: { id: 4, login: 'alice' }, submitted_at: submitted_at - ) + } end it_behaves_like 'a PullRequest review' do @@ -37,9 +36,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequestReview do end it 'does not set the user if the response did not include a user' do - allow(response) - .to receive(:user) - .and_return(nil) + response[:user] = nil review = described_class.from_api_response(response) diff --git a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb index deb9535a845..b8c1c67e07c 100644 --- a/spec/lib/gitlab/github_import/representation/pull_request_spec.rb +++ b/spec/lib/gitlab/github_import/representation/pull_request_spec.rb @@ -93,33 +93,30 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequest do describe '.from_api_response' do let(:response) 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: created_at, updated_at: updated_at, merged_at: merged_at - ) + } end it_behaves_like 'a PullRequest' do @@ -127,9 +124,7 @@ RSpec.describe Gitlab::GithubImport::Representation::PullRequest do end it 'does not set the user if the response did not include a user' do - allow(response) - .to receive(:user) - .and_return(nil) + response[:user] = nil pr = described_class.from_api_response(response) diff --git a/spec/lib/gitlab/github_import/representation/user_spec.rb b/spec/lib/gitlab/github_import/representation/user_spec.rb index d7219556ada..ccada558f8b 100644 --- a/spec/lib/gitlab/github_import/representation/user_spec.rb +++ b/spec/lib/gitlab/github_import/representation/user_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Gitlab::GithubImport::Representation::User do describe '.from_api_response' do it_behaves_like 'a User' do - let(:response) { double(:response, id: 42, login: 'alice') } + let(:response) { { id: 42, login: 'alice' } } let(:user) { described_class.from_api_response(response) } end end diff --git a/spec/lib/gitlab/github_import/user_finder_spec.rb b/spec/lib/gitlab/github_import/user_finder_spec.rb index 8ebbff31f64..d77aaa0e846 100644 --- a/spec/lib/gitlab/github_import/user_finder_spec.rb +++ b/spec/lib/gitlab/github_import/user_finder_spec.rb @@ -17,8 +17,8 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do describe '#author_id_for' do context 'with default author_key' do it 'returns the user ID for the author of an object' do - user = double(:user, id: 4, login: 'kittens') - note = double(:note, author: user) + user = { id: 4, login: 'kittens' } + note = { author: user } expect(finder).to receive(:user_id_for).with(user).and_return(42) @@ -26,8 +26,8 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do end it 'returns the ID of the project creator if no user ID could be found' do - user = double(:user, id: 4, login: 'kittens') - note = double(:note, author: user) + user = { id: 4, login: 'kittens' } + note = { author: user } expect(finder).to receive(:user_id_for).with(user).and_return(nil) @@ -35,7 +35,7 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do end it 'returns the ID of the ghost user when the object has no user' do - note = double(:note, author: nil) + note = { author: nil } expect(finder.author_id_for(note)).to eq([User.ghost.id, true]) end @@ -46,7 +46,7 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do end context 'with a non-default author_key' do - let(:user) { double(:user, id: 4, login: 'kittens') } + let(:user) { { id: 4, login: 'kittens' } } shared_examples 'user ID finder' do |author_key| it 'returns the user ID for an object' do @@ -57,25 +57,25 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do end context 'when the author_key parameter is :actor' do - let(:issue_event) { double('Gitlab::GithubImport::Representation::IssueEvent', actor: user) } + let(:issue_event) { { actor: user } } it_behaves_like 'user ID finder', :actor end context 'when the author_key parameter is :assignee' do - let(:issue_event) { double('Gitlab::GithubImport::Representation::IssueEvent', assignee: user) } + let(:issue_event) { { assignee: user } } it_behaves_like 'user ID finder', :assignee end context 'when the author_key parameter is :requested_reviewer' do - let(:issue_event) { double('Gitlab::GithubImport::Representation::IssueEvent', requested_reviewer: user) } + let(:issue_event) { { requested_reviewer: user } } it_behaves_like 'user ID finder', :requested_reviewer end context 'when the author_key parameter is :review_requester' do - let(:issue_event) { double('Gitlab::GithubImport::Representation::IssueEvent', review_requester: user) } + let(:issue_event) { { review_requester: user } } it_behaves_like 'user ID finder', :review_requester end @@ -84,15 +84,15 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do describe '#assignee_id_for' do it 'returns the user ID for the assignee of an issuable' do - user = double(:user, id: 4, login: 'kittens') - issue = double(:issue, assignee: user) + user = { id: 4, login: 'kittens' } + issue = { assignee: user } expect(finder).to receive(:user_id_for).with(user).and_return(42) expect(finder.assignee_id_for(issue)).to eq(42) end it 'returns nil if the issuable does not have an assignee' do - issue = double(:issue, assignee: nil) + issue = { assignee: nil } expect(finder).not_to receive(:user_id_for) expect(finder.assignee_id_for(issue)).to be_nil @@ -101,9 +101,9 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do describe '#user_id_for' do it 'returns the user ID for the given user' do - user = double(:user, id: 4, login: 'kittens') + user = { id: 4, login: 'kittens' } - expect(finder).to receive(:find).with(user.id, user.login).and_return(42) + expect(finder).to receive(:find).with(user[:id], user[:login]).and_return(42) expect(finder.user_id_for(user)).to eq(42) end @@ -221,7 +221,7 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do end context 'when an Email address is not cached' do - let(:user) { double(:user, email: email) } + let(:user) { { email: email } } it 'retrieves the Email address from the GitHub API' do expect(client).to receive(:user).with('kittens').and_return(user) @@ -251,7 +251,7 @@ RSpec.describe Gitlab::GithubImport::UserFinder, :clean_gitlab_redis_cache do end it 'shortens the timeout for Email address in cache when an Email address is private/nil from GitHub' do - user = double(:user, email: nil) + user = { email: nil } expect(client).to receive(:user).with('kittens').and_return(user) expect(Gitlab::Cache::Import::Caching) |