diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb')
-rw-r--r-- | spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb b/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb index 7d8875e36c3..90469693820 100644 --- a/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb +++ b/spec/lib/gitlab/legacy_github_import/pull_request_formatter_spec.rb @@ -3,22 +3,22 @@ require 'spec_helper' RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do + let_it_be(:project) { create(:project, :repository) } let(:client) { double } - let(:project) { create(:project, :repository) } let(:source_sha) { create(:commit, project: project).id } let(:target_commit) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit) } let(:target_sha) { target_commit.id } let(:target_short_sha) { target_commit.id.to_s[0..7] } - let(:repository) { double(id: 1, fork: false) } + let(:repository) { { id: 1, fork: false } } let(:source_repo) { repository } - let(:source_branch) { double(ref: 'branch-merged', repo: source_repo, sha: source_sha) } - let(:forked_source_repo) { double(id: 2, fork: true, name: 'otherproject', full_name: 'company/otherproject') } + let(:source_branch) { { ref: 'branch-merged', repo: source_repo, sha: source_sha } } + let(:forked_source_repo) { { id: 2, fork: true, name: 'otherproject', full_name: 'company/otherproject' } } let(:target_repo) { repository } - let(:target_branch) { double(ref: 'master', repo: target_repo, sha: target_sha, user: octocat) } - let(:removed_branch) { double(ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat) } - let(:forked_branch) { double(ref: 'master', repo: forked_source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat) } - let(:branch_deleted_repo) { double(ref: 'master', repo: nil, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat) } - let(:octocat) { double(id: 123456, login: 'octocat', email: 'octocat@example.com') } + let(:target_branch) { { ref: 'master', repo: target_repo, sha: target_sha, user: octocat } } + let(:removed_branch) { { ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat } } + let(:forked_branch) { { ref: 'master', repo: forked_source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat } } + let(:branch_deleted_repo) { { ref: 'master', repo: nil, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat } } + let(:octocat) { { id: 123456, login: 'octocat', email: 'octocat@example.com' } } let(:created_at) { DateTime.strptime('2011-01-26T19:01:12Z') } let(:updated_at) { DateTime.strptime('2011-01-27T19:01:12Z') } let(:base_data) do @@ -48,7 +48,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do shared_examples 'Gitlab::LegacyGithubImport::PullRequestFormatter#attributes' do context 'when pull request is open' do - let(:raw_data) { double(base_data.merge(state: 'open')) } + let(:raw_data) { base_data.merge(state: 'open') } it 'returns formatted attributes' do expected = { @@ -75,7 +75,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when pull request is closed' do - let(:raw_data) { double(base_data.merge(state: 'closed')) } + let(:raw_data) { base_data.merge(state: 'closed') } it 'returns formatted attributes' do expected = { @@ -103,7 +103,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do context 'when pull request is merged' do let(:merged_at) { DateTime.strptime('2011-01-28T13:01:12Z') } - let(:raw_data) { double(base_data.merge(state: 'closed', merged_at: merged_at)) } + let(:raw_data) { base_data.merge(state: 'closed', merged_at: merged_at) } it 'returns formatted attributes' do expected = { @@ -130,54 +130,54 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when it is assigned to someone' do - let(:raw_data) { double(base_data.merge(assignee: octocat)) } + let(:raw_data) { base_data.merge(assignee: octocat) } it 'returns nil as assignee_id when is not a GitLab user' do expect(pull_request.attributes.fetch(:assignee_id)).to be_nil end it 'returns GitLab user id associated with GitHub id as assignee_id' do - gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github') + gl_user = create(:omniauth_user, extern_uid: octocat[:id], provider: 'github') expect(pull_request.attributes.fetch(:assignee_id)).to eq gl_user.id end it 'returns GitLab user id associated with GitHub email as assignee_id' do - gl_user = create(:user, email: octocat.email) + gl_user = create(:user, email: octocat[:email]) expect(pull_request.attributes.fetch(:assignee_id)).to eq gl_user.id end end context 'when author is a GitLab user' do - let(:raw_data) { double(base_data.merge(user: octocat)) } + let(:raw_data) { base_data.merge(user: octocat) } it 'returns project creator_id as author_id when is not a GitLab user' do expect(pull_request.attributes.fetch(:author_id)).to eq project.creator_id end it 'returns GitLab user id associated with GitHub id as author_id' do - gl_user = create(:omniauth_user, extern_uid: octocat.id, provider: 'github') + gl_user = create(:omniauth_user, extern_uid: octocat[:id], provider: 'github') expect(pull_request.attributes.fetch(:author_id)).to eq gl_user.id end it 'returns GitLab user id associated with GitHub email as author_id' do - gl_user = create(:user, email: octocat.email) + gl_user = create(:user, email: octocat[:email]) expect(pull_request.attributes.fetch(:author_id)).to eq gl_user.id end it 'returns description without created at tag line' do - create(:omniauth_user, extern_uid: octocat.id, provider: 'github') + create(:omniauth_user, extern_uid: octocat[:id], provider: 'github') expect(pull_request.attributes.fetch(:description)).to eq('Please pull these awesome changes') end end context 'when it has a milestone' do - let(:milestone) { double(id: 42, number: 42) } - let(:raw_data) { double(base_data.merge(milestone: milestone)) } + let(:milestone) { { id: 42, number: 42 } } + let(:raw_data) { base_data.merge(milestone: milestone) } it 'returns nil when milestone does not exist' do expect(pull_request.attributes.fetch(:milestone)).to be_nil @@ -192,7 +192,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end shared_examples 'Gitlab::LegacyGithubImport::PullRequestFormatter#number' do - let(:raw_data) { double(base_data) } + let(:raw_data) { base_data } it 'returns pull request number' do expect(pull_request.number).to eq 1347 @@ -201,7 +201,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do shared_examples 'Gitlab::LegacyGithubImport::PullRequestFormatter#source_branch_name' do context 'when source branch exists' do - let(:raw_data) { double(base_data) } + let(:raw_data) { base_data } it 'returns branch ref' do expect(pull_request.source_branch_name).to eq 'branch-merged' @@ -209,7 +209,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when source branch does not exist' do - let(:raw_data) { double(base_data.merge(head: removed_branch)) } + let(:raw_data) { base_data.merge(head: removed_branch) } it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do expect(pull_request.source_branch_name).to eq "gh-#{target_short_sha}/1347/octocat/removed-branch" @@ -217,7 +217,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when source branch is from a fork' do - let(:raw_data) { double(base_data.merge(head: forked_branch)) } + let(:raw_data) { base_data.merge(head: forked_branch) } it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do expect(pull_request.source_branch_name).to eq "gh-#{target_short_sha}/1347/octocat/master" @@ -225,7 +225,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when source branch is from a deleted fork' do - let(:raw_data) { double(base_data.merge(head: branch_deleted_repo)) } + let(:raw_data) { base_data.merge(head: branch_deleted_repo) } it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do expect(pull_request.source_branch_name).to eq "gh-#{target_short_sha}/1347/octocat/master" @@ -235,7 +235,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do shared_examples 'Gitlab::LegacyGithubImport::PullRequestFormatter#target_branch_name' do context 'when target branch exists' do - let(:raw_data) { double(base_data) } + let(:raw_data) { base_data } it 'returns branch ref' do expect(pull_request.target_branch_name).to eq 'master' @@ -243,7 +243,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when target branch does not exist' do - let(:raw_data) { double(base_data.merge(base: removed_branch)) } + let(:raw_data) { base_data.merge(base: removed_branch) } it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do expect(pull_request.target_branch_name).to eq 'gl-2e5d3239/1347/octocat/removed-branch' @@ -271,7 +271,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do describe '#valid?' do context 'when source, and target repos are not a fork' do - let(:raw_data) { double(base_data) } + let(:raw_data) { base_data } it 'returns true' do expect(pull_request.valid?).to eq true @@ -279,8 +279,8 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when source repo is a fork' do - let(:source_repo) { double(id: 2) } - let(:raw_data) { double(base_data) } + let(:source_repo) { { id: 2 } } + let(:raw_data) { base_data } it 'returns true' do expect(pull_request.valid?).to eq true @@ -288,8 +288,8 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when target repo is a fork' do - let(:target_repo) { double(id: 2) } - let(:raw_data) { double(base_data) } + let(:target_repo) { { id: 2 } } + let(:raw_data) { base_data } it 'returns true' do expect(pull_request.valid?).to eq true @@ -299,7 +299,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do describe '#cross_project?' do context 'when source and target repositories are different' do - let(:raw_data) { double(base_data.merge(head: forked_branch)) } + let(:raw_data) { base_data.merge(head: forked_branch) } it 'returns true' do expect(pull_request.cross_project?).to eq true @@ -307,7 +307,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when source repository does not exist anymore' do - let(:raw_data) { double(base_data.merge(head: branch_deleted_repo)) } + let(:raw_data) { base_data.merge(head: branch_deleted_repo) } it 'returns true' do expect(pull_request.cross_project?).to eq true @@ -315,7 +315,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end context 'when source and target repositories are the same' do - let(:raw_data) { double(base_data.merge(head: source_branch)) } + let(:raw_data) { base_data.merge(head: source_branch) } it 'returns false' do expect(pull_request.cross_project?).to eq false @@ -324,7 +324,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end describe '#source_branch_exists?' do - let(:raw_data) { double(base_data.merge(head: forked_branch)) } + let(:raw_data) { base_data.merge(head: forked_branch) } it 'returns false when is a cross_project' do expect(pull_request.source_branch_exists?).to eq false @@ -332,7 +332,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end describe '#url' do - let(:raw_data) { double(base_data) } + let(:raw_data) { base_data } it 'return raw url' do expect(pull_request.url).to eq 'https://api.github.com/repos/octocat/Hello-World/pulls/1347' @@ -340,7 +340,7 @@ RSpec.describe Gitlab::LegacyGithubImport::PullRequestFormatter do end describe '#opened?' do - let(:raw_data) { double(base_data.merge(state: 'open')) } + let(:raw_data) { base_data.merge(state: 'open') } it 'returns true when state is "open"' do expect(pull_request.opened?).to be_truthy |