Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/controllers/projects/pipelines_controller_spec.rb')
-rw-r--r--spec/controllers/projects/pipelines_controller_spec.rb95
1 files changed, 62 insertions, 33 deletions
diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb
index ca09d2b1428..872f0e97b09 100644
--- a/spec/controllers/projects/pipelines_controller_spec.rb
+++ b/spec/controllers/projects/pipelines_controller_spec.rb
@@ -37,16 +37,13 @@ RSpec.describe Projects::PipelinesController do
expect(json_response).to include('pipelines')
expect(json_response['pipelines'].count).to eq 6
expect(json_response['count']['all']).to eq '6'
- expect(json_response['count']['running']).to eq '2'
- expect(json_response['count']['pending']).to eq '1'
- expect(json_response['count']['finished']).to eq '3'
json_response.dig('pipelines', 0, 'details', 'stages').tap do |stages|
expect(stages.count).to eq 3
end
end
- it 'does not execute N+1 queries' do
+ it 'executes N+1 queries' do
get_pipelines_index_json
control_count = ActiveRecord::QueryRecorder.new do
@@ -56,10 +53,31 @@ RSpec.describe Projects::PipelinesController do
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 { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 7)
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
@@ -77,9 +95,9 @@ RSpec.describe Projects::PipelinesController do
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
- # ListCommitsByOid, RepositoryExists, HasLocalBranches
+ # ListCommitsByOid, RepositoryExists, HasLocalBranches, ListCommitsByRefNames
expect { get_pipelines_index_json }
- .to change { Gitlab::GitalyClient.get_request_count }.by(3)
+ .to change { Gitlab::GitalyClient.get_request_count }.by(4)
end
end
@@ -101,23 +119,27 @@ RSpec.describe Projects::PipelinesController do
end
end
- context 'filter by scope' do
- it 'returns matched pipelines' do
- get_pipelines_index_json(scope: 'running')
+ context 'when user tries to access legacy scope via URL' do
+ it 'redirects to all pipelines with that status instead' do
+ get_pipelines_index_html(scope: 'running')
- check_pipeline_response(returned: 2, all: 6, running: 2, pending: 1, finished: 3)
+ expect(response).to redirect_to(project_pipelines_path(project, status: 'running', format: :html))
end
+ end
+ context 'filter by scope' do
context 'scope is branches or tags' do
before do
create(:ci_pipeline, :failed, project: project, ref: 'v1.0.0', tag: true)
+ create(:ci_pipeline, :failed, project: project, ref: 'master', tag: false)
+ create(:ci_pipeline, :failed, project: project, ref: 'feature', tag: false)
end
context 'when scope is branches' do
it 'returns matched pipelines' do
get_pipelines_index_json(scope: 'branches')
- check_pipeline_response(returned: 1, all: 7, running: 2, pending: 1, finished: 4)
+ check_pipeline_response(returned: 2, all: 9)
end
end
@@ -125,7 +147,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns matched pipelines' do
get_pipelines_index_json(scope: 'tags')
- check_pipeline_response(returned: 1, all: 7, running: 2, pending: 1, finished: 4)
+ check_pipeline_response(returned: 1, all: 9)
end
end
end
@@ -138,7 +160,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns matched pipelines' do
get_pipelines_index_json(username: user.username)
- check_pipeline_response(returned: 1, all: 1, running: 1, pending: 0, finished: 0)
+ check_pipeline_response(returned: 1, all: 1)
end
end
@@ -146,7 +168,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns empty' do
get_pipelines_index_json(username: 'invalid-username')
- check_pipeline_response(returned: 0, all: 0, running: 0, pending: 0, finished: 0)
+ check_pipeline_response(returned: 0, all: 0)
end
end
end
@@ -158,7 +180,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns matched pipelines' do
get_pipelines_index_json(ref: 'branch-1')
- check_pipeline_response(returned: 1, all: 1, running: 1, pending: 0, finished: 0)
+ check_pipeline_response(returned: 1, all: 1)
end
end
@@ -166,7 +188,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns empty list' do
get_pipelines_index_json(ref: 'invalid-ref')
- check_pipeline_response(returned: 0, all: 0, running: 0, pending: 0, finished: 0)
+ check_pipeline_response(returned: 0, all: 0)
end
end
end
@@ -176,15 +198,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns matched pipelines' do
get_pipelines_index_json(status: 'success')
- check_pipeline_response(returned: 1, all: 1, running: 0, pending: 0, finished: 1)
- end
-
- context 'when filter by unrelated scope' do
- it 'returns empty list' do
- get_pipelines_index_json(status: 'success', scope: 'running')
-
- check_pipeline_response(returned: 0, all: 1, running: 0, pending: 0, finished: 1)
- end
+ check_pipeline_response(returned: 1, all: 1)
end
end
@@ -192,7 +206,7 @@ RSpec.describe Projects::PipelinesController do
it 'returns empty list' do
get_pipelines_index_json(status: 'manual')
- check_pipeline_response(returned: 0, all: 0, running: 0, pending: 0, finished: 0)
+ check_pipeline_response(returned: 0, all: 0)
end
end
@@ -200,11 +214,19 @@ RSpec.describe Projects::PipelinesController do
it 'returns all list' do
get_pipelines_index_json(status: 'invalid-status')
- check_pipeline_response(returned: 6, all: 6, running: 2, pending: 1, finished: 3)
+ check_pipeline_response(returned: 6, all: 6)
end
end
end
+ def get_pipelines_index_html(params = {})
+ get :index, params: {
+ namespace_id: project.namespace,
+ project_id: project
+ }.merge(params),
+ format: :html
+ end
+
def get_pipelines_index_json(params = {})
get :index, params: {
namespace_id: project.namespace,
@@ -234,7 +256,8 @@ RSpec.describe Projects::PipelinesController do
user = create(:user)
pipeline = create(:ci_empty_pipeline, status: status,
project: project,
- sha: sha,
+ sha: sha.id,
+ ref: sha.id.first(8),
user: user,
merge_request: merge_request)
@@ -260,15 +283,12 @@ RSpec.describe Projects::PipelinesController do
)
end
- def check_pipeline_response(returned:, all:, running:, pending:, finished:)
+ def check_pipeline_response(returned:, all:)
aggregate_failures do
expect(response).to match_response_schema('pipeline')
expect(json_response['pipelines'].count).to eq returned
expect(json_response['count']['all'].to_i).to eq all
- expect(json_response['count']['running'].to_i).to eq running
- expect(json_response['count']['pending'].to_i).to eq pending
- expect(json_response['count']['finished'].to_i).to eq finished
end
end
end
@@ -689,6 +709,15 @@ RSpec.describe Projects::PipelinesController do
end
end
+ describe 'GET #charts' do
+ let(:pipeline) { create(:ci_pipeline, project: project) }
+
+ it_behaves_like 'tracking unique visits', :charts do
+ let(:request_params) { { namespace_id: project.namespace, project_id: project, id: pipeline.id } }
+ let(:target_id) { 'p_analytics_pipelines' }
+ end
+ end
+
describe 'POST create' do
let(:project) { create(:project, :public, :repository) }