diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-19 12:06:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-19 12:06:16 +0300 |
commit | 34b3567c97ecc0f317adae04e10e4d7d8c8830db (patch) | |
tree | 2612572041a8a6121ce9098cabf8724e67a96ea2 /spec | |
parent | 3209c1a49c14cab93eb347bfca59bace30879440 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/releases_controller_spec.rb | 35 | ||||
-rw-r--r-- | spec/factories/releases.rb | 6 | ||||
-rw-r--r-- | spec/frontend/monitoring/charts/time_series_spec.js | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/middleware/go_spec.rb | 49 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/release_spec.rb | 48 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 12 | ||||
-rw-r--r-- | spec/support/matchers/navigation_matcher.rb | 2 |
8 files changed, 171 insertions, 14 deletions
diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index 562119d967f..5b528c3be52 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -166,6 +166,41 @@ describe Projects::ReleasesController do end end + describe 'GET #evidence' do + let!(:release) { create(:release, :with_evidence, project: project) } + let(:tag) { CGI.escape(release.tag) } + let(:format) { :json } + + subject do + get :evidence, params: { + namespace_id: project.namespace, + project_id: project, + tag: tag, + format: format + } + end + + before do + sign_in(user) + end + + it 'returns the correct evidence summary as a json' do + subject + + expect(json_response).to eq(release.evidence.summary) + end + + context 'when the release was created before evidence existed' do + it 'returns an empty json' do + release.evidence.destroy + + subject + + expect(json_response).to eq({}) + end + end + end + private def get_index diff --git a/spec/factories/releases.rb b/spec/factories/releases.rb index 2f77bb95ea3..182ee2378d4 100644 --- a/spec/factories/releases.rb +++ b/spec/factories/releases.rb @@ -14,5 +14,11 @@ FactoryBot.define do sha { nil } author { nil } end + + trait :with_evidence do + after(:create) do |release, _| + create(:evidence, release: release) + end + end end end diff --git a/spec/frontend/monitoring/charts/time_series_spec.js b/spec/frontend/monitoring/charts/time_series_spec.js index 554535418fe..c561c5edf3c 100644 --- a/spec/frontend/monitoring/charts/time_series_spec.js +++ b/spec/frontend/monitoring/charts/time_series_spec.js @@ -116,6 +116,19 @@ describe('Time series component', () => { }); }); + it('does not throw error if data point is outside the zoom range', () => { + const seriesDataWithoutValue = generateSeriesData('line'); + expect( + timeSeriesChart.vm.formatTooltipText({ + ...seriesDataWithoutValue, + seriesData: seriesDataWithoutValue.seriesData.map(data => ({ + ...data, + value: undefined, + })), + }), + ).toBeUndefined(); + }); + describe('when series is of line type', () => { beforeEach(done => { timeSeriesChart.vm.formatTooltipText(generateSeriesData('line')); diff --git a/spec/lib/gitlab/middleware/go_spec.rb b/spec/lib/gitlab/middleware/go_spec.rb index 16595102375..c81c69e95c7 100644 --- a/spec/lib/gitlab/middleware/go_spec.rb +++ b/spec/lib/gitlab/middleware/go_spec.rb @@ -30,13 +30,13 @@ describe Gitlab::Middleware::Go do shared_examples 'go-get=1' do |enabled_protocol:| context 'with simple 2-segment project path' do - let!(:project) { create(:project, :private) } + let!(:project) { create(:project, :private, :repository) } context 'with subpackages' do let(:path) { "#{project.full_path}/subpackage" } it 'returns the full project path' do - expect_response_with_path(go, enabled_protocol, project.full_path) + expect_response_with_path(go, enabled_protocol, project.full_path, project.default_branch) end end @@ -44,19 +44,19 @@ describe Gitlab::Middleware::Go do let(:path) { project.full_path } it 'returns the full project path' do - expect_response_with_path(go, enabled_protocol, project.full_path) + expect_response_with_path(go, enabled_protocol, project.full_path, project.default_branch) end end end context 'with a nested project path' do let(:group) { create(:group, :nested) } - let!(:project) { create(:project, :public, namespace: group) } + let!(:project) { create(:project, :public, :repository, namespace: group) } shared_examples 'a nested project' do context 'when the project is public' do it 'returns the full project path' do - expect_response_with_path(go, enabled_protocol, project.full_path) + expect_response_with_path(go, enabled_protocol, project.full_path, project.default_branch) end end @@ -67,7 +67,7 @@ describe Gitlab::Middleware::Go do shared_examples 'unauthorized' do it 'returns the 2-segment group path' do - expect_response_with_path(go, enabled_protocol, group.full_path) + expect_response_with_path(go, enabled_protocol, group.full_path, project.default_branch) end end @@ -85,7 +85,7 @@ describe Gitlab::Middleware::Go do shared_examples 'authenticated' do context 'with access to the project' do it 'returns the full project path' do - expect_response_with_path(go, enabled_protocol, project.full_path) + expect_response_with_path(go, enabled_protocol, project.full_path, project.default_branch) end end @@ -160,6 +160,36 @@ describe Gitlab::Middleware::Go do go end end + + context 'with a public project without a repository' do + let!(:project) { create(:project, :public) } + let(:path) { project.full_path } + + it 'returns 404' do + response = go + expect(response[0]).to eq(404) + expect(response[1]['Content-Type']).to eq('text/html') + expected_body = %{<html><body>go get #{Gitlab.config.gitlab.url}/#{project.full_path}</body></html>} + expect(response[2].body).to eq([expected_body]) + end + end + + context 'with a non-standard head' do + let(:user) { create(:user) } + let!(:project) { create(:project, :public, :repository) } + let(:path) { project.full_path } + let(:default_branch) { 'default_branch' } + + before do + project.add_maintainer(user) + project.repository.add_branch(user, default_branch, 'master') + project.change_head(default_branch) + end + + it 'returns the full project path' do + expect_response_with_path(go, enabled_protocol, project.full_path, default_branch) + end + end end context 'with SSH disabled' do @@ -199,16 +229,17 @@ describe Gitlab::Middleware::Go do middleware.call(env) end - def expect_response_with_path(response, protocol, path) + def expect_response_with_path(response, protocol, path, branch) repository_url = case protocol when :ssh "ssh://#{Gitlab.config.gitlab.user}@#{Gitlab.config.gitlab.host}/#{path}.git" when :http, nil "http://#{Gitlab.config.gitlab.host}/#{path}.git" end + project_url = "http://#{Gitlab.config.gitlab.host}/#{path}" expect(response[0]).to eq(200) expect(response[1]['Content-Type']).to eq('text/html') - expected_body = %{<html><head><meta name="go-import" content="#{Gitlab.config.gitlab.host}/#{path} git #{repository_url}" /></head></html>} + expected_body = %{<html><head><meta name="go-import" content="#{Gitlab.config.gitlab.host}/#{path} git #{repository_url}" /><meta name="go-source" content="#{Gitlab.config.gitlab.host}/#{path} #{project_url} #{project_url}/tree/#{branch}{/dir} #{project_url}/blob/#{branch}{/dir}/{file}#L{line}" /></head><body>go get #{Gitlab.config.gitlab.url}/#{path}</body></html>} expect(response[2].body).to eq([expected_body]) end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index b5aa05fd8b4..310f806e3d3 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -2326,6 +2326,26 @@ describe MergeRequest do end end + describe "#head_pipeline_active? " do + it do + is_expected + .to delegate_method(:active?) + .to(:head_pipeline) + .with_prefix + .with_arguments(allow_nil: true) + end + end + + describe "#actual_head_pipeline_success? " do + it do + is_expected + .to delegate_method(:success?) + .to(:actual_head_pipeline) + .with_prefix + .with_arguments(allow_nil: true) + end + end + describe '#mergeable_ci_state?' do let(:project) { create(:project, only_allow_merge_if_pipeline_succeeds: true) } let(:pipeline) { create(:ci_empty_pipeline) } diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index f9c7a14f1f3..cadb8793e15 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -53,6 +53,12 @@ RSpec.describe Release do end end + describe 'callbacks' do + it 'creates a new Evidence object on after_commit', :sidekiq_inline do + expect { release }.to change(Evidence, :count).by(1) + end + end + describe '#assets_count' do subject { release.assets_count } @@ -92,20 +98,22 @@ RSpec.describe Release do end end - describe 'evidence', :sidekiq_might_not_need_inline do + describe 'evidence' do + let(:release_with_evidence) { create(:release, :with_evidence, project: project) } + describe '#create_evidence!' do context 'when a release is created' do it 'creates one Evidence object too' do - expect { release }.to change(Evidence, :count).by(1) + expect { release_with_evidence }.to change(Evidence, :count).by(1) end end end context 'when a release is deleted' do it 'also deletes the associated evidence' do - release = create(:release) + release_with_evidence - expect { release.destroy }.to change(Evidence, :count).by(-1) + expect { release_with_evidence.destroy }.to change(Evidence, :count).by(-1) end end end @@ -141,4 +149,36 @@ RSpec.describe Release do end end end + + describe '#evidence_sha' do + subject { release.evidence_sha } + + context 'when a release was created before evidence collection existed' do + let!(:release) { create(:release) } + + it { is_expected.to be_nil } + end + + context 'when a release was created with evidence collection' do + let!(:release) { create(:release, :with_evidence) } + + it { is_expected.to eq(release.evidence.summary_sha) } + end + end + + describe '#evidence_summary' do + subject { release.evidence_summary } + + context 'when a release was created before evidence collection existed' do + let!(:release) { create(:release) } + + it { is_expected.to eq({}) } + end + + context 'when a release was created with evidence collection' do + let!(:release) { create(:release, :with_evidence) } + + it { is_expected.to eq(release.evidence.summary) } + end + end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index c96c80b6998..e5ad1a6378e 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -1567,6 +1567,18 @@ describe API::MergeRequests do expect(response).to have_gitlab_http_status(200) end + it 'does not merge if merge_when_pipeline_succeeds is passed and the pipeline has failed' do + create(:ci_pipeline, + :failed, + sha: merge_request.diff_head_sha, + merge_requests_as_head_pipeline: [merge_request]) + + put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/merge", user), params: { merge_when_pipeline_succeeds: true } + + expect(response).to have_gitlab_http_status(405) + expect(merge_request.reload.state).to eq('opened') + end + it "enables merge when pipeline succeeds if the pipeline is active" do allow_any_instance_of(MergeRequest).to receive_messages(head_pipeline: pipeline, actual_head_pipeline: pipeline) allow(pipeline).to receive(:active?).and_return(true) diff --git a/spec/support/matchers/navigation_matcher.rb b/spec/support/matchers/navigation_matcher.rb index ad73c96031e..a0beecbfb2c 100644 --- a/spec/support/matchers/navigation_matcher.rb +++ b/spec/support/matchers/navigation_matcher.rb @@ -9,6 +9,6 @@ end RSpec::Matchers.define :have_active_sub_navigation do |expected| match do |page| - expect(page.find('.sidebar-sub-level-items > li.active:not(.fly-out-top-item)')).to have_content(expected) + expect(page).to have_css('.sidebar-sub-level-items > li.active:not(.fly-out-top-item)', text: expected) end end |