Use HasStatus::AVAILABLE_STATUSES instead of hard coding

This commit is contained in:
Shinya Maeda 2017-03-30 18:59:45 +09:00
parent 4bd0d8e433
commit 0a36bfa994
4 changed files with 8 additions and 21 deletions

View File

@ -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)

View File

@ -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'

View File

@ -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

View File

@ -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