diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-22 15:06:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-22 15:06:25 +0300 |
commit | 4db9eeb44af5644eb1d080b4ccf4aff8b90656b9 (patch) | |
tree | 4ca630fe181e6c66134579694fc97a60430ff7e9 /spec | |
parent | 8a3fdede9607c806d88856d46d4f5394b630a006 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/error_tracking/components/error_details_spec.js | 27 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 175 | ||||
-rw-r--r-- | spec/models/merge_request/pipelines_spec.rb | 154 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 177 |
4 files changed, 178 insertions, 355 deletions
diff --git a/spec/frontend/error_tracking/components/error_details_spec.js b/spec/frontend/error_tracking/components/error_details_spec.js index ddc17dea291..cf91c840cc4 100644 --- a/spec/frontend/error_tracking/components/error_details_spec.js +++ b/spec/frontend/error_tracking/components/error_details_spec.js @@ -83,13 +83,34 @@ describe('ErrorDetails', () => { expect(wrapper.find(Stacktrace).exists()).toBe(false); }); - it('should allow a blank issue to be created', () => { + it('should allow an issue to be created with title and description', () => { store.state.details.loading = false; - store.state.details.error.id = 1; + store.state.details.error = { + id: 1, + title: 'Issue title', + external_url: 'http://sentry.gitlab.net/gitlab', + first_seen: '2017-05-26T13:32:48Z', + last_seen: '2018-05-26T13:32:48Z', + count: 12, + user_count: 2, + }; mountComponent(); const button = wrapper.find(GlButton); + const title = 'Issue title'; + const url = 'Sentry event: http://sentry.gitlab.net/gitlab'; + const firstSeen = 'First seen: 2017-05-26T13:32:48Z'; + const lastSeen = 'Last seen: 2018-05-26T13:32:48Z'; + const count = 'Events: 12'; + const userCount = 'Users: 2'; + + const issueDescription = `${url}${firstSeen}${lastSeen}${count}${userCount}`; + + const issueLink = `/test-project/issues/new?issue[title]=${encodeURIComponent( + title, + )}&issue[description]=${encodeURIComponent(issueDescription)}`; + expect(button.exists()).toBe(true); - expect(button.attributes().href).toBe(wrapper.props().issueProjectPath); + expect(button.attributes().href).toBe(issueLink); }); describe('Stacktrace', () => { diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 800ec3219e5..977f1fdd267 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -75,71 +75,6 @@ describe Ci::Pipeline, :mailer do end end - describe '.sort_by_merge_request_pipelines' do - subject { described_class.sort_by_merge_request_pipelines } - - context 'when branch pipelines exist' do - let!(:branch_pipeline_1) { create(:ci_pipeline, source: :push) } - let!(:branch_pipeline_2) { create(:ci_pipeline, source: :push) } - - it 'returns pipelines order by id' do - expect(subject).to eq([branch_pipeline_2, - branch_pipeline_1]) - end - end - - context 'when merge request pipelines exist' do - let!(:merge_request_pipeline_1) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request) - end - - let!(:merge_request_pipeline_2) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request) - end - - let(:merge_request) do - create(:merge_request, - source_project: project, - source_branch: 'feature', - target_project: project, - target_branch: 'master') - end - - it 'returns pipelines order by id' do - expect(subject).to eq([merge_request_pipeline_2, - merge_request_pipeline_1]) - end - end - - context 'when both branch pipeline and merge request pipeline exist' do - let!(:branch_pipeline_1) { create(:ci_pipeline, source: :push) } - let!(:branch_pipeline_2) { create(:ci_pipeline, source: :push) } - - let!(:merge_request_pipeline_1) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request) - end - - let!(:merge_request_pipeline_2) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request) - end - - let(:merge_request) do - create(:merge_request, - source_project: project, - source_branch: 'feature', - target_project: project, - target_branch: 'master') - end - - it 'returns merge request pipeline first' do - expect(subject).to eq([merge_request_pipeline_2, - merge_request_pipeline_1, - branch_pipeline_2, - branch_pipeline_1]) - end - end - end - describe '.for_sha' do subject { described_class.for_sha(sha) } @@ -226,39 +161,6 @@ describe Ci::Pipeline, :mailer do end end - describe '.detached_merge_request_pipelines' do - subject { described_class.detached_merge_request_pipelines(merge_request, sha) } - - let!(:pipeline) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, sha: merge_request.diff_head_sha) - end - - let(:merge_request) { create(:merge_request) } - let(:sha) { merge_request.diff_head_sha } - - it 'returns detached merge request pipelines' do - is_expected.to eq([pipeline]) - end - - context 'when sha does not exist' do - let(:sha) { 'abc' } - - it 'returns empty array' do - is_expected.to be_empty - end - end - - context 'when pipeline is merge request pipeline' do - let!(:pipeline) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, source_sha: merge_request.diff_head_sha) - end - - it 'returns empty array' do - is_expected.to be_empty - end - end - end - describe '#detached_merge_request_pipeline?' do subject { pipeline.detached_merge_request_pipeline? } @@ -278,39 +180,6 @@ describe Ci::Pipeline, :mailer do end end - describe '.merge_request_pipelines' do - subject { described_class.merge_request_pipelines(merge_request, source_sha) } - - let!(:pipeline) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, source_sha: merge_request.diff_head_sha) - end - - let(:merge_request) { create(:merge_request) } - let(:source_sha) { merge_request.diff_head_sha } - - it 'returns merge pipelines' do - is_expected.to eq([pipeline]) - end - - context 'when source sha is empty' do - let(:source_sha) { nil } - - it 'returns empty array' do - is_expected.to be_empty - end - end - - context 'when pipeline is detached merge request pipeline' do - let!(:pipeline) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, sha: merge_request.diff_head_sha) - end - - it 'returns empty array' do - is_expected.to be_empty - end - end - end - describe '#merge_request_pipeline?' do subject { pipeline.merge_request_pipeline? } @@ -499,50 +368,6 @@ describe Ci::Pipeline, :mailer do end end - describe '.triggered_for_branch' do - subject { described_class.triggered_for_branch(ref) } - - let(:project) { create(:project, :repository) } - let(:ref) { 'feature' } - let!(:pipeline) { create(:ci_pipeline, ref: ref) } - - it 'returns the pipeline' do - is_expected.to eq([pipeline]) - end - - context 'when sha is not specified' do - it 'returns the pipeline' do - expect(described_class.triggered_for_branch(ref)).to eq([pipeline]) - end - end - - context 'when pipeline is triggered for tag' do - let(:ref) { 'v1.1.0' } - let!(:pipeline) { create(:ci_pipeline, ref: ref, tag: true) } - - it 'does not return the pipeline' do - is_expected.to be_empty - end - end - - context 'when pipeline is triggered for merge_request' do - let!(:merge_request) do - create(:merge_request, - :with_merge_request_pipeline, - source_project: project, - source_branch: ref, - target_project: project, - target_branch: 'master') - end - - let(:pipeline) { merge_request.pipelines_for_merge_request.first } - - it 'does not return the pipeline' do - is_expected.to be_empty - end - end - end - describe '.with_reports' do subject { described_class.with_reports(Ci::JobArtifact.test_reports) } diff --git a/spec/models/merge_request/pipelines_spec.rb b/spec/models/merge_request/pipelines_spec.rb new file mode 100644 index 00000000000..96f09eda647 --- /dev/null +++ b/spec/models/merge_request/pipelines_spec.rb @@ -0,0 +1,154 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MergeRequest::Pipelines do + describe '#all' do + let(:merge_request) { create(:merge_request) } + let(:project) { merge_request.source_project } + + subject { described_class.new(merge_request) } + + shared_examples 'returning pipelines with proper ordering' do + let!(:all_pipelines) do + merge_request.all_commit_shas.map do |sha| + create(:ci_empty_pipeline, + project: project, sha: sha, ref: merge_request.source_branch) + end + end + + it 'returns all pipelines' do + expect(subject.all).not_to be_empty + expect(subject.all).to eq(all_pipelines.reverse) + end + end + + context 'with single merge_request_diffs' do + it_behaves_like 'returning pipelines with proper ordering' + end + + context 'with multiple irrelevant merge_request_diffs' do + before do + merge_request.update(target_branch: 'v1.0.0') + end + + it_behaves_like 'returning pipelines with proper ordering' + end + + context 'with unsaved merge request' do + let(:merge_request) { build(:merge_request) } + + let!(:pipeline) do + create(:ci_empty_pipeline, project: project, + sha: merge_request.diff_head_sha, ref: merge_request.source_branch) + end + + it 'returns pipelines from diff_head_sha' do + expect(subject.all).to contain_exactly(pipeline) + end + end + + context 'when pipelines exist for the branch and merge request' do + let(:source_ref) { 'feature' } + let(:target_ref) { 'master' } + + let!(:branch_pipeline) do + create(:ci_pipeline, source: :push, project: project, + ref: source_ref, sha: shas.second) + end + + let!(:tag_pipeline) do + create(:ci_pipeline, project: project, ref: source_ref, tag: true) + end + + let!(:detached_merge_request_pipeline) do + create(:ci_pipeline, source: :merge_request_event, project: project, + ref: source_ref, sha: shas.second, merge_request: merge_request) + end + + let(:merge_request) do + create(:merge_request, source_project: project, source_branch: source_ref, + target_project: project, target_branch: target_ref) + end + + let(:project) { create(:project, :repository) } + let(:shas) { project.repository.commits(source_ref, limit: 2).map(&:id) } + + before do + allow(merge_request).to receive(:all_commit_shas) { shas } + end + + it 'returns merge request pipeline first' do + expect(subject.all).to eq([detached_merge_request_pipeline, branch_pipeline]) + end + + context 'when there are a branch pipeline and a merge request pipeline' do + let!(:branch_pipeline_2) do + create(:ci_pipeline, source: :push, project: project, + ref: source_ref, sha: shas.first) + end + + let!(:detached_merge_request_pipeline_2) do + create(:ci_pipeline, source: :merge_request_event, project: project, + ref: source_ref, sha: shas.first, merge_request: merge_request) + end + + it 'returns merge request pipelines first' do + expect(subject.all) + .to eq([detached_merge_request_pipeline_2, + detached_merge_request_pipeline, + branch_pipeline_2, + branch_pipeline]) + end + end + + context 'when there are multiple merge request pipelines from the same branch' do + let!(:branch_pipeline_2) do + create(:ci_pipeline, source: :push, project: project, + ref: source_ref, sha: shas.first) + end + + let!(:detached_merge_request_pipeline_2) do + create(:ci_pipeline, source: :merge_request_event, project: project, + ref: source_ref, sha: shas.first, merge_request: merge_request_2) + end + + let(:merge_request_2) do + create(:merge_request, source_project: project, source_branch: source_ref, + target_project: project, target_branch: 'stable') + end + + before do + allow(merge_request_2).to receive(:all_commit_shas) { shas } + end + + it 'returns only related merge request pipelines' do + expect(subject.all) + .to eq([detached_merge_request_pipeline, + branch_pipeline_2, + branch_pipeline]) + + expect(described_class.new(merge_request_2).all) + .to eq([detached_merge_request_pipeline_2, + branch_pipeline_2, + branch_pipeline]) + end + end + + context 'when detached merge request pipeline is run on head ref of the merge request' do + let!(:detached_merge_request_pipeline) do + create(:ci_pipeline, source: :merge_request_event, project: project, + ref: merge_request.ref_path, sha: shas.second, merge_request: merge_request) + end + + it 'sets the head ref of the merge request to the pipeline ref' do + expect(detached_merge_request_pipeline.ref).to match(%r{refs/merge-requests/\d+/head}) + end + + it 'includes the detached merge request pipeline even though the ref is custom path' do + expect(merge_request.all_pipelines).to include(detached_merge_request_pipeline) + end + end + end + end +end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 656753da5f1..53d67113f9e 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1441,183 +1441,6 @@ describe MergeRequest do end end - describe '#all_pipelines' do - shared_examples 'returning pipelines with proper ordering' do - let!(:all_pipelines) do - subject.all_commit_shas.map do |sha| - create(:ci_empty_pipeline, - project: subject.source_project, - sha: sha, - ref: subject.source_branch) - end - end - - it 'returns all pipelines' do - expect(subject.all_pipelines).not_to be_empty - expect(subject.all_pipelines).to eq(all_pipelines.reverse) - end - end - - context 'with single merge_request_diffs' do - it_behaves_like 'returning pipelines with proper ordering' - end - - context 'with multiple irrelevant merge_request_diffs' do - before do - subject.update(target_branch: 'v1.0.0') - end - - it_behaves_like 'returning pipelines with proper ordering' - end - - context 'with unsaved merge request' do - subject { build(:merge_request) } - - let!(:pipeline) do - create(:ci_empty_pipeline, - project: subject.project, - sha: subject.diff_head_sha, - ref: subject.source_branch) - end - - it 'returns pipelines from diff_head_sha' do - expect(subject.all_pipelines).to contain_exactly(pipeline) - end - end - - context 'when pipelines exist for the branch and merge request' do - let(:source_ref) { 'feature' } - let(:target_ref) { 'master' } - - let!(:branch_pipeline) do - create(:ci_pipeline, - source: :push, - project: project, - ref: source_ref, - sha: shas.second) - end - - let!(:detached_merge_request_pipeline) do - create(:ci_pipeline, - source: :merge_request_event, - project: project, - ref: source_ref, - sha: shas.second, - merge_request: merge_request) - end - - let(:merge_request) do - create(:merge_request, - source_project: project, - source_branch: source_ref, - target_project: project, - target_branch: target_ref) - end - - let(:project) { create(:project, :repository) } - let(:shas) { project.repository.commits(source_ref, limit: 2).map(&:id) } - - before do - allow(merge_request).to receive(:all_commit_shas) { shas } - end - - it 'returns merge request pipeline first' do - expect(merge_request.all_pipelines) - .to eq([detached_merge_request_pipeline, - branch_pipeline]) - end - - context 'when there are a branch pipeline and a merge request pipeline' do - let!(:branch_pipeline_2) do - create(:ci_pipeline, - source: :push, - project: project, - ref: source_ref, - sha: shas.first) - end - - let!(:detached_merge_request_pipeline_2) do - create(:ci_pipeline, - source: :merge_request_event, - project: project, - ref: source_ref, - sha: shas.first, - merge_request: merge_request) - end - - it 'returns merge request pipelines first' do - expect(merge_request.all_pipelines) - .to eq([detached_merge_request_pipeline_2, - detached_merge_request_pipeline, - branch_pipeline_2, - branch_pipeline]) - end - end - - context 'when there are multiple merge request pipelines from the same branch' do - let!(:branch_pipeline_2) do - create(:ci_pipeline, - source: :push, - project: project, - ref: source_ref, - sha: shas.first) - end - - let!(:detached_merge_request_pipeline_2) do - create(:ci_pipeline, - source: :merge_request_event, - project: project, - ref: source_ref, - sha: shas.first, - merge_request: merge_request_2) - end - - let(:merge_request_2) do - create(:merge_request, - source_project: project, - source_branch: source_ref, - target_project: project, - target_branch: 'stable') - end - - before do - allow(merge_request_2).to receive(:all_commit_shas) { shas } - end - - it 'returns only related merge request pipelines' do - expect(merge_request.all_pipelines) - .to eq([detached_merge_request_pipeline, - branch_pipeline_2, - branch_pipeline]) - - expect(merge_request_2.all_pipelines) - .to eq([detached_merge_request_pipeline_2, - branch_pipeline_2, - branch_pipeline]) - end - end - - context 'when detached merge request pipeline is run on head ref of the merge request' do - let!(:detached_merge_request_pipeline) do - create(:ci_pipeline, - source: :merge_request_event, - project: project, - ref: merge_request.ref_path, - sha: shas.second, - merge_request: merge_request) - end - - it 'sets the head ref of the merge request to the pipeline ref' do - expect(detached_merge_request_pipeline.ref).to match(%r{refs/merge-requests/\d+/head}) - end - - it 'includes the detached merge request pipeline even though the ref is custom path' do - expect(merge_request.all_pipelines).to include(detached_merge_request_pipeline) - end - end - end - end - describe '#update_head_pipeline' do subject { merge_request.update_head_pipeline } |