summaryrefslogtreecommitdiff
path: root/spec/controllers/projects
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/controllers/projects
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/controllers/projects')
-rw-r--r--spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb4
-rw-r--r--spec/controllers/projects/ci/lints_controller_spec.rb73
-rw-r--r--spec/controllers/projects/cycle_analytics/events_controller_spec.rb2
-rw-r--r--spec/controllers/projects/cycle_analytics_controller_spec.rb2
-rw-r--r--spec/controllers/projects/environments_controller_spec.rb36
-rw-r--r--spec/controllers/projects/forks_controller_spec.rb19
-rw-r--r--spec/controllers/projects/hooks_controller_spec.rb3
-rw-r--r--spec/controllers/projects/incidents_controller_spec.rb46
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb70
-rw-r--r--spec/controllers/projects/logs_controller_spec.rb26
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb4
-rw-r--r--spec/controllers/projects/notes_controller_spec.rb1
-rw-r--r--spec/controllers/projects/pipelines/tests_controller_spec.rb32
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb224
-rw-r--r--spec/controllers/projects/product_analytics_controller_spec.rb95
-rw-r--r--spec/controllers/projects/prometheus/alerts_controller_spec.rb18
-rw-r--r--spec/controllers/projects/protected_branches_controller_spec.rb1
-rw-r--r--spec/controllers/projects/serverless/functions_controller_spec.rb1
-rw-r--r--spec/controllers/projects/services_controller_spec.rb2
-rw-r--r--spec/controllers/projects/settings/operations_controller_spec.rb4
-rw-r--r--spec/controllers/projects/settings/repository_controller_spec.rb3
-rw-r--r--spec/controllers/projects/snippets_controller_spec.rb27
-rw-r--r--spec/controllers/projects/tags_controller_spec.rb10
-rw-r--r--spec/controllers/projects/variables_controller_spec.rb1
24 files changed, 438 insertions, 266 deletions
diff --git a/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb b/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb
index 252ad6ec9c4..594c24bb7e3 100644
--- a/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb
+++ b/spec/controllers/projects/ci/daily_build_group_report_results_controller_spec.rb
@@ -149,8 +149,4 @@ RSpec.describe Projects::Ci::DailyBuildGroupReportResultsController do
date: date
)
end
-
- def csv_response
- CSV.parse(response.body)
- end
end
diff --git a/spec/controllers/projects/ci/lints_controller_spec.rb b/spec/controllers/projects/ci/lints_controller_spec.rb
index eb92385fc83..b3e08292546 100644
--- a/spec/controllers/projects/ci/lints_controller_spec.rb
+++ b/spec/controllers/projects/ci/lints_controller_spec.rb
@@ -45,6 +45,9 @@ RSpec.describe Projects::Ci::LintsController do
end
describe 'POST #create' do
+ subject { post :create, params: params }
+
+ let(:params) { { namespace_id: project.namespace, project_id: project, content: content } }
let(:remote_file_path) { 'https://gitlab.com/gitlab-org/gitlab-foss/blob/1234/.gitlab-ci-1.yml' }
let(:remote_file_content) do
@@ -72,18 +75,62 @@ RSpec.describe Projects::Ci::LintsController do
before do
stub_full_request(remote_file_path).to_return(body: remote_file_content)
project.add_developer(user)
+ end
- post :create, params: { namespace_id: project.namespace, project_id: project, content: content }
+ shared_examples 'returns a successful validation' do
+ it 'returns successfully' do
+ subject
+ expect(response).to be_successful
+ end
+
+ it 'render show page' do
+ subject
+ expect(response).to render_template :show
+ end
+
+ it 'retrieves project' do
+ subject
+ expect(assigns(:project)).to eq(project)
+ end
end
- it { expect(response).to be_successful }
+ context 'using legacy validation (YamlProcessor)' do
+ it_behaves_like 'returns a successful validation'
- it 'render show page' do
- expect(response).to render_template :show
+ it 'runs validations through YamlProcessor' do
+ expect(Gitlab::Ci::YamlProcessor).to receive(:new_with_validation_errors).and_call_original
+
+ subject
+ end
end
- it 'retrieves project' do
- expect(assigns(:project)).to eq(project)
+ context 'using dry_run mode' do
+ subject { post :create, params: params.merge(dry_run: 'true') }
+
+ it_behaves_like 'returns a successful validation'
+
+ it 'runs validations through Ci::CreatePipelineService' do
+ expect(Ci::CreatePipelineService)
+ .to receive(:new)
+ .with(project, user, ref: 'master')
+ .and_call_original
+
+ subject
+ end
+
+ context 'when dry_run feature flag is disabled' do
+ before do
+ stub_feature_flags(ci_lint_creates_pipeline_with_dry_run: false)
+ end
+
+ it_behaves_like 'returns a successful validation'
+
+ it 'runs validations through YamlProcessor' do
+ expect(Gitlab::Ci::YamlProcessor).to receive(:new_with_validation_errors).and_call_original
+
+ subject
+ end
+ end
end
end
@@ -98,13 +145,23 @@ RSpec.describe Projects::Ci::LintsController do
before do
project.add_developer(user)
-
- post :create, params: { namespace_id: project.namespace, project_id: project, content: content }
end
it 'assigns errors' do
+ subject
+
expect(assigns[:errors]).to eq(['root config contains unknown keys: rubocop'])
end
+
+ context 'with dry_run mode' do
+ subject { post :create, params: params.merge(dry_run: 'true') }
+
+ it 'assigns errors' do
+ subject
+
+ expect(assigns[:errors]).to eq(['root config contains unknown keys: rubocop'])
+ end
+ end
end
context 'without enough privileges' do
diff --git a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb
index 408ce51d34b..c5b72ff2b3b 100644
--- a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb
+++ b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb
@@ -57,6 +57,8 @@ RSpec.describe Projects::CycleAnalytics::EventsController do
end
end
+ include_examples GracefulTimeoutHandling
+
def get_issue(additional_params: {})
params = additional_params.merge(namespace_id: project.namespace, project_id: project)
get(:issue, params: params, format: :json)
diff --git a/spec/controllers/projects/cycle_analytics_controller_spec.rb b/spec/controllers/projects/cycle_analytics_controller_spec.rb
index ec853b74b9b..e956065972f 100644
--- a/spec/controllers/projects/cycle_analytics_controller_spec.rb
+++ b/spec/controllers/projects/cycle_analytics_controller_spec.rb
@@ -67,4 +67,6 @@ RSpec.describe Projects::CycleAnalyticsController do
end
end
end
+
+ include_examples GracefulTimeoutHandling
end
diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb
index 85ec1f7396d..d1142cbd129 100644
--- a/spec/controllers/projects/environments_controller_spec.rb
+++ b/spec/controllers/projects/environments_controller_spec.rb
@@ -348,34 +348,10 @@ RSpec.describe Projects::EnvironmentsController do
end
describe 'GET #metrics_redirect' do
- it 'redirects to environment if it exists' do
+ it 'redirects to metrics dashboard page' do
get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
- expect(response).to redirect_to(environment_metrics_path(environment))
- end
-
- context 'with anonymous user and public dashboard visibility' do
- let(:project) { create(:project, :public) }
- let(:user) { create(:user) }
-
- it 'redirects successfully' do
- project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
-
- get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
-
- expect(response).to redirect_to(environment_metrics_path(environment))
- end
- end
-
- context 'when there are no environments' do
- let(:environment) { }
-
- it 'redirects to empty metrics page' do
- get :metrics_redirect, params: { namespace_id: project.namespace, project_id: project }
-
- expect(response).to be_ok
- expect(response).to render_template 'empty_metrics'
- end
+ expect(response).to redirect_to(project_metrics_dashboard_path(project))
end
end
@@ -385,12 +361,12 @@ RSpec.describe Projects::EnvironmentsController do
end
context 'when environment has no metrics' do
- it 'returns a metrics page' do
+ it 'redirects to metrics dashboard page' do
expect(environment).not_to receive(:metrics)
get :metrics, params: environment_params
- expect(response).to be_ok
+ expect(response).to redirect_to(project_metrics_dashboard_path(project, environment: environment))
end
context 'when requesting metrics as JSON' do
@@ -440,12 +416,12 @@ RSpec.describe Projects::EnvironmentsController do
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
- it 'returns success' do
+ it 'redirects to metrics dashboard page' do
project.project_feature.update!(metrics_dashboard_access_level: ProjectFeature::ENABLED)
get :metrics, params: environment_params
- expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to redirect_to(project_metrics_dashboard_path(project, environment: environment))
end
end
end
diff --git a/spec/controllers/projects/forks_controller_spec.rb b/spec/controllers/projects/forks_controller_spec.rb
index 4c0fd7b8954..e8b30294cdd 100644
--- a/spec/controllers/projects/forks_controller_spec.rb
+++ b/spec/controllers/projects/forks_controller_spec.rb
@@ -162,9 +162,25 @@ RSpec.describe Projects::ForksController do
end
context 'when user is signed in' do
- it 'responds with status 200' do
+ before do
sign_in(user)
+ end
+
+ context 'when JSON requested' do
+ it 'responds with available groups' do
+ get :new,
+ format: :json,
+ params: {
+ namespace_id: project.namespace,
+ project_id: project
+ }
+
+ expect(json_response['namespaces'].length).to eq(1)
+ expect(json_response['namespaces'].first['id']).to eq(group.id)
+ end
+ end
+ it 'responds with status 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
@@ -229,6 +245,7 @@ RSpec.describe Projects::ForksController do
continue: continue_params
}
end
+
let(:continue_params) do
{
to: '/-/ide/project/path',
diff --git a/spec/controllers/projects/hooks_controller_spec.rb b/spec/controllers/projects/hooks_controller_spec.rb
index 440e6b2a74c..85d036486ee 100644
--- a/spec/controllers/projects/hooks_controller_spec.rb
+++ b/spec/controllers/projects/hooks_controller_spec.rb
@@ -36,7 +36,8 @@ RSpec.describe Projects::HooksController do
note_events: true,
job_events: true,
pipeline_events: true,
- wiki_page_events: true
+ wiki_page_events: true,
+ deployment_events: true
}
post :create, params: { namespace_id: project.namespace, project_id: project, hook: hook_params }
diff --git a/spec/controllers/projects/incidents_controller_spec.rb b/spec/controllers/projects/incidents_controller_spec.rb
new file mode 100644
index 00000000000..2baae0661cb
--- /dev/null
+++ b/spec/controllers/projects/incidents_controller_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Projects::IncidentsController do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:developer) { create(:user) }
+ let_it_be(:guest) { create(:user) }
+
+ before_all do
+ project.add_developer(developer)
+ project.add_guest(guest)
+ end
+
+ describe 'GET #index' do
+ def make_request
+ get :index, params: { namespace_id: project.namespace, project_id: project }
+ end
+
+ it 'shows the page for user with developer role' do
+ sign_in(developer)
+ make_request
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:index)
+ end
+
+ context 'when user is unauthorized' do
+ it 'redirects to the login page' do
+ sign_out(developer)
+ make_request
+
+ expect(response).to redirect_to(new_user_session_path)
+ end
+ end
+
+ context 'when user is a guest' do
+ it 'shows 404' do
+ sign_in(guest)
+ make_request
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+end
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index f9580c79390..a0e478ef368 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -181,10 +181,11 @@ RSpec.describe Projects::IssuesController do
project.add_developer(user)
end
- it 'builds a new issue' do
+ it 'builds a new issue', :aggregate_failures do
get :new, params: { namespace_id: project.namespace, project_id: project }
expect(assigns(:issue)).to be_a_new(Issue)
+ expect(assigns(:issue).issue_type).to eq('issue')
end
where(:conf_value, :conf_result) do
@@ -214,6 +215,24 @@ RSpec.describe Projects::IssuesController do
end
end
+ context 'setting issue type' do
+ let(:issue_type) { 'issue' }
+
+ before do
+ get :new, params: { namespace_id: project.namespace, project_id: project, issue: { issue_type: issue_type } }
+ end
+
+ subject { assigns(:issue).issue_type }
+
+ it { is_expected.to eq('issue') }
+
+ context 'incident issue' do
+ let(:issue_type) { 'incident' }
+
+ it { is_expected.to eq(issue_type) }
+ end
+ end
+
it 'fills in an issue for a merge request' do
project_with_repository = create(:project, :repository)
project_with_repository.add_developer(user)
@@ -964,6 +983,33 @@ RSpec.describe Projects::IssuesController do
expect { issue.update(description: [issue.description, labels].join(' ')) }
.not_to exceed_query_limit(control_count + 2 * labels.count)
end
+
+ context 'real-time sidebar feature flag' do
+ using RSpec::Parameterized::TableSyntax
+
+ let_it_be(:project) { create(:project, :public) }
+ let_it_be(:issue) { create(:issue, project: project) }
+
+ where(:action_cable_in_app_enabled, :feature_flag_enabled, :gon_feature_flag) do
+ true | true | true
+ true | false | true
+ false | true | true
+ false | false | false
+ end
+
+ with_them do
+ before do
+ expect(Gitlab::ActionCable::Config).to receive(:in_app?).and_return(action_cable_in_app_enabled)
+ stub_feature_flags(real_time_issue_sidebar: feature_flag_enabled)
+ end
+
+ it 'broadcasts to the issues channel based on ActionCable and feature flag values' do
+ go(id: issue.to_param)
+
+ expect(Gon.features).to include('realTimeIssueSidebar' => gon_feature_flag)
+ end
+ end
+ end
end
describe 'GET #realtime_changes' do
@@ -1022,6 +1068,14 @@ RSpec.describe Projects::IssuesController do
project.issues.first
end
+ it 'creates the issue successfully', :aggregate_failures do
+ issue = post_new_issue
+
+ expect(issue).to be_a(Issue)
+ expect(issue.persisted?).to eq(true)
+ expect(issue.issue_type).to eq('issue')
+ end
+
context 'resolving discussions in MergeRequest' do
let(:discussion) { create(:diff_note_on_merge_request).to_discussion }
let(:merge_request) { discussion.noteable }
@@ -1262,6 +1316,20 @@ RSpec.describe Projects::IssuesController do
end
end
end
+
+ context 'setting issue type' do
+ let(:issue_type) { 'issue' }
+
+ subject { post_new_issue(issue_type: issue_type)&.issue_type }
+
+ it { is_expected.to eq('issue') }
+
+ context 'incident issue' do
+ let(:issue_type) { 'incident' }
+
+ it { is_expected.to eq(issue_type) }
+ end
+ end
end
describe 'POST #mark_as_spam' do
diff --git a/spec/controllers/projects/logs_controller_spec.rb b/spec/controllers/projects/logs_controller_spec.rb
index 0f34e536064..d5c602df41d 100644
--- a/spec/controllers/projects/logs_controller_spec.rb
+++ b/spec/controllers/projects/logs_controller_spec.rb
@@ -22,8 +22,8 @@ RSpec.describe Projects::LogsController do
describe 'GET #index' do
let(:empty_project) { create(:project) }
- it 'returns 404 with developer access' do
- project.add_developer(user)
+ it 'returns 404 with reporter access' do
+ project.add_reporter(user)
get :index, params: environment_params
@@ -31,7 +31,7 @@ RSpec.describe Projects::LogsController do
end
it 'renders empty logs page if no environment exists' do
- empty_project.add_maintainer(user)
+ empty_project.add_developer(user)
get :index, params: { namespace_id: empty_project.namespace, project_id: empty_project }
@@ -40,7 +40,7 @@ RSpec.describe Projects::LogsController do
end
it 'renders index template' do
- project.add_maintainer(user)
+ project.add_developer(user)
get :index, params: environment_params
@@ -59,6 +59,7 @@ RSpec.describe Projects::LogsController do
container_name: container
}
end
+
let(:service_result_json) { Gitlab::Json.parse(service_result.to_json) }
let_it_be(:cluster) { create(:cluster, :provided_by_gcp, environment_scope: '*', projects: [project]) }
@@ -69,14 +70,27 @@ RSpec.describe Projects::LogsController do
end
end
- it 'returns 404 with developer access' do
- project.add_developer(user)
+ it 'returns 404 with reporter access' do
+ project.add_reporter(user)
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:not_found)
end
+ context 'with developer access' do
+ before do
+ project.add_developer(user)
+ end
+
+ it 'returns the service result' do
+ get endpoint, params: environment_params(pod_name: pod_name, format: :json)
+
+ expect(response).to have_gitlab_http_status(:success)
+ expect(json_response).to eq(service_result_json)
+ end
+ end
+
context 'with maintainer access' do
before do
project.add_maintainer(user)
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 4327e0bbb7a..8e1b250cd3c 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -334,7 +334,7 @@ RSpec.describe Projects::MergeRequestsController do
it 'closes MR without errors' do
update_merge_request(state_event: 'close')
- expect(response).to redirect_to([merge_request.target_project.namespace.becomes(Namespace), merge_request.target_project, merge_request])
+ expect(response).to redirect_to([merge_request.target_project, merge_request])
expect(merge_request.reload.closed?).to be_truthy
end
@@ -343,7 +343,7 @@ RSpec.describe Projects::MergeRequestsController do
update_merge_request(title: 'New title')
- expect(response).to redirect_to([merge_request.target_project.namespace.becomes(Namespace), merge_request.target_project, merge_request])
+ expect(response).to redirect_to([merge_request.target_project, merge_request])
expect(merge_request.reload.title).to eq 'New title'
end
diff --git a/spec/controllers/projects/notes_controller_spec.rb b/spec/controllers/projects/notes_controller_spec.rb
index 9728fad417e..570d65dba4f 100644
--- a/spec/controllers/projects/notes_controller_spec.rb
+++ b/spec/controllers/projects/notes_controller_spec.rb
@@ -302,6 +302,7 @@ RSpec.describe Projects::NotesController do
target_id: merge_request.id
}.merge(extra_request_params)
end
+
let(:extra_request_params) { {} }
let(:project_visibility) { Gitlab::VisibilityLevel::PUBLIC }
diff --git a/spec/controllers/projects/pipelines/tests_controller_spec.rb b/spec/controllers/projects/pipelines/tests_controller_spec.rb
index e2abd1238c5..61118487e20 100644
--- a/spec/controllers/projects/pipelines/tests_controller_spec.rb
+++ b/spec/controllers/projects/pipelines/tests_controller_spec.rb
@@ -19,7 +19,7 @@ RSpec.describe Projects::Pipelines::TestsController do
get_tests_summary_json
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(2)
+ expect(json_response.dig('total', 'count')).to eq(2)
end
end
@@ -28,20 +28,7 @@ RSpec.describe Projects::Pipelines::TestsController do
get_tests_summary_json
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(0)
- end
- end
-
- context 'when feature is disabled' do
- before do
- stub_feature_flags(build_report_summary: false)
- end
-
- it 'returns 404' do
- get_tests_summary_json
-
- expect(response).to have_gitlab_http_status(:not_found)
- expect(response.body).to be_empty
+ expect(json_response.dig('total', 'count')).to eq(0)
end
end
end
@@ -71,21 +58,6 @@ RSpec.describe Projects::Pipelines::TestsController do
expect(response.body).to be_empty
end
end
-
- context 'when feature is disabled' do
- let(:suite_name) { 'test' }
-
- before do
- stub_feature_flags(build_report_summary: false)
- end
-
- it 'returns 404' do
- get_tests_show_json([])
-
- expect(response).to have_gitlab_http_status(:not_found)
- expect(response.body).to be_empty
- end
- end
end
def get_tests_summary_json
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index 872f0e97b09..ef560f6426b 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -57,27 +57,6 @@ RSpec.describe Projects::PipelinesController do
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pipelines'].count).to eq 12
end
-
- context 'with build_report_summary turned off' do
- before do
- stub_feature_flags(build_report_summary: false)
- end
-
- it 'does not execute N+1 queries' do
- get_pipelines_index_json
-
- control_count = ActiveRecord::QueryRecorder.new do
- get_pipelines_index_json
- end.count
-
- create_all_pipeline_types
-
- # There appears to be one extra query for Pipelines#has_warnings? for some reason
- expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1)
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['pipelines'].count).to eq 12
- end
- end
end
it 'does not include coverage data for the pipelines' do
@@ -880,113 +859,88 @@ RSpec.describe Projects::PipelinesController do
end
end
- context 'when feature is enabled' do
- before do
- stub_feature_flags(junit_pipeline_view: project)
- end
-
- context 'when pipeline does not have a test report' do
- it 'renders an empty test report' do
- get_test_report_json
+ context 'when pipeline does not have a test report' do
+ it 'renders an empty test report' do
+ get_test_report_json
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(0)
- end
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['total_count']).to eq(0)
end
+ end
- context 'when pipeline has a test report' do
- before do
- create(:ci_build, name: 'rspec', pipeline: pipeline).tap do |build|
- create(:ci_job_artifact, :junit, job: build)
- end
- end
-
- it 'renders the test report' do
- get_test_report_json
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(4)
- end
+ context 'when pipeline has a test report' do
+ before do
+ create(:ci_build, :test_reports, name: 'rspec', pipeline: pipeline)
end
- context 'when pipeline has a corrupt test report artifact' do
- before do
- create(:ci_build, name: 'rspec', pipeline: pipeline).tap do |build|
- create(:ci_job_artifact, :junit_with_corrupted_data, job: build)
- end
+ it 'renders the test report' do
+ get_test_report_json
- get_test_report_json
- end
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['total_count']).to eq(4)
+ end
+ end
- it 'renders the test reports' do
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['test_suites'].count).to eq(1)
- end
+ context 'when pipeline has a corrupt test report artifact' do
+ before do
+ create(:ci_build, :broken_test_reports, name: 'rspec', pipeline: pipeline)
- it 'returns a suite_error on the suite with corrupted XML' do
- expect(json_response['test_suites'].first['suite_error']).to eq('JUnit XML parsing failed: 1:1: FATAL: Document is empty')
- end
+ get_test_report_json
end
- context 'when junit_pipeline_screenshots_view is enabled' do
- before do
- stub_feature_flags(junit_pipeline_screenshots_view: project)
- end
-
- context 'when test_report contains attachment and scope is with_attachment as a URL param' do
- let(:pipeline) { create(:ci_pipeline, :with_test_reports_attachment, project: project) }
+ it 'renders the test reports' do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['test_suites'].count).to eq(1)
+ end
- it 'returns a test reports with attachment' do
- get_test_report_json(scope: 'with_attachment')
+ it 'returns a suite_error on the suite with corrupted XML' do
+ expect(json_response['test_suites'].first['suite_error']).to eq('JUnit XML parsing failed: 1:1: FATAL: Document is empty')
+ end
+ end
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response["test_suites"]).to be_present
- expect(json_response["test_suites"].first["test_cases"].first).to include("attachment_url")
- end
- end
+ context 'when junit_pipeline_screenshots_view is enabled' do
+ before do
+ stub_feature_flags(junit_pipeline_screenshots_view: project)
+ end
- context 'when test_report does not contain attachment and scope is with_attachment as a URL param' do
- let(:pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
+ context 'when test_report contains attachment and scope is with_attachment as a URL param' do
+ let(:pipeline) { create(:ci_pipeline, :with_test_reports_attachment, project: project) }
- it 'returns a test reports with empty values' do
- get_test_report_json(scope: 'with_attachment')
+ it 'returns a test reports with attachment' do
+ get_test_report_json(scope: 'with_attachment')
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response["test_suites"]).to be_empty
- end
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["test_suites"]).to be_present
+ expect(json_response["test_suites"].first["test_cases"].first).to include("attachment_url")
end
end
- context 'when junit_pipeline_screenshots_view is disabled' do
- before do
- stub_feature_flags(junit_pipeline_screenshots_view: false)
- end
-
- context 'when test_report contains attachment and scope is with_attachment as a URL param' do
- let(:pipeline) { create(:ci_pipeline, :with_test_reports_attachment, project: project) }
+ context 'when test_report does not contain attachment and scope is with_attachment as a URL param' do
+ let(:pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
- it 'returns a test reports without attachment_url' do
- get_test_report_json(scope: 'with_attachment')
+ it 'returns a test reports with empty values' do
+ get_test_report_json(scope: 'with_attachment')
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response["test_suites"].first["test_cases"].first).not_to include("attachment_url")
- end
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["test_suites"]).to be_empty
end
end
end
- context 'when feature is disabled' do
- let(:pipeline) { create(:ci_empty_pipeline, project: project) }
-
+ context 'when junit_pipeline_screenshots_view is disabled' do
before do
- stub_feature_flags(junit_pipeline_view: false)
+ stub_feature_flags(junit_pipeline_screenshots_view: false)
end
- it 'renders empty response' do
- get_test_report_json
+ context 'when test_report contains attachment and scope is with_attachment as a URL param' do
+ let(:pipeline) { create(:ci_pipeline, :with_test_reports_attachment, project: project) }
+
+ it 'returns a test reports without attachment_url' do
+ get_test_report_json(scope: 'with_attachment')
- expect(response).to have_gitlab_http_status(:no_content)
- expect(response.body).to be_empty
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response["test_suites"].first["test_cases"].first).not_to include("attachment_url")
+ end
end
end
@@ -1010,76 +964,6 @@ RSpec.describe Projects::PipelinesController do
end
end
- describe 'GET test_report_count.json' do
- subject(:test_reports_count_json) do
- get :test_reports_count, params: {
- namespace_id: project.namespace,
- project_id: project,
- id: pipeline.id
- },
- format: :json
- end
-
- context 'when feature is enabled' do
- before do
- stub_feature_flags(junit_pipeline_view: true)
- end
-
- context 'when pipeline does not have a test report' do
- let(:pipeline) { create(:ci_pipeline, project: project) }
-
- it 'renders an empty badge counter' do
- test_reports_count_json
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(0)
- end
- end
-
- context 'when pipeline has a test report' do
- let(:pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
-
- it 'renders the badge counter value' do
- test_reports_count_json
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(4)
- end
- end
-
- context 'when pipeline has corrupt test reports' do
- let(:pipeline) { create(:ci_pipeline, project: project) }
-
- before do
- job = create(:ci_build, pipeline: pipeline)
- create(:ci_job_artifact, :junit_with_corrupted_data, job: job, project: project)
- end
-
- it 'renders 0' do
- test_reports_count_json
-
- expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['total_count']).to eq(0)
- end
- end
- end
-
- context 'when feature is disabled' do
- let(:pipeline) { create(:ci_empty_pipeline, project: project) }
-
- before do
- stub_feature_flags(junit_pipeline_view: false)
- end
-
- it 'renders empty response' do
- test_reports_count_json
-
- expect(response).to have_gitlab_http_status(:no_content)
- expect(response.body).to be_empty
- end
- end
- end
-
describe 'GET latest' do
let(:branch_main) { project.repository.branches[0] }
let(:branch_secondary) { project.repository.branches[1] }
diff --git a/spec/controllers/projects/product_analytics_controller_spec.rb b/spec/controllers/projects/product_analytics_controller_spec.rb
new file mode 100644
index 00000000000..47f1d96c70b
--- /dev/null
+++ b/spec/controllers/projects/product_analytics_controller_spec.rb
@@ -0,0 +1,95 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Projects::ProductAnalyticsController do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+
+ before(:all) do
+ project.add_maintainer(user)
+ end
+
+ before do
+ sign_in(user)
+ stub_feature_flags(product_analytics: true)
+ end
+
+ describe 'GET #index' do
+ it 'renders index with 200 status code' do
+ get :index, params: project_params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:index)
+ end
+
+ context 'with an anonymous user' do
+ before do
+ sign_out(user)
+ end
+
+ it 'redirects to sign-in page' do
+ get :index, params: project_params
+
+ expect(response).to redirect_to(new_user_session_path)
+ end
+ end
+
+ context 'feature flag disabled' do
+ before do
+ stub_feature_flags(product_analytics: false)
+ end
+
+ it 'returns not found' do
+ get :index, params: project_params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+
+ describe 'GET #test' do
+ it 'renders test with 200 status code' do
+ get :test, params: project_params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:test)
+ end
+ end
+
+ describe 'GET #setup' do
+ it 'renders setup with 200 status code' do
+ get :setup, params: project_params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:setup)
+ end
+ end
+
+ describe 'GET #graphs' do
+ it 'renders graphs with 200 status code' do
+ get :graphs, params: project_params
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to render_template(:graphs)
+ end
+
+ context 'feature flag disabled' do
+ before do
+ stub_feature_flags(product_analytics: false)
+ end
+
+ it 'returns not found' do
+ get :graphs, params: project_params
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+ end
+
+ private
+
+ def project_params(opts = {})
+ opts.reverse_merge(namespace_id: project.namespace, project_id: project)
+ end
+end
diff --git a/spec/controllers/projects/prometheus/alerts_controller_spec.rb b/spec/controllers/projects/prometheus/alerts_controller_spec.rb
index 6e3148231bd..cbd599506df 100644
--- a/spec/controllers/projects/prometheus/alerts_controller_spec.rb
+++ b/spec/controllers/projects/prometheus/alerts_controller_spec.rb
@@ -111,6 +111,7 @@ RSpec.describe Projects::Prometheus::AlertsController do
describe 'GET #show' do
let(:alert) do
create(:prometheus_alert,
+ :with_runbook_url,
project: project,
environment: environment,
prometheus_metric: metric)
@@ -140,6 +141,7 @@ RSpec.describe Projects::Prometheus::AlertsController do
'query' => alert.query,
'operator' => alert.computed_operator,
'threshold' => alert.threshold,
+ 'runbook_url' => alert.runbook_url,
'alert_path' => alert_path(alert)
}
end
@@ -225,7 +227,8 @@ RSpec.describe Projects::Prometheus::AlertsController do
'title' => metric.title,
'query' => metric.query,
'operator' => '>',
- 'threshold' => 1.0
+ 'threshold' => 1.0,
+ 'runbook_url' => 'https://sample.runbook.com'
}
end
@@ -234,6 +237,7 @@ RSpec.describe Projects::Prometheus::AlertsController do
opts,
operator: '>',
threshold: '1',
+ runbook_url: 'https://sample.runbook.com',
environment_id: environment,
prometheus_metric_id: metric
)
@@ -250,14 +254,14 @@ RSpec.describe Projects::Prometheus::AlertsController do
expect(json_response).to include(alert_params)
end
- it 'returns no_content for an invalid metric' do
+ it 'returns bad_request for an invalid metric' do
make_request(prometheus_metric_id: 'invalid')
- expect(response).to have_gitlab_http_status(:no_content)
+ expect(response).to have_gitlab_http_status(:bad_request)
end
it_behaves_like 'unprivileged'
- it_behaves_like 'project non-specific environment', :no_content
+ it_behaves_like 'project non-specific environment', :bad_request
end
describe 'PUT #update' do
@@ -304,6 +308,12 @@ RSpec.describe Projects::Prometheus::AlertsController do
expect(json_response).to include(alert_params)
end
+ it 'returns bad_request for an invalid alert data' do
+ make_request(runbook_url: 'bad-url')
+
+ expect(response).to have_gitlab_http_status(:bad_request)
+ end
+
it_behaves_like 'unprivileged'
it_behaves_like 'project non-specific environment', :not_found
it_behaves_like 'project non-specific metric', :not_found
diff --git a/spec/controllers/projects/protected_branches_controller_spec.rb b/spec/controllers/projects/protected_branches_controller_spec.rb
index 09eb1a45c73..a0cb5c1473a 100644
--- a/spec/controllers/projects/protected_branches_controller_spec.rb
+++ b/spec/controllers/projects/protected_branches_controller_spec.rb
@@ -27,6 +27,7 @@ RSpec.describe Projects::ProtectedBranchesController do
{ merge_access_levels_attributes: maintainer_access_level,
push_access_levels_attributes: maintainer_access_level }
end
+
let(:create_params) { attributes_for(:protected_branch).merge(access_level_params) }
before do
diff --git a/spec/controllers/projects/serverless/functions_controller_spec.rb b/spec/controllers/projects/serverless/functions_controller_spec.rb
index 3071d0b7f54..7f558ad9231 100644
--- a/spec/controllers/projects/serverless/functions_controller_spec.rb
+++ b/spec/controllers/projects/serverless/functions_controller_spec.rb
@@ -18,6 +18,7 @@ RSpec.describe Projects::Serverless::FunctionsController do
let(:knative_stub_options) do
{ namespace: namespace.namespace, name: function_name, description: function_description }
end
+
let(:knative) { create(:clusters_applications_knative, :installed, cluster: cluster) }
let(:namespace) do
diff --git a/spec/controllers/projects/services_controller_spec.rb b/spec/controllers/projects/services_controller_spec.rb
index e8a23dcfafb..50f474c0222 100644
--- a/spec/controllers/projects/services_controller_spec.rb
+++ b/spec/controllers/projects/services_controller_spec.rb
@@ -82,7 +82,7 @@ RSpec.describe Projects::ServicesController do
'active' => '1',
'push_events' => '1',
'token' => 'token',
- 'project_url' => 'http://test.com'
+ 'project_url' => 'https://buildkite.com/organization/pipeline'
}
end
diff --git a/spec/controllers/projects/settings/operations_controller_spec.rb b/spec/controllers/projects/settings/operations_controller_spec.rb
index d4f3c5d0c9b..191b718af56 100644
--- a/spec/controllers/projects/settings/operations_controller_spec.rb
+++ b/spec/controllers/projects/settings/operations_controller_spec.rb
@@ -206,7 +206,7 @@ RSpec.describe Projects::Settings::OperationsController do
reset_pagerduty_token
new_token = incident_management_setting.reload.pagerduty_token
- new_webhook_url = project_incidents_pagerduty_url(project, token: new_token)
+ new_webhook_url = project_incidents_integrations_pagerduty_url(project, token: new_token)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pagerduty_webhook_url']).to eq(new_webhook_url)
@@ -219,7 +219,7 @@ RSpec.describe Projects::Settings::OperationsController do
it 'does not reset a token' do
reset_pagerduty_token
- new_webhook_url = project_incidents_pagerduty_url(project, token: nil)
+ new_webhook_url = project_incidents_integrations_pagerduty_url(project, token: nil)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pagerduty_webhook_url']).to eq(new_webhook_url)
diff --git a/spec/controllers/projects/settings/repository_controller_spec.rb b/spec/controllers/projects/settings/repository_controller_spec.rb
index 46dba691bc4..d93f23ae142 100644
--- a/spec/controllers/projects/settings/repository_controller_spec.rb
+++ b/spec/controllers/projects/settings/repository_controller_spec.rb
@@ -56,6 +56,7 @@ RSpec.describe Projects::Settings::RepositoryController do
deploy_token_type: DeployToken.deploy_token_types[:project_type]
}
end
+
let(:request_params) do
{
namespace_id: project.namespace.to_param,
@@ -77,7 +78,7 @@ RSpec.describe Projects::Settings::RepositoryController do
'token' => be_a(String),
'scopes' => deploy_token_params.inject([]) do |scopes, kv|
key, value = kv
- key.to_s.start_with?('read_') && !value.to_i.zero? ? scopes << key.to_s : scopes
+ key.to_s.start_with?('read_') && value.to_i != 0 ? scopes << key.to_s : scopes
end
}
end
diff --git a/spec/controllers/projects/snippets_controller_spec.rb b/spec/controllers/projects/snippets_controller_spec.rb
index 6fcb24da3cd..bb9b556f442 100644
--- a/spec/controllers/projects/snippets_controller_spec.rb
+++ b/spec/controllers/projects/snippets_controller_spec.rb
@@ -416,12 +416,13 @@ RSpec.describe Projects::SnippetsController do
describe "GET #show for embeddable content" do
let(:project_snippet) { create(:project_snippet, :repository, snippet_permission, project: project, author: user) }
+ let(:extra_params) { {} }
before do
sign_in(user)
end
- subject { get :show, params: { namespace_id: project.namespace, project_id: project, id: project_snippet.to_param }, format: :js }
+ subject { get :show, params: { namespace_id: project.namespace, project_id: project, id: project_snippet.to_param, **extra_params }, format: :js }
context 'when snippet is private' do
let(:snippet_permission) { :private }
@@ -436,7 +437,29 @@ RSpec.describe Projects::SnippetsController do
context 'when snippet is public' do
let(:snippet_permission) { :public }
- it_behaves_like 'successful response'
+ it 'renders the blob from the repository' do
+ subject
+
+ expect(assigns(:snippet)).to eq(project_snippet)
+ expect(assigns(:blobs)).to eq(project_snippet.blobs)
+ expect(response).to have_gitlab_http_status(:ok)
+ end
+
+ it 'does not show the blobs expanded by default' do
+ subject
+
+ expect(project_snippet.blobs.map(&:expanded?)).to be_all(false)
+ end
+
+ context 'when param expanded is set' do
+ let(:extra_params) { { expanded: true } }
+
+ it 'shows all blobs expanded' do
+ subject
+
+ expect(project_snippet.blobs.map(&:expanded?)).to be_all(true)
+ end
+ end
end
context 'when the project is private' do
diff --git a/spec/controllers/projects/tags_controller_spec.rb b/spec/controllers/projects/tags_controller_spec.rb
index 122d1b072d0..d213d003bed 100644
--- a/spec/controllers/projects/tags_controller_spec.rb
+++ b/spec/controllers/projects/tags_controller_spec.rb
@@ -120,10 +120,14 @@ RSpec.describe Projects::TagsController do
request
- release = project.releases.find_by_tag!('1.0')
+ aggregate_failures do
+ expect(response).to have_gitlab_http_status(:found)
- expect(release).to be_present
- expect(release.description).to eq(release_description)
+ release = project.releases.find_by_tag('1.0')
+
+ expect(release).to be_present
+ expect(release&.description).to eq(release_description)
+ end
end
end
end
diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb
index 8bb4c2dae4b..768d2ec00bd 100644
--- a/spec/controllers/projects/variables_controller_spec.rb
+++ b/spec/controllers/projects/variables_controller_spec.rb
@@ -47,6 +47,7 @@ RSpec.describe Projects::VariablesController do
protected: variable.protected?.to_s,
environment_scope: variable.environment_scope }
end
+
let(:new_variable_attributes) do
{ key: 'new_key',
secret_value: 'dummy_value',