BigW Consortium Gitlab

Commit 0a36bfa9 by Shinya Maeda

Use HasStatus::AVAILABLE_STATUSES instead of hard coding

parent 4bd0d8e4
......@@ -54,22 +54,9 @@ class PipelinesFinder
end
def by_status(items)
case params[:status]
when 'running'
items.running
when 'pending'
items.pending
when 'success'
items.success
when 'failed'
items.failed
when 'canceled'
items.canceled
when 'skipped'
items.skipped
else
items
end
return items unless HasStatus::AVAILABLE_STATUSES.include?(params[:status])
items.where(status: params[:status])
end
def by_ref(items)
......
......@@ -16,7 +16,7 @@ module API
use :pagination
optional :scope, type: String, values: %w[running pending finished branches tags],
desc: 'The scope of pipelines'
optional :status, type: String, values: %w[running pending success failed canceled skipped],
optional :status, type: String, values: HasStatus::AVAILABLE_STATUSES,
desc: 'The status of pipelines'
optional :ref, type: String, desc: 'The ref of pipelines'
optional :yaml_errors, type: Boolean, desc: 'If true, returns only yaml error pipelines'
......
......@@ -60,13 +60,13 @@ describe PipelinesFinder do
end
end
%w[running pending success failed canceled skipped].each do |target|
HasStatus::AVAILABLE_STATUSES.each do |target|
context "when status is #{target}" do
let(:params) { { status: target } }
let!(:pipeline) { create(:ci_pipeline, project: project, status: target) }
before do
exception_status = %w[running pending success failed canceled skipped] - [target]
exception_status = HasStatus::AVAILABLE_STATUSES - [target]
create(:ci_pipeline, project: project, status: exception_status.sample)
end
......
......@@ -95,11 +95,11 @@ describe API::Pipelines do
end
end
%w[running pending success failed canceled skipped].each do |target|
HasStatus::AVAILABLE_STATUSES.each do |target|
context "when status is #{target}" do
before do
create(:ci_pipeline, project: project, status: target)
exception_status = %w[running pending success failed canceled skipped] - [target]
exception_status = HasStatus::AVAILABLE_STATUSES - [target]
create(:ci_pipeline, project: project, status: exception_status.sample)
end
......
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