gitlab-org--gitlab-foss/spec/finders/pipelines_finder_spec.rb

242 lines
6.9 KiB
Ruby
Raw Normal View History

2016-08-29 16:02:08 +00:00
require 'spec_helper'
describe PipelinesFinder do
2017-03-07 17:44:38 +00: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')
end
2016-08-29 16:02:08 +00:00
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-02-28 17:34:48 +00:00
context 'when nothing is passed' do
let(:params) { {} }
it 'selects all pipelines' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.all)
2017-02-28 17:34:48 +00:00
end
it 'orders in descending order on ID' do
expect(subject).to eq(Ci::Pipeline.order(id: :desc))
2017-02-28 17:34:48 +00:00
end
end
2017-03-08 17:20:00 +00:00
context 'when scope is passed' do
2017-02-28 17:34:48 +00:00
context 'when selecting running' do
let(:params) { { scope: 'running' } }
it 'has only running status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.running)
2017-02-28 17:34:48 +00:00
end
end
context 'when selecting pending' do
let(:params) { { scope: 'pending' } }
it 'has only pending status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.pending)
2017-02-28 17:34:48 +00:00
end
end
context 'when selecting finished' do
let(:params) { { scope: 'finished' } }
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
it 'has only finished status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.finished)
2016-08-29 16:02:08 +00:00
end
end
context 'when selecting branches' do
let(:params) { { scope: 'branches' } }
it 'excludes tags' do
2017-03-07 17:44:38 +00:00
expect(subject).to eq([Ci::Pipeline.where(tag: false).last])
2016-08-29 16:02:08 +00:00
end
end
context 'when selecting tags' do
let(:params) { { scope: 'tags' } }
it 'excludes branches' do
2017-03-07 17:44:38 +00:00
expect(subject).to eq([Ci::Pipeline.where(tag: true).last])
2016-08-29 16:02:08 +00:00
end
end
end
2017-03-08 17:20:00 +00:00
context 'when status is passed' do
2017-02-28 17:34:48 +00:00
context 'when selecting running' do
let(:params) { { status: 'running' } }
2017-02-28 17:34:48 +00:00
it 'has only running status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.running)
2017-02-28 17:34:48 +00:00
end
end
context 'when selecting pending' do
let(:params) { { status: 'pending' } }
2017-02-28 17:34:48 +00:00
it 'has only pending status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.pending)
2017-02-28 17:34:48 +00:00
end
end
context 'when selecting success' do
let(:params) { { status: 'success' } }
2017-02-28 17:34:48 +00:00
it 'has only success status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.success)
2017-02-28 17:34:48 +00:00
end
end
context 'when selecting failed' do
let(:params) { { status: 'failed' } }
2017-02-28 17:34:48 +00:00
it 'has only failed status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.failed)
2017-02-28 17:34:48 +00:00
end
end
context 'when selecting canceled' do
let(:params) { { status: 'canceled' } }
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
it 'has only canceled status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.canceled)
2017-02-28 17:34:48 +00:00
end
end
2016-08-29 16:02:08 +00:00
2017-02-28 17:34:48 +00:00
context 'when selecting skipped' do
let(:params) { { status: 'skipped' } }
2017-02-28 17:34:48 +00:00
it 'has only skipped status' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.skipped)
2017-02-28 17:34:48 +00:00
end
end
end
2017-03-08 17:20:00 +00:00
context 'when ref is passed' do
context 'when ref exists' do
2017-02-28 17:34:48 +00:00
let(:params) { { ref: 'master' } }
it 'selects all pipelines which belong to the ref' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.where(ref: 'master'))
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
it 'selects nothing' do
expect(subject).to be_empty
end
end
2017-03-08 11:24:00 +00:00
end
2017-03-08 17:20:00 +00:00
context 'when name is passed' do
context 'when name exists' do
2017-03-08 11:24:00 +00:00
let(:params) { { name: user1.name } }
it 'selects all pipelines which belong to the name' do
expect(subject).to match_array(Ci::Pipeline.where(user: user1))
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' } }
it 'selects nothing' do
expect(subject).to be_empty
end
end
end
2017-02-28 17:34:48 +00:00
2017-03-08 17:20:00 +00:00
context 'when username is passed' do
context 'when username exists' do
2017-03-08 09:19:11 +00:00
let(:params) { { username: user1.username } }
2017-02-28 17:34:48 +00:00
it 'selects all pipelines which belong to the username' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.where(user: user1))
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
it 'selects nothing' do
expect(subject).to be_empty
end
end
2017-03-08 11:24:00 +00:00
end
2017-02-28 17:34:48 +00:00
2017-03-08 17:20:00 +00:00
context 'when yaml_errors is passed' do
2017-02-28 17:34:48 +00:00
context 'when yaml_errors is true' do
let(:params) { { yaml_errors: true } }
it 'selects only pipelines have yaml_errors' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.where("yaml_errors IS NOT NULL"))
2017-02-28 17:34:48 +00:00
end
end
context 'when yaml_errors is false' do
let(:params) { { yaml_errors: false } }
it 'selects only pipelines do not have yaml_errors' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.where("yaml_errors IS NULL"))
2017-02-28 17:34:48 +00:00
end
end
context 'when an argument is invalid' do
let(:params) { { yaml_errors: "UnexpectedValue" } }
it 'selects all pipelines' do
2017-03-07 17:44:38 +00:00
expect(subject).to match_array(Ci::Pipeline.all)
end
end
2017-02-28 17:34:48 +00:00
end
2017-03-08 17:20:00 +00:00
context 'when order_by and sort are passed' do
context 'when order by created_at asc' do
2017-02-28 17:34:48 +00:00
let(:params) { { order_by: 'created_at', sort: 'asc' } }
it 'sorts by created_at asc' do
expect(subject).to eq(Ci::Pipeline.order(created_at: :asc))
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
expect(subject).to eq(Ci::Pipeline.order(created_at: :desc))
2017-02-28 17:34:48 +00:00
end
end
context 'when order_by does not exist' do
2017-03-08 11:24:00 +00:00
let(:params) { { order_by: 'invalid_column', sort: 'desc' } }
it 'sorts by default' do
expect(subject).to eq(Ci::Pipeline.order(id: :desc))
end
end
context 'when sort does not exist' do
2017-03-08 11:24:00 +00:00
let(:params) { { order_by: 'created_at', sort: 'invalid_sort' } }
it 'sorts by default' do
2017-03-14 16:33:25 +00:00
expect(subject).to eq(Ci::Pipeline.order(created_at: :desc))
end
end
2016-08-29 16:02:08 +00:00
end
end
end