Commit 89a9b3a9 authored by lauraMon's avatar lauraMon

Redirects if scope is not valid

parent 16c547a6
...@@ -19,6 +19,8 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -19,6 +19,8 @@ class Projects::PipelinesController < Projects::ApplicationController
end end
before_action :ensure_pipeline, only: [:show] before_action :ensure_pipeline, only: [:show]
before_action :ensure_valid_scope, only: [:index]
around_action :allow_gitaly_ref_name_caching, only: [:index, :show] around_action :allow_gitaly_ref_name_caching, only: [:index, :show]
track_unique_visits :charts, target_id: 'p_analytics_pipelines' track_unique_visits :charts, target_id: 'p_analytics_pipelines'
...@@ -44,7 +46,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -44,7 +46,7 @@ class Projects::PipelinesController < Projects::ApplicationController
render json: { render json: {
pipelines: serialize_pipelines, pipelines: serialize_pipelines,
count: { count: {
all: @pipelines_count, all: @pipelines_count
} }
} }
end end
...@@ -223,6 +225,10 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -223,6 +225,10 @@ class Projects::PipelinesController < Projects::ApplicationController
render_404 unless pipeline render_404 unless pipeline
end end
def ensure_valid_scope
redirect_to project_pipelines_path(project, status: params[:scope]) if %w[running pending].include?(params[:scope])
end
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def pipeline def pipeline
@pipeline ||= if params[:id].blank? && params[:latest] @pipeline ||= if params[:id].blank? && params[:latest]
......
...@@ -119,6 +119,14 @@ RSpec.describe Projects::PipelinesController do ...@@ -119,6 +119,14 @@ RSpec.describe Projects::PipelinesController do
end end
end end
context 'when scope is pending or running' do
it 'redirects to all pipelines with that status instead' do
get_pipelines_index_json(scope: 'running')
expect(response).to redirect_to(project_pipelines_path(project, status: 'running'))
end
end
context 'filter by scope' do context 'filter by scope' do
context 'scope is branches or tags' do context 'scope is branches or tags' do
before do before do
...@@ -192,14 +200,6 @@ RSpec.describe Projects::PipelinesController do ...@@ -192,14 +200,6 @@ RSpec.describe Projects::PipelinesController do
check_pipeline_response(returned: 1, all: 1) check_pipeline_response(returned: 1, all: 1)
end 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)
end
end
end end
context 'when no pipeline with the status exists' do context 'when no pipeline with the status exists' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment