2016-08-29 16:02:08 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PipelinesFinder do
|
2017-03-07 17:44:38 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
2017-02-28 17:34:48 +00:00
|
|
|
subject { described_class.new(project, params).execute }
|
2016-08-29 16:02:08 +00:00
|
|
|
|
|
|
|
describe "#execute" do
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when params is empty' do
|
2017-02-28 17:34:48 +00:00
|
|
|
let(:params) { {} }
|
2017-03-27 10:12:09 +00:00
|
|
|
let!(:pipelines) { create_list(:ci_pipeline, 2, project: project) }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns all pipelines' do
|
2017-04-27 13:23:06 +00:00
|
|
|
is_expected.to match_array(pipelines)
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
%w[running pending].each do |target|
|
|
|
|
context "when scope is #{target}" do
|
|
|
|
let(:params) { { scope: target } }
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project, status: target) }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline])
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-27 10:12:09 +00:00
|
|
|
end
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when scope is finished' do
|
|
|
|
let(:params) { { scope: 'finished' } }
|
2017-03-28 18:07:11 +00:00
|
|
|
let!(:pipelines) do
|
|
|
|
[create(:ci_pipeline, project: project, status: 'success'),
|
|
|
|
create(:ci_pipeline, project: project, status: 'failed'),
|
|
|
|
create(:ci_pipeline, project: project, status: 'canceled')]
|
|
|
|
end
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-04-27 13:23:06 +00:00
|
|
|
is_expected.to match_array(pipelines)
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
2017-03-27 10:12:09 +00:00
|
|
|
end
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when scope is branches or tags' do
|
|
|
|
let!(:pipeline_branch) { create(:ci_pipeline, project: project) }
|
|
|
|
let!(:pipeline_tag) { create(:ci_pipeline, project: project, ref: 'v1.0.0', tag: true) }
|
2016-08-29 16:02:08 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
context 'when scope is branches' do
|
2016-08-29 16:02:08 +00:00
|
|
|
let(:params) { { scope: 'branches' } }
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline_branch])
|
2016-08-29 16:02:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
context 'when scope is tags' do
|
2016-08-29 16:02:08 +00:00
|
|
|
let(:params) { { scope: 'tags' } }
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline_tag])
|
2016-08-29 16:02:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-30 09:59:45 +00:00
|
|
|
HasStatus::AVAILABLE_STATUSES.each do |target|
|
2017-03-27 10:12:09 +00:00
|
|
|
context "when status is #{target}" do
|
|
|
|
let(:params) { { status: target } }
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project, status: target) }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-28 16:02:17 +00:00
|
|
|
before do
|
2017-03-30 09:59:45 +00:00
|
|
|
exception_status = HasStatus::AVAILABLE_STATUSES - [target]
|
2017-04-05 11:52:02 +00:00
|
|
|
create(:ci_pipeline, project: project, status: exception_status.first)
|
2017-03-28 16:02:17 +00:00
|
|
|
end
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline])
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-27 10:12:09 +00:00
|
|
|
end
|
2016-08-29 16:02:08 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when ref is specified' do
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project) }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-08 17:20:00 +00:00
|
|
|
context 'when ref exists' do
|
2017-02-28 17:34:48 +00:00
|
|
|
let(:params) { { ref: 'master' } }
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline])
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-08 17:20:00 +00:00
|
|
|
context 'when ref does not exist' do
|
2017-03-08 11:24:00 +00:00
|
|
|
let(:params) { { ref: 'invalid-ref' } }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns empty' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to be_empty
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-08 11:24:00 +00:00
|
|
|
end
|
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when name is specified' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project, user: user) }
|
|
|
|
|
2017-03-08 17:20:00 +00:00
|
|
|
context 'when name exists' do
|
2017-03-27 10:12:09 +00:00
|
|
|
let(:params) { { name: user.name } }
|
2017-03-08 11:24:00 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline])
|
2017-03-08 11:24:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-08 17:20:00 +00:00
|
|
|
context 'when name does not exist' do
|
2017-03-08 11:24:00 +00:00
|
|
|
let(:params) { { name: 'invalid-name' } }
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns empty' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to be_empty
|
2017-03-08 11:24:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when username is specified' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, project: project, user: user) }
|
|
|
|
|
2017-03-08 17:20:00 +00:00
|
|
|
context 'when username exists' do
|
2017-03-27 10:12:09 +00:00
|
|
|
let(:params) { { username: user.username } }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline])
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-08 17:20:00 +00:00
|
|
|
context 'when username does not exist' do
|
2017-03-08 11:24:00 +00:00
|
|
|
let(:params) { { username: 'invalid-username' } }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns empty' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to be_empty
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-08 11:24:00 +00:00
|
|
|
end
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when yaml_errors is specified' do
|
|
|
|
let!(:pipeline1) { create(:ci_pipeline, project: project, yaml_errors: 'Syntax error') }
|
|
|
|
let!(:pipeline2) { create(:ci_pipeline, project: project) }
|
|
|
|
|
2017-02-28 17:34:48 +00:00
|
|
|
context 'when yaml_errors is true' do
|
|
|
|
let(:params) { { yaml_errors: true } }
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline1])
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when yaml_errors is false' do
|
|
|
|
let(:params) { { yaml_errors: false } }
|
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns matched pipelines' do
|
2017-03-27 10:12:09 +00:00
|
|
|
is_expected.to eq([pipeline2])
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-02 08:43:37 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
context 'when yaml_errors is invalid' do
|
2017-03-27 10:12:09 +00:00
|
|
|
let(:params) { { yaml_errors: "invalid-yaml_errors" } }
|
2017-03-02 08:43:37 +00:00
|
|
|
|
2017-03-14 16:42:31 +00:00
|
|
|
it 'returns all pipelines' do
|
2017-04-27 13:23:06 +00:00
|
|
|
is_expected.to match_array([pipeline1, pipeline2])
|
2017-03-02 08:43:37 +00:00
|
|
|
end
|
|
|
|
end
|
2017-02-28 17:34:48 +00:00
|
|
|
end
|
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when order_by and sort are specified' do
|
|
|
|
context 'when order_by user_id' do
|
2017-03-17 13:22:50 +00:00
|
|
|
let(:params) { { order_by: 'user_id', sort: 'asc' } }
|
2017-03-27 10:12:09 +00:00
|
|
|
let!(:pipelines) { create_list(:ci_pipeline, 2, project: project, user: create(:user)) }
|
2017-02-28 17:34:48 +00:00
|
|
|
|
2017-03-28 18:07:11 +00:00
|
|
|
it 'sorts as user_id: :asc' do
|
2017-04-27 13:23:06 +00:00
|
|
|
is_expected.to match_array(pipelines)
|
2017-03-01 06:58:06 +00:00
|
|
|
end
|
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when sort is invalid' do
|
|
|
|
let(:params) { { order_by: 'user_id', sort: 'invalid_sort' } }
|
2017-03-02 08:43:37 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
it 'sorts as user_id: :desc' do
|
2017-03-28 15:55:55 +00:00
|
|
|
is_expected.to eq(pipelines.sort_by { |p| -p.user.id })
|
2017-03-27 10:12:09 +00:00
|
|
|
end
|
2017-03-02 08:43:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
context 'when order_by is invalid' do
|
|
|
|
let(:params) { { order_by: 'invalid_column', sort: 'asc' } }
|
|
|
|
let!(:pipelines) { create_list(:ci_pipeline, 2, project: project) }
|
2017-03-02 08:43:37 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
it 'sorts as id: :asc' do
|
2017-03-28 15:55:55 +00:00
|
|
|
is_expected.to eq(pipelines.sort_by { |p| p.id })
|
2017-03-02 08:43:37 +00:00
|
|
|
end
|
|
|
|
end
|
2017-03-17 09:27:11 +00:00
|
|
|
|
|
|
|
context 'when both are nil' do
|
|
|
|
let(:params) { { order_by: nil, sort: nil } }
|
2017-03-27 10:12:09 +00:00
|
|
|
let!(:pipelines) { create_list(:ci_pipeline, 2, project: project) }
|
2017-03-17 09:27:11 +00:00
|
|
|
|
2017-03-27 10:12:09 +00:00
|
|
|
it 'sorts as id: :desc' do
|
2017-03-28 15:55:55 +00:00
|
|
|
is_expected.to eq(pipelines.sort_by { |p| -p.id })
|
2017-03-17 09:27:11 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-29 16:02:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|