2016-08-29 12:02:08 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PipelinesFinder do
|
2017-03-07 12:44:38 -05:00
|
|
|
let(:user1) { create(:user) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:ci_pipeline, project: project, user: user1, ref: 'v1.0.0', tag: true)
|
|
|
|
create(:ci_pipeline, project: project, user: user1, status: 'created')
|
|
|
|
create(:ci_pipeline, project: project, user: user1, status: 'pending')
|
|
|
|
create(:ci_pipeline, project: project, user: user1, status: 'running')
|
|
|
|
create(:ci_pipeline, project: project, user: user1, status: 'success')
|
|
|
|
create(:ci_pipeline, project: project, user: user2, status: 'failed')
|
|
|
|
create(:ci_pipeline, project: project, user: user2, status: 'canceled')
|
|
|
|
create(:ci_pipeline, project: project, user: user2, status: 'skipped')
|
|
|
|
create(:ci_pipeline, project: project, user: user2, yaml_errors: 'Syntax error')
|
2017-03-02 03:43:37 -05:00
|
|
|
end
|
2016-08-29 12:02:08 -04:00
|
|
|
|
2017-02-28 12:34:48 -05:00
|
|
|
subject { described_class.new(project, params).execute }
|
2016-08-29 12:02:08 -04:00
|
|
|
|
|
|
|
describe "#execute" do
|
2017-02-28 12:34:48 -05:00
|
|
|
context 'when nothing is passed' do
|
|
|
|
let(:params) { {} }
|
|
|
|
|
|
|
|
it 'selects all pipelines' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.all)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'orders in descending order on ID' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.order(id: :desc))
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-29 12:02:08 -04:00
|
|
|
context 'when a scope is passed' do
|
2017-02-28 12:34:48 -05:00
|
|
|
context 'when selecting running' do
|
|
|
|
let(:params) { { scope: 'running' } }
|
|
|
|
|
|
|
|
it 'has only running status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.running)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting pending' do
|
|
|
|
let(:params) { { scope: 'pending' } }
|
|
|
|
|
|
|
|
it 'has only pending status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.pending)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting finished' do
|
|
|
|
let(:params) { { scope: 'finished' } }
|
2016-08-29 12:02:08 -04:00
|
|
|
|
2017-02-28 12:34:48 -05:00
|
|
|
it 'has only finished status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.finished)
|
2016-08-29 12:02:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting branches' do
|
|
|
|
let(:params) { { scope: 'branches' } }
|
|
|
|
|
|
|
|
it 'excludes tags' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to eq([Ci::Pipeline.where(tag: false).last])
|
2016-08-29 12:02:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting tags' do
|
|
|
|
let(:params) { { scope: 'tags' } }
|
|
|
|
|
|
|
|
it 'excludes branches' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to eq([Ci::Pipeline.where(tag: true).last])
|
2016-08-29 12:02:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-28 12:34:48 -05:00
|
|
|
context 'when a status is passed' do
|
|
|
|
context 'when selecting running' do
|
2017-03-07 08:19:15 -05:00
|
|
|
let(:params) { { status: 'running' } }
|
2017-02-28 12:34:48 -05:00
|
|
|
|
|
|
|
it 'has only running status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.running)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting pending' do
|
2017-03-07 08:19:15 -05:00
|
|
|
let(:params) { { status: 'pending' } }
|
2017-02-28 12:34:48 -05:00
|
|
|
|
|
|
|
it 'has only pending status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.pending)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting success' do
|
2017-03-07 08:19:15 -05:00
|
|
|
let(:params) { { status: 'success' } }
|
2017-02-28 12:34:48 -05:00
|
|
|
|
|
|
|
it 'has only success status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.success)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting failed' do
|
2017-03-07 08:19:15 -05:00
|
|
|
let(:params) { { status: 'failed' } }
|
2017-02-28 12:34:48 -05:00
|
|
|
|
|
|
|
it 'has only failed status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.failed)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when selecting canceled' do
|
2017-03-07 08:19:15 -05:00
|
|
|
let(:params) { { status: 'canceled' } }
|
2016-08-29 12:02:08 -04:00
|
|
|
|
2017-02-28 12:34:48 -05:00
|
|
|
it 'has only canceled status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.canceled)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-29 12:02:08 -04:00
|
|
|
|
2017-02-28 12:34:48 -05:00
|
|
|
context 'when selecting skipped' do
|
2017-03-07 08:19:15 -05:00
|
|
|
let(:params) { { status: 'skipped' } }
|
2017-02-28 12:34:48 -05:00
|
|
|
|
|
|
|
it 'has only skipped status' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.skipped)
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a ref is passed' do
|
|
|
|
context 'when a ref exists' do
|
|
|
|
let(:params) { { ref: 'master' } }
|
|
|
|
|
|
|
|
it 'selects all pipelines which belong to the ref' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.where(ref: 'master'))
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a ref does not exist' do
|
|
|
|
let(:params) { { ref: 'unique-ref' } }
|
|
|
|
|
|
|
|
it 'selects nothing' do
|
|
|
|
expect(subject).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a username is passed' do
|
|
|
|
context 'when a username exists' do
|
2017-03-02 04:41:27 -05:00
|
|
|
let(:params) { { username: user1.name } }
|
2017-02-28 12:34:48 -05:00
|
|
|
|
|
|
|
it 'selects all pipelines which belong to the username' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.where(user: user1))
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a username does not exist' do
|
|
|
|
let(:params) { { username: 'unique-username' } }
|
|
|
|
|
|
|
|
it 'selects nothing' do
|
|
|
|
expect(subject).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a yaml_errors is passed' do
|
|
|
|
context 'when yaml_errors is true' do
|
|
|
|
let(:params) { { yaml_errors: true } }
|
|
|
|
|
2017-03-02 04:41:27 -05:00
|
|
|
it 'selects only pipelines have yaml_errors' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.where("yaml_errors IS NOT NULL"))
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when yaml_errors is false' do
|
|
|
|
let(:params) { { yaml_errors: false } }
|
|
|
|
|
2017-03-02 04:41:27 -05:00
|
|
|
it 'selects only pipelines do not have yaml_errors' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.where("yaml_errors IS NULL"))
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
2017-03-02 03:43:37 -05:00
|
|
|
|
|
|
|
context 'when an argument is invalid' do
|
|
|
|
let(:params) { { yaml_errors: "UnexpectedValue" } }
|
|
|
|
|
|
|
|
it 'selects all pipelines' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.all)
|
2017-03-02 03:43:37 -05:00
|
|
|
end
|
|
|
|
end
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a order_by and sort are passed' do
|
2017-03-01 01:58:06 -05:00
|
|
|
context 'when order by created_at asc' do
|
2017-02-28 12:34:48 -05:00
|
|
|
let(:params) { { order_by: 'created_at', sort: 'asc' } }
|
|
|
|
|
2017-03-01 01:58:06 -05:00
|
|
|
it 'sorts by created_at asc' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.order(created_at: :asc))
|
2017-03-01 01:58:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when order by created_at desc' do
|
|
|
|
let(:params) { { order_by: 'created_at', sort: 'desc' } }
|
|
|
|
|
|
|
|
it 'sorts by created_at desc' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.order(created_at: :desc))
|
2017-02-28 12:34:48 -05:00
|
|
|
end
|
|
|
|
end
|
2017-03-02 03:43:37 -05:00
|
|
|
|
|
|
|
context 'when order_by does not exist' do
|
|
|
|
let(:params) { { order_by: 'abnormal_column', sort: 'desc' } }
|
|
|
|
|
|
|
|
it 'sorts by default' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.order(id: :desc))
|
2017-03-02 03:43:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sort does not exist' do
|
|
|
|
let(:params) { { order_by: 'created_at', sort: 'abnormal_sort' } }
|
|
|
|
|
|
|
|
it 'sorts by default' do
|
2017-03-07 12:44:38 -05:00
|
|
|
expect(subject).to match_array(Ci::Pipeline.order(id: :desc))
|
2017-03-02 03:43:37 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-29 12:02:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|