diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/controllers/projects | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/controllers/projects')
22 files changed, 530 insertions, 213 deletions
diff --git a/spec/controllers/projects/alerting/notifications_controller_spec.rb b/spec/controllers/projects/alerting/notifications_controller_spec.rb index b3d37723ccf..3656cfbcc30 100644 --- a/spec/controllers/projects/alerting/notifications_controller_spec.rb +++ b/spec/controllers/projects/alerting/notifications_controller_spec.rb @@ -38,7 +38,7 @@ RSpec.describe Projects::Alerting::NotificationsController do expect(notify_service_class) .to have_received(:new) - .with(project, nil, permitted_params) + .with(project, permitted_params) end end diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb index dad932f9cdf..1ed61e0990f 100644 --- a/spec/controllers/projects/boards_controller_spec.rb +++ b/spec/controllers/projects/boards_controller_spec.rb @@ -27,7 +27,7 @@ RSpec.describe Projects::BoardsController do list_boards expect(response).to render_template :index - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end context 'with unauthorized user' do @@ -41,7 +41,7 @@ RSpec.describe Projects::BoardsController do list_boards expect(response).to have_gitlab_http_status(:not_found) - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end end @@ -57,7 +57,7 @@ RSpec.describe Projects::BoardsController do list_boards expect(response).to render_template :index - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end end end @@ -85,7 +85,7 @@ RSpec.describe Projects::BoardsController do list_boards format: :json expect(response).to have_gitlab_http_status(:not_found) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end end end @@ -127,7 +127,7 @@ RSpec.describe Projects::BoardsController do expect { read_board board: board }.to change(BoardProjectRecentVisit, :count).by(1) expect(response).to render_template :show - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end context 'with unauthorized user' do @@ -141,7 +141,7 @@ RSpec.describe Projects::BoardsController do read_board board: board expect(response).to have_gitlab_http_status(:not_found) - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end end @@ -154,7 +154,7 @@ RSpec.describe Projects::BoardsController do expect { read_board board: board }.to change(BoardProjectRecentVisit, :count).by(0) expect(response).to render_template :show - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end end end @@ -179,7 +179,7 @@ RSpec.describe Projects::BoardsController do read_board board: board, format: :json expect(response).to have_gitlab_http_status(:not_found) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end end end diff --git a/spec/controllers/projects/branches_controller_spec.rb b/spec/controllers/projects/branches_controller_spec.rb index 625fc5bddda..14a5e7da7d2 100644 --- a/spec/controllers/projects/branches_controller_spec.rb +++ b/spec/controllers/projects/branches_controller_spec.rb @@ -512,7 +512,8 @@ RSpec.describe Projects::BranchesController do state: 'all' } - expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("success") + expect(assigns[:branch_pipeline_statuses]["master"].group).to eq("success") + expect(assigns[:sort]).to eq('updated_desc') end end @@ -543,8 +544,8 @@ RSpec.describe Projects::BranchesController do state: 'all' } - expect(controller.instance_variable_get(:@branch_pipeline_statuses)["master"].group).to eq("running") - expect(controller.instance_variable_get(:@branch_pipeline_statuses)["test"].group).to eq("success") + expect(assigns[:branch_pipeline_statuses]["master"].group).to eq("running") + expect(assigns[:branch_pipeline_statuses]["test"].group).to eq("success") end end @@ -555,10 +556,11 @@ RSpec.describe Projects::BranchesController do params: { namespace_id: project.namespace, project_id: project, - state: 'all' + state: 'stale' } - expect(controller.instance_variable_get(:@branch_pipeline_statuses)).to be_blank + expect(assigns[:branch_pipeline_statuses]).to be_blank + expect(assigns[:sort]).to eq('updated_asc') end end @@ -573,10 +575,12 @@ RSpec.describe Projects::BranchesController do params: { namespace_id: project.namespace, project_id: project, + sort: 'name_asc', state: 'all' } expect(response).to have_gitlab_http_status(:ok) + expect(assigns[:sort]).to eq('name_asc') end end @@ -635,6 +639,34 @@ RSpec.describe Projects::BranchesController do expect(response).to redirect_to project_branches_filtered_path(project, state: 'all') end end + + context 'fetching branches for overview' do + before do + get :index, format: :html, params: { + namespace_id: project.namespace, project_id: project, state: 'overview' + } + end + + it 'sets active and stale branches' do + expect(assigns[:active_branches]).to eq([]) + expect(assigns[:stale_branches].map(&:name)).to eq( + ["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"] + ) + end + + context 'branch_list_keyset_pagination is disabled' do + before do + stub_feature_flags(branch_list_keyset_pagination: false) + end + + it 'sets active and stale branches' do + expect(assigns[:active_branches]).to eq([]) + expect(assigns[:stale_branches].map(&:name)).to eq( + ["feature", "improve/awesome", "merge-test", "markdown", "feature_conflict", "'test'"] + ) + end + end + end end describe 'GET diverging_commit_counts' do diff --git a/spec/controllers/projects/ci/lints_controller_spec.rb b/spec/controllers/projects/ci/lints_controller_spec.rb index c4e040b0287..d778739be38 100644 --- a/spec/controllers/projects/ci/lints_controller_spec.rb +++ b/spec/controllers/projects/ci/lints_controller_spec.rb @@ -82,7 +82,7 @@ RSpec.describe Projects::Ci::LintsController do end it 'renders json' do - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' expect(parsed_body).to include('errors', 'warnings', 'jobs', 'valid') expect(parsed_body).to match_schema('entities/lint_result_entity') end diff --git a/spec/controllers/projects/clusters/applications_controller_spec.rb b/spec/controllers/projects/clusters/applications_controller_spec.rb index b50814b4790..cc6170252c1 100644 --- a/spec/controllers/projects/clusters/applications_controller_spec.rb +++ b/spec/controllers/projects/clusters/applications_controller_spec.rb @@ -32,7 +32,7 @@ RSpec.describe Projects::Clusters::ApplicationsController do let(:cluster) { create(:cluster, :project, :provided_by_gcp) } let(:project) { cluster.project } - let(:application) { 'helm' } + let(:application) { 'ingress' } let(:params) { { application: application, id: cluster.id } } describe 'functionality' do @@ -48,7 +48,7 @@ RSpec.describe Projects::Clusters::ApplicationsController do expect { subject }.to change { current_application.count } expect(response).to have_gitlab_http_status(:no_content) - expect(cluster.application_helm).to be_scheduled + expect(cluster.application_ingress).to be_scheduled end context 'when cluster do not exists' do @@ -72,7 +72,7 @@ RSpec.describe Projects::Clusters::ApplicationsController do context 'when application is already installing' do before do - create(:clusters_applications_helm, :installing, cluster: cluster) + create(:clusters_applications_ingress, :installing, cluster: cluster) end it 'returns 400' do diff --git a/spec/controllers/projects/clusters_controller_spec.rb b/spec/controllers/projects/clusters_controller_spec.rb index 52cd6869b04..dd3440f7660 100644 --- a/spec/controllers/projects/clusters_controller_spec.rb +++ b/spec/controllers/projects/clusters_controller_spec.rb @@ -500,7 +500,7 @@ RSpec.describe Projects::ClustersController do expect { post_create_aws }.not_to change { Clusters::Cluster.count } expect(response).to have_gitlab_http_status(:unprocessable_entity) - expect(response.content_type).to eq('application/json') + expect(response.media_type).to eq('application/json') expect(response.body).to include('is invalid') end end diff --git a/spec/controllers/projects/commits_controller_spec.rb b/spec/controllers/projects/commits_controller_spec.rb index 557002acbc0..4cf77fde3a1 100644 --- a/spec/controllers/projects/commits_controller_spec.rb +++ b/spec/controllers/projects/commits_controller_spec.rb @@ -80,7 +80,7 @@ RSpec.describe Projects::CommitsController do it "renders as atom" do expect(response).to be_successful - expect(response.content_type).to eq('application/atom+xml') + expect(response.media_type).to eq('application/atom+xml') end it 'renders summary with type=html' do @@ -105,7 +105,7 @@ RSpec.describe Projects::CommitsController do it "renders as HTML" do expect(response).to be_successful - expect(response.content_type).to eq('text/html') + expect(response.media_type).to eq('text/html') end end end diff --git a/spec/controllers/projects/cycle_analytics_controller_spec.rb b/spec/controllers/projects/cycle_analytics_controller_spec.rb index 24c2d568d9a..ccd213fdffa 100644 --- a/spec/controllers/projects/cycle_analytics_controller_spec.rb +++ b/spec/controllers/projects/cycle_analytics_controller_spec.rb @@ -32,41 +32,5 @@ RSpec.describe Projects::CycleAnalyticsController do end end - describe 'value stream analytics not set up flag' do - context 'with no data' do - it 'is true' do - get(:show, - params: { - namespace_id: project.namespace, - project_id: project - }) - - expect(response).to be_successful - expect(assigns(:cycle_analytics_no_data)).to eq(true) - end - end - - context 'with data' do - before do - issue = create(:issue, project: project, created_at: 4.days.ago) - milestone = create(:milestone, project: project, created_at: 5.days.ago) - issue.update(milestone: milestone) - - create_merge_request_closing_issue(user, project, issue) - end - - it 'is false' do - get(:show, - params: { - namespace_id: project.namespace, - project_id: project - }) - - expect(response).to be_successful - expect(assigns(:cycle_analytics_no_data)).to eq(false) - end - end - end - include_examples GracefulTimeoutHandling end diff --git a/spec/controllers/projects/feature_flags_controller_spec.rb b/spec/controllers/projects/feature_flags_controller_spec.rb index 1473ec95192..d5fc80bd5a7 100644 --- a/spec/controllers/projects/feature_flags_controller_spec.rb +++ b/spec/controllers/projects/feature_flags_controller_spec.rb @@ -217,15 +217,6 @@ RSpec.describe Projects::FeatureFlagsController do expect(json_response['feature_flags'].count).to eq(3) end - - it 'returns only version 1 flags when new version flags are disabled' do - stub_feature_flags(feature_flags_new_version: false) - - subject - - expected = [feature_flag_active.name, feature_flag_inactive.name].sort - expect(json_response['feature_flags'].map { |f| f['name'] }.sort).to eq(expected) - end end end @@ -283,24 +274,6 @@ RSpec.describe Projects::FeatureFlagsController do expect(json_response['name']).to eq(other_feature_flag.name) end - it 'routes based on iid when new version flags are disabled' do - stub_feature_flags(feature_flags_new_version: false) - other_project = create(:project) - other_project.add_developer(user) - other_feature_flag = create(:operations_feature_flag, project: other_project, - name: 'other_flag') - params = { - namespace_id: other_project.namespace, - project_id: other_project, - iid: other_feature_flag.iid - } - - get(:show, params: params, format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response['name']).to eq(other_feature_flag.name) - end - context 'when feature flag is not found' do let!(:feature_flag) { } @@ -386,14 +359,6 @@ RSpec.describe Projects::FeatureFlagsController do expect(json_response['version']).to eq('new_version_flag') end - it 'returns a 404 when new version flags are disabled' do - stub_feature_flags(feature_flags_new_version: false) - - subject - - expect(response).to have_gitlab_http_status(:not_found) - end - it 'returns strategies ordered by id' do first_strategy = create(:operations_strategy, feature_flag: new_version_feature_flag) second_strategy = create(:operations_strategy, feature_flag: new_version_feature_flag) @@ -791,54 +756,6 @@ RSpec.describe Projects::FeatureFlagsController do expect(Operations::FeatureFlag.count).to eq(0) end end - - context 'when version 2 flags are disabled' do - context 'and attempting to create a version 2 flag' do - let(:params) do - { - namespace_id: project.namespace, - project_id: project, - operations_feature_flag: { - name: 'my_feature_flag', - active: true, - version: 'new_version_flag' - } - } - end - - it 'returns a 400' do - stub_feature_flags(feature_flags_new_version: false) - - subject - - expect(response).to have_gitlab_http_status(:bad_request) - expect(Operations::FeatureFlag.count).to eq(0) - end - end - - context 'and attempting to create a version 1 flag' do - let(:params) do - { - namespace_id: project.namespace, - project_id: project, - operations_feature_flag: { - name: 'my_feature_flag', - active: true - } - } - end - - it 'creates the flag' do - stub_feature_flags(feature_flags_new_version: false) - - subject - - expect(response).to have_gitlab_http_status(:ok) - expect(Operations::FeatureFlag.count).to eq(1) - expect(json_response['version']).to eq('legacy_flag') - end - end - end end describe 'DELETE destroy.json' do @@ -913,15 +830,6 @@ RSpec.describe Projects::FeatureFlagsController do it 'deletes the flag' do expect { subject }.to change { Operations::FeatureFlag.count }.by(-1) end - - context 'when new version flags are disabled' do - it 'returns a 404' do - stub_feature_flags(feature_flags_new_version: false) - - expect { subject }.not_to change { Operations::FeatureFlag.count } - expect(response).to have_gitlab_http_status(:not_found) - end - end end end @@ -1610,15 +1518,6 @@ RSpec.describe Projects::FeatureFlagsController do expect(json_response['strategies'].first['scopes']).to eq([]) end - it 'does not update the flag if version 2 flags are disabled' do - stub_feature_flags(feature_flags_new_version: false) - - put_request(new_version_flag, { name: 'some-other-name' }) - - expect(response).to have_gitlab_http_status(:not_found) - expect(new_version_flag.reload.name).to eq('new-feature') - end - it 'updates the flag when legacy feature flags are set to be read only' do stub_feature_flags(feature_flags_legacy_read_only: true) diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb index 26e1842468b..12c8c84dd77 100644 --- a/spec/controllers/projects/issues_controller_spec.rb +++ b/spec/controllers/projects/issues_controller_spec.rb @@ -62,6 +62,56 @@ RSpec.describe Projects::IssuesController do expect(response).to have_gitlab_http_status(:moved_permanently) end end + + describe 'the null hypothesis experiment', :snowplow do + it 'defines the expected before actions' do + expect(controller).to use_before_action(:run_null_hypothesis_experiment) + end + + context 'when rolled out to 100%' do + it 'assigns the candidate experience and tracks the event' do + get :index, params: { namespace_id: project.namespace, project_id: project } + + expect_snowplow_event( + category: 'null_hypothesis', + action: 'index', + context: [{ + schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', + data: { variant: 'candidate', experiment: 'null_hypothesis', key: anything } + }] + ) + end + end + + context 'when not rolled out' do + before do + stub_feature_flags(null_hypothesis: false) + end + + it 'assigns the control experience and tracks the event' do + get :index, params: { namespace_id: project.namespace, project_id: project } + + expect_snowplow_event( + category: 'null_hypothesis', + action: 'index', + context: [{ + schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', + data: { variant: 'control', experiment: 'null_hypothesis', key: anything } + }] + ) + end + end + + context 'when gitlab_experiments is disabled' do + it 'does not run the experiment at all' do + stub_feature_flags(gitlab_experiments: false) + + expect(controller).not_to receive(:run_null_hypothesis_experiment) + + get :index, params: { namespace_id: project.namespace, project_id: project } + end + end + end end context 'internal issue tracker' do @@ -1128,12 +1178,12 @@ RSpec.describe Projects::IssuesController do { merge_request_to_resolve_discussions_of: merge_request.iid } end - def post_issue(issue_params, other_params: {}) + def post_issue(other_params: {}, **issue_params) post :create, params: { namespace_id: project.namespace.to_param, project_id: project, issue: issue_params, merge_request_to_resolve_discussions_of: merge_request.iid }.merge(other_params) end it 'creates an issue for the project' do - expect { post_issue({ title: 'Hello' }) }.to change { project.issues.reload.size }.by(1) + expect { post_issue(title: 'Hello') }.to change { project.issues.reload.size }.by(1) end it "doesn't overwrite given params" do @@ -1157,7 +1207,7 @@ RSpec.describe Projects::IssuesController do describe "resolving a single discussion" do before do - post_issue({ title: 'Hello' }, other_params: { discussion_to_resolve: discussion.id }) + post_issue(title: 'Hello', other_params: { discussion_to_resolve: discussion.id }) end it 'resolves a single discussion' do discussion.first_note.reload diff --git a/spec/controllers/projects/jobs_controller_spec.rb b/spec/controllers/projects/jobs_controller_spec.rb index 80cb16966e5..3309b15b276 100644 --- a/spec/controllers/projects/jobs_controller_spec.rb +++ b/spec/controllers/projects/jobs_controller_spec.rb @@ -15,6 +15,54 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do end describe 'GET index' do + describe 'pushing tracking_data to Gon' do + before do + stub_experiment(jobs_empty_state: experiment_active) + stub_experiment_for_subject(jobs_empty_state: in_experiment_group) + + get_index + end + + context 'when experiment not active' do + let(:experiment_active) { false } + let(:in_experiment_group) { false } + + it 'does not push tracking_data to Gon' do + expect(Gon.tracking_data).to be_nil + end + end + + context 'when experiment active and user in control group' do + let(:experiment_active) { true } + let(:in_experiment_group) { false } + + it 'pushes tracking_data to Gon' do + expect(Gon.tracking_data).to match( + { + category: 'Growth::Activation::Experiment::JobsEmptyState', + action: 'click_button', + label: anything, + property: 'control_group' + } + ) + end + end + + context 'when experiment active and user in experimental group' do + let(:experiment_active) { true } + let(:in_experiment_group) { true } + + it 'pushes tracking_data to gon' do + expect(Gon.tracking_data).to match( + category: 'Growth::Activation::Experiment::JobsEmptyState', + action: 'click_button', + label: anything, + property: 'experimental_group' + ) + end + end + end + context 'when scope is pending' do before do create(:ci_build, :pending, pipeline: pipeline) @@ -113,11 +161,11 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do context 'when requesting HTML' do context 'when job exists' do - before do - get_show(id: job.id) - end + let(:extra_params) { { id: job.id } } it 'has a job' do + get_show(**extra_params) + expect(response).to have_gitlab_http_status(:ok) expect(assigns(:build).id).to eq(job.id) end @@ -599,6 +647,46 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do expect(json_response['total']).to be_present expect(json_response['lines'].count).to be_positive end + + context 'when CI_DEBUG_TRACE enabled' do + let!(:variable) { create(:ci_instance_variable, key: 'CI_DEBUG_TRACE', value: 'true') } + + context 'with proper permissions on a project' do + before do + project.add_developer(user) + sign_in(user) + end + + it 'returns response ok' do + get_trace + + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'without proper permissions for debug logging' do + before do + project.add_guest(user) + sign_in(user) + end + + it 'returns response forbidden' do + get_trace + + expect(response).to have_gitlab_http_status(:forbidden) + end + + context 'with restrict_access_to_build_debug_mode feature disabled' do + before do + stub_feature_flags(restrict_access_to_build_debug_mode: false) + end + + it 'returns response forbidden' do + expect(response).to have_gitlab_http_status(:ok) + end + end + end + end end context 'when job has a trace' do @@ -806,18 +894,6 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do expect(job.reload).to be_pending end - - context 'when FF ci_manual_bridges is disabled' do - before do - stub_feature_flags(ci_manual_bridges: false) - end - - it 'returns 404' do - post_play - - expect(response).to have_gitlab_http_status(:not_found) - end - end end end @@ -1027,7 +1103,7 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do } end - context "when job has a trace artifact" do + context 'when job has a trace artifact' do let(:job) { create(:ci_build, :trace_artifact, pipeline: pipeline) } it "sets #{Gitlab::Workhorse::DETECT_HEADER} header" do @@ -1038,6 +1114,62 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do expect(response.body).to eq(job.job_artifacts_trace.open.read) expect(response.header[Gitlab::Workhorse::DETECT_HEADER]).to eq "true" end + + context 'when CI_DEBUG_TRACE enabled' do + before do + create(:ci_instance_variable, key: 'CI_DEBUG_TRACE', value: 'true') + end + + context 'with proper permissions for debug logging on a project' do + before do + project.add_developer(user) + sign_in(user) + end + + it 'returns response ok' do + response = subject + + expect(response).to have_gitlab_http_status(:ok) + end + + context 'with restrict_access_to_build_debug_mode feature disabled' do + before do + stub_feature_flags(restrict_access_to_build_debug_mode: false) + end + + it 'returns response ok' do + response = subject + + expect(response).to have_gitlab_http_status(:ok) + end + end + end + + context 'without proper permissions for debug logging on a project' do + before do + project.add_reporter(user) + sign_in(user) + end + + it 'returns response forbidden' do + response = subject + + expect(response).to have_gitlab_http_status(:forbidden) + end + + context 'with restrict_access_to_build_debug_mode feature disabled' do + before do + stub_feature_flags(restrict_access_to_build_debug_mode: false) + end + + it 'returns response ok' do + response = subject + + expect(response).to have_gitlab_http_status(:ok) + end + end + end + end end context "when job has a trace file" do diff --git a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb index bda1f1a3b1c..f4f0a9f8108 100644 --- a/spec/controllers/projects/merge_requests/diffs_controller_spec.rb +++ b/spec/controllers/projects/merge_requests/diffs_controller_spec.rb @@ -74,6 +74,8 @@ RSpec.describe Projects::MergeRequests::DiffsController do let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } before do + stub_feature_flags(diffs_gradual_load: false) + project.add_maintainer(user) sign_in(user) end diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index f159f0e6099..cf8b4c564c4 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -1498,6 +1498,121 @@ RSpec.describe Projects::MergeRequestsController do end end + describe 'GET codequality_reports' do + let_it_be(:merge_request) do + create(:merge_request, + :with_diffs, + :with_merge_request_pipeline, + target_project: project, + source_project: project + ) + end + + let(:pipeline) do + create(:ci_pipeline, + :success, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha) + end + + before do + allow_any_instance_of(MergeRequest) + .to receive(:compare_codequality_reports) + .and_return(codequality_comparison) + + allow_any_instance_of(MergeRequest) + .to receive(:actual_head_pipeline) + .and_return(pipeline) + end + + subject do + get :codequality_reports, params: { + namespace_id: project.namespace.to_param, + project_id: project, + id: merge_request.iid + }, + format: :json + end + + context 'permissions on a public project with private CI/CD' do + let(:project) { project_public_with_private_builds } + let(:codequality_comparison) { { status: :parsed, data: { summary: 1 } } } + + context 'while signed out' do + before do + sign_out(user) + end + + it 'responds with a 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_blank + end + end + + context 'while signed in as an unrelated user' do + before do + sign_in(create(:user)) + end + + it 'responds with a 404' do + subject + + expect(response).to have_gitlab_http_status(:not_found) + expect(response.body).to be_blank + end + end + end + + context 'when pipeline has jobs with codequality reports' do + before do + allow_any_instance_of(MergeRequest) + .to receive(:has_codequality_reports?) + .and_return(true) + end + + context 'when processing codequality reports is in progress' do + let(:codequality_comparison) { { status: :parsing } } + + it 'sends polling interval' do + expect(Gitlab::PollingInterval).to receive(:set_header) + + subject + end + + it 'returns 204 HTTP status' do + subject + + expect(response).to have_gitlab_http_status(:no_content) + end + end + + context 'when processing codequality reports is completed' do + let(:codequality_comparison) { { status: :parsed, data: { summary: 1 } } } + + it 'returns codequality reports' do + subject + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response).to eq({ 'summary' => 1 }) + end + end + end + + context 'when pipeline has job without a codequality report' do + let(:codequality_comparison) { { status: :error, status_reason: 'no codequality report' } } + + it 'returns a 400' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + expect(json_response).to eq({ 'status_reason' => 'no codequality report' }) + end + end + end + describe 'POST remove_wip' do before do merge_request.title = merge_request.wip_title diff --git a/spec/controllers/projects/milestones_controller_spec.rb b/spec/controllers/projects/milestones_controller_spec.rb index 9e5d41b1075..b93f1b41a7e 100644 --- a/spec/controllers/projects/milestones_controller_spec.rb +++ b/spec/controllers/projects/milestones_controller_spec.rb @@ -33,14 +33,14 @@ RSpec.describe Projects::MilestonesController do view_milestone expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end it 'returns milestone json' do view_milestone format: :json expect(response).to have_gitlab_http_status(:not_found) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end end @@ -189,7 +189,7 @@ RSpec.describe Projects::MilestonesController do get :labels, params: { namespace_id: group.id, project_id: project.id, id: milestone.iid }, format: :json expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' expect(json_response['html']).not_to include(label.title) end @@ -200,7 +200,7 @@ RSpec.describe Projects::MilestonesController do get :labels, params: { namespace_id: group.id, project_id: project.id, id: milestone.iid }, format: :json expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' expect(json_response['html']).to include(label.title) end @@ -262,7 +262,7 @@ RSpec.describe Projects::MilestonesController do get :participants, params: params expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' expect(json_response['html']).to include(issue_assignee.name) end end @@ -277,7 +277,7 @@ RSpec.describe Projects::MilestonesController do get :participants, params: params expect(response).to have_gitlab_http_status(:ok) - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' expect(json_response['html']).not_to include(issue_assignee.name) end end diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb index d76432f71b3..e96113c0133 100644 --- a/spec/controllers/projects/notes_controller_spec.rb +++ b/spec/controllers/projects/notes_controller_spec.rb @@ -426,7 +426,7 @@ RSpec.describe Projects::NotesController do let(:note_text) { "/award :thumbsup:\n/estimate 1d\n/spend 3h" } let(:extra_request_params) { { format: :json } } - it 'includes changes in commands_changes ' do + it 'includes changes in commands_changes' do create! expect(response).to have_gitlab_http_status(:ok) diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index 0720124ea57..e1405660ccb 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -1149,11 +1149,17 @@ RSpec.describe Projects::PipelinesController do end end - describe 'GET config_variables.json' do + describe 'GET config_variables.json', :use_clean_rails_memory_store_caching do + include ReactiveCachingHelpers + let(:result) { YAML.dump(ci_config) } + let(:service) { Ci::ListConfigVariablesService.new(project, user) } before do stub_gitlab_ci_yml_for_sha(sha, result) + allow(Ci::ListConfigVariablesService) + .to receive(:new) + .and_return(service) end context 'when sending a valid sha' do @@ -1170,6 +1176,10 @@ RSpec.describe Projects::PipelinesController do } end + before do + synchronous_reactive_cache(service) + end + it 'returns variable list' do get_config_variables @@ -1182,6 +1192,10 @@ RSpec.describe Projects::PipelinesController do let(:sha) { 'invalid-sha' } let(:ci_config) { nil } + before do + synchronous_reactive_cache(service) + end + it 'returns empty json' do get_config_variables @@ -1204,6 +1218,10 @@ RSpec.describe Projects::PipelinesController do } end + before do + synchronous_reactive_cache(service) + end + it 'returns empty result' do get_config_variables @@ -1212,6 +1230,27 @@ RSpec.describe Projects::PipelinesController do end end + context 'when the cache is empty' do + let(:sha) { 'master' } + let(:ci_config) do + { + variables: { + KEY1: { value: 'val 1', description: 'description 1' } + }, + test: { + stage: 'test', + script: 'echo' + } + } + end + + it 'returns no content' do + get_config_variables + + expect(response).to have_gitlab_http_status(:no_content) + end + end + private def stub_gitlab_ci_yml_for_sha(sha, result) diff --git a/spec/controllers/projects/prometheus/alerts_controller_spec.rb b/spec/controllers/projects/prometheus/alerts_controller_spec.rb index cbd599506df..46de8aa4baf 100644 --- a/spec/controllers/projects/prometheus/alerts_controller_spec.rb +++ b/spec/controllers/projects/prometheus/alerts_controller_spec.rb @@ -168,7 +168,7 @@ RSpec.describe Projects::Prometheus::AlertsController do expect(Projects::Prometheus::Alerts::NotifyService) .to receive(:new) - .with(project, nil, duck_type(:permitted?)) + .with(project, duck_type(:permitted?)) .and_return(notify_service) end diff --git a/spec/controllers/projects/raw_controller_spec.rb b/spec/controllers/projects/raw_controller_spec.rb index 43cf1a16051..dfe7ba34e6d 100644 --- a/spec/controllers/projects/raw_controller_spec.rb +++ b/spec/controllers/projects/raw_controller_spec.rb @@ -5,11 +5,11 @@ require 'spec_helper' RSpec.describe Projects::RawController do include RepoHelpers - let(:project) { create(:project, :public, :repository) } + let_it_be(:project) { create(:project, :public, :repository) } let(:inline) { nil } describe 'GET #show' do - subject do + def get_show get(:show, params: { namespace_id: project.namespace, @@ -19,6 +19,18 @@ RSpec.describe Projects::RawController do }) end + subject { get_show } + + shared_examples 'single Gitaly request' do + it 'makes a single Gitaly request', :request_store, :clean_gitlab_redis_cache do + # Warm up to populate repository cache + get_show + RequestStore.clear! + + expect { get_show }.to change { Gitlab::GitalyClient.get_request_count }.by(1) + end + end + context 'regular filename' do let(:filepath) { 'master/README.md' } @@ -33,6 +45,7 @@ RSpec.describe Projects::RawController do it_behaves_like 'project cache control headers' it_behaves_like 'content disposition headers' + include_examples 'single Gitaly request' end context 'image header' do @@ -48,6 +61,7 @@ RSpec.describe Projects::RawController do it_behaves_like 'project cache control headers' it_behaves_like 'content disposition headers' + include_examples 'single Gitaly request' end context 'with LFS files' do @@ -56,6 +70,7 @@ RSpec.describe Projects::RawController do it_behaves_like 'a controller that can serve LFS files' it_behaves_like 'project cache control headers' + include_examples 'single Gitaly request' end context 'when the endpoint receives requests above the limit', :clean_gitlab_redis_cache do diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index 07fb03b39c6..c1f1373ddc2 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -83,7 +83,7 @@ RSpec.describe Projects::ReleasesController do let(:format) { :html } it 'returns a text/html content_type' do - expect(response.content_type).to eq 'text/html' + expect(response.media_type).to eq 'text/html' end it_behaves_like 'common access controls' @@ -101,7 +101,7 @@ RSpec.describe Projects::ReleasesController do let(:format) { :json } it 'returns an application/json content_type' do - expect(response.content_type).to eq 'application/json' + expect(response.media_type).to eq 'application/json' end it "returns the project's releases as JSON, ordered by released_at" do diff --git a/spec/controllers/projects/runners_controller_spec.rb b/spec/controllers/projects/runners_controller_spec.rb index 2443a823070..d63d88f8283 100644 --- a/spec/controllers/projects/runners_controller_spec.rb +++ b/spec/controllers/projects/runners_controller_spec.rb @@ -78,40 +78,84 @@ RSpec.describe Projects::RunnersController do let(:group) { create(:group) } let(:project) { create(:project, group: group) } - it 'toggles shared_runners_enabled when the group allows shared runners' do - project.update!(shared_runners_enabled: true) + context 'without feature flag' do + before do + stub_feature_flags(vueify_shared_runners_toggle: false) + end - post :toggle_shared_runners, params: params + it 'toggles shared_runners_enabled when the group allows shared runners' do + project.update!(shared_runners_enabled: true) - project.reload + post :toggle_shared_runners, params: params - expect(response).to have_gitlab_http_status(:found) - expect(project.shared_runners_enabled).to eq(false) - end + project.reload - it 'toggles shared_runners_enabled when the group disallows shared runners but allows overrides' do - group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: true) - project.update!(shared_runners_enabled: false) + expect(response).to have_gitlab_http_status(:found) + expect(project.shared_runners_enabled).to eq(false) + end - post :toggle_shared_runners, params: params + it 'toggles shared_runners_enabled when the group disallows shared runners but allows overrides' do + group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: true) + project.update!(shared_runners_enabled: false) - project.reload + post :toggle_shared_runners, params: params - expect(response).to have_gitlab_http_status(:found) - expect(project.shared_runners_enabled).to eq(true) + project.reload + + expect(response).to have_gitlab_http_status(:found) + expect(project.shared_runners_enabled).to eq(true) + end + + it 'does not enable if the group disallows shared runners' do + group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: false) + project.update!(shared_runners_enabled: false) + + post :toggle_shared_runners, params: params + + project.reload + + expect(response).to have_gitlab_http_status(:found) + expect(project.shared_runners_enabled).to eq(false) + expect(flash[:alert]).to eq('Cannot enable shared runners because parent group does not allow it') + end end - it 'does not enable if the group disallows shared runners' do - group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: false) - project.update!(shared_runners_enabled: false) + context 'with feature flag: vueify_shared_runners_toggle' do + it 'toggles shared_runners_enabled when the group allows shared runners' do + project.update!(shared_runners_enabled: true) - post :toggle_shared_runners, params: params + post :toggle_shared_runners, params: params - project.reload + project.reload - expect(response).to have_gitlab_http_status(:found) - expect(project.shared_runners_enabled).to eq(false) - expect(flash[:alert]).to eq("Cannot enable shared runners because parent group does not allow it") + expect(response).to have_gitlab_http_status(:ok) + expect(project.shared_runners_enabled).to eq(false) + end + + it 'toggles shared_runners_enabled when the group disallows shared runners but allows overrides' do + group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: true) + project.update!(shared_runners_enabled: false) + + post :toggle_shared_runners, params: params + + project.reload + + expect(response).to have_gitlab_http_status(:ok) + expect(project.shared_runners_enabled).to eq(true) + end + + it 'does not enable if the group disallows shared runners' do + group.update!(shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: false) + project.update!(shared_runners_enabled: false) + + post :toggle_shared_runners, params: params + + project.reload + + expect(response).to have_gitlab_http_status(:unauthorized) + expect(project.shared_runners_enabled).to eq(false) + expect(json_response['error']).to eq('Cannot enable shared runners because parent group does not allow it') + end end end end diff --git a/spec/controllers/projects/static_site_editor_controller_spec.rb b/spec/controllers/projects/static_site_editor_controller_spec.rb index 867b2b51039..b563f3b667f 100644 --- a/spec/controllers/projects/static_site_editor_controller_spec.rb +++ b/spec/controllers/projects/static_site_editor_controller_spec.rb @@ -7,6 +7,21 @@ RSpec.describe Projects::StaticSiteEditorController do let_it_be(:user) { create(:user) } let(:data) { { key: 'value' } } + describe 'GET index' do + let(:default_params) do + { + namespace_id: project.namespace, + project_id: project + } + end + + it 'responds with 404 page' do + get :index, params: default_params + + expect(response).to have_gitlab_http_status(:not_found) + end + end + describe 'GET show' do render_views diff --git a/spec/controllers/projects/terraform_controller_spec.rb b/spec/controllers/projects/terraform_controller_spec.rb index 1978b9494fa..73f0a5b26fb 100644 --- a/spec/controllers/projects/terraform_controller_spec.rb +++ b/spec/controllers/projects/terraform_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Projects::TerraformController do - let_it_be(:project) { create(:project) } + let_it_be(:project) { create(:project, :public) } describe 'GET index' do subject { get :index, params: { namespace_id: project.namespace, project_id: project } } @@ -34,5 +34,15 @@ RSpec.describe Projects::TerraformController do expect(response).to have_gitlab_http_status(:not_found) end end + + context 'when no user is present' do + before do + subject + end + + it 'shows 404' do + expect(response).to have_gitlab_http_status(:not_found) + end + end end end |