Commit e3fd8caf authored by Shinya Maeda's avatar Shinya Maeda

Improved CI. Fix yaml_errors boolean evaluation.

parent f0bc9af3
...@@ -89,7 +89,7 @@ class PipelinesFinder ...@@ -89,7 +89,7 @@ class PipelinesFinder
def by_yaml_errors(items) def by_yaml_errors(items)
flg = Gitlab::Utils.to_boolean(params[:yaml_errors]) flg = Gitlab::Utils.to_boolean(params[:yaml_errors])
if flg.present? if !flg.nil?
if flg if flg
items.where("yaml_errors IS NOT NULL") items.where("yaml_errors IS NOT NULL")
else else
......
require 'spec_helper' require 'spec_helper'
describe PipelinesFinder do describe PipelinesFinder do
let(:user) { create(:user) } let!(:user1) { create(:user) }
let(:project) { create(:project, :repository) } let!(:user2) { create(:user) }
let!(:project) { create(:project, :repository) }
let!(:tag_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 10.minutes.ago, ref: 'v1.0.0') }
let!(:created_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 9.minutes.ago, status: 'created') } let!(:dummy_pipelines) do
let!(:pending_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 8.minutes.ago, status: 'pending') } {
let!(:running_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 7.minutes.ago, status: 'running') } tag: create(:ci_pipeline, project: project, user: user1, created_at: 9.minutes.ago, ref: 'v1.0.0'),
let!(:success_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 6.minutes.ago, status: 'success') } created: create(:ci_pipeline, project: project, user: user1, created_at: 8.minutes.ago, status: 'created'),
let!(:failed_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 5.minutes.ago, status: 'failed') } pending: create(:ci_pipeline, project: project, user: user1, created_at: 7.minutes.ago, status: 'pending'),
let!(:canceled_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 2.minutes.ago, status: 'canceled') } running: create(:ci_pipeline, project: project, user: user1, created_at: 6.minutes.ago, status: 'running'),
let!(:skipped_pipeline) { create(:ci_pipeline, project: project, user: user, created_at: 1.minute.ago, status: 'skipped') } success: create(:ci_pipeline, project: project, user: user1, created_at: 5.minutes.ago, status: 'success'),
let!(:yaml_errors_pipeline) { create(:ci_pipeline, project: project, user: user, yaml_errors: 'Syntax error') } failed: create(:ci_pipeline, project: project, user: user2, created_at: 4.minutes.ago, status: 'failed'),
let(:dummy_pipelines) do canceled: create(:ci_pipeline, project: project, user: user2, created_at: 3.minutes.ago, status: 'canceled'),
[tag_pipeline, skipped: create(:ci_pipeline, project: project, user: user2, created_at: 2.minutes.ago, status: 'skipped'),
created_pipeline, yaml_errors: create(:ci_pipeline, project: project, user: user2, created_at: 1.minute.ago, yaml_errors: 'Syntax error'),
pending_pipeline, }
running_pipeline,
success_pipeline,
failed_pipeline,
canceled_pipeline,
skipped_pipeline,
yaml_errors_pipeline]
end end
subject { described_class.new(project, params).execute } subject { described_class.new(project, params).execute }
...@@ -33,11 +27,11 @@ describe PipelinesFinder do ...@@ -33,11 +27,11 @@ describe PipelinesFinder do
it 'selects all pipelines' do it 'selects all pipelines' do
expect(subject.count).to be dummy_pipelines.count expect(subject.count).to be dummy_pipelines.count
expect(subject).to match_array(dummy_pipelines) expect(subject).to match_array dummy_pipelines.values
end end
it 'orders in descending order on ID' do it 'orders in descending order on ID' do
expect(subject.map(&:id)).to eq dummy_pipelines.map(&:id).sort.reverse expect(subject.map(&:id)).to eq dummy_pipelines.values.map(&:id).sort.reverse
end end
end end
...@@ -71,7 +65,7 @@ describe PipelinesFinder do ...@@ -71,7 +65,7 @@ describe PipelinesFinder do
it 'excludes tags' do it 'excludes tags' do
expect(subject.count).to be 1 expect(subject.count).to be 1
expect(subject).not_to include tag_pipeline expect(subject).not_to include dummy_pipelines[:tag]
expect(subject.map(&:ref)).to include('master') expect(subject.map(&:ref)).to include('master')
end end
end end
...@@ -81,7 +75,7 @@ describe PipelinesFinder do ...@@ -81,7 +75,7 @@ describe PipelinesFinder do
it 'excludes branches' do it 'excludes branches' do
expect(subject.count).to be 1 expect(subject.count).to be 1
expect(subject).to include tag_pipeline expect(subject).to include dummy_pipelines[:tag]
expect(subject.map(&:ref)).not_to include('master') expect(subject.map(&:ref)).not_to include('master')
end end
end end
...@@ -142,15 +136,8 @@ describe PipelinesFinder do ...@@ -142,15 +136,8 @@ describe PipelinesFinder do
let(:params) { { ref: 'master' } } let(:params) { { ref: 'master' } }
it 'selects all pipelines which belong to the ref' do it 'selects all pipelines which belong to the ref' do
expect(subject.count).to be 8 expected = dummy_pipelines.except(:tag)
expect(subject).to include created_pipeline expect(subject).to match_array expected.values
expect(subject).to include pending_pipeline
expect(subject).to include running_pipeline
expect(subject).to include success_pipeline
expect(subject).to include failed_pipeline
expect(subject).to include canceled_pipeline
expect(subject).to include skipped_pipeline
expect(subject).to include yaml_errors_pipeline
end end
end end
...@@ -165,11 +152,11 @@ describe PipelinesFinder do ...@@ -165,11 +152,11 @@ describe PipelinesFinder do
context 'when a username is passed' do context 'when a username is passed' do
context 'when a username exists' do context 'when a username exists' do
let(:params) { { username: user.name } } let(:params) { { username: user1.name } }
it 'selects all pipelines which belong to the username' do it 'selects all pipelines which belong to the username' do
expect(subject).to include success_pipeline expected = dummy_pipelines.except(:failed).except(:canceled).except(:skipped).except(:yaml_errors)
expect(subject).to include failed_pipeline expect(subject).to match_array expected.values
end end
end end
...@@ -186,22 +173,19 @@ describe PipelinesFinder do ...@@ -186,22 +173,19 @@ describe PipelinesFinder do
context 'when yaml_errors is true' do context 'when yaml_errors is true' do
let(:params) { { yaml_errors: true } } let(:params) { { yaml_errors: true } }
it 'selects only pipelines has yaml_errors' do it 'selects only pipelines have yaml_errors' do
expect(subject).to include yaml_errors_pipeline expect(subject.count).to be 1
expect(subject.first).to eq dummy_pipelines[:yaml_errors]
end end
end end
context 'when yaml_errors is false' do context 'when yaml_errors is false' do
let(:params) { { yaml_errors: false } } let(:params) { { yaml_errors: false } }
it 'selects only pipelines does not have yaml_errors' do it 'selects only pipelines do not have yaml_errors' do
expect(subject).to include created_pipeline expected = dummy_pipelines.except(:yaml_errors)
expect(subject).to include pending_pipeline expect(subject.count).to be expected.count
expect(subject).to include running_pipeline expect(subject).to match_array expected.values
expect(subject).to include success_pipeline
expect(subject).to include failed_pipeline
expect(subject).to include canceled_pipeline
expect(subject).to include skipped_pipeline
end end
end end
...@@ -209,8 +193,7 @@ describe PipelinesFinder do ...@@ -209,8 +193,7 @@ describe PipelinesFinder do
let(:params) { { yaml_errors: "UnexpectedValue" } } let(:params) { { yaml_errors: "UnexpectedValue" } }
it 'selects all pipelines' do it 'selects all pipelines' do
expect(subject.count).to be dummy_pipelines.count expect(subject).to match_array dummy_pipelines.values
expect(subject).to match_array(dummy_pipelines)
end end
end end
end end
...@@ -220,8 +203,8 @@ describe PipelinesFinder do ...@@ -220,8 +203,8 @@ describe PipelinesFinder do
let(:params) { { order_by: 'created_at', sort: 'asc' } } let(:params) { { order_by: 'created_at', sort: 'asc' } }
it 'sorts by created_at asc' do it 'sorts by created_at asc' do
expect(subject.first).to eq(tag_pipeline) expect(subject.first).to eq dummy_pipelines[:tag]
expect(subject.last).to eq(yaml_errors_pipeline) expect(subject.last).to eq dummy_pipelines[:yaml_errors]
end end
end end
...@@ -229,8 +212,8 @@ describe PipelinesFinder do ...@@ -229,8 +212,8 @@ describe PipelinesFinder do
let(:params) { { order_by: 'created_at', sort: 'desc' } } let(:params) { { order_by: 'created_at', sort: 'desc' } }
it 'sorts by created_at desc' do it 'sorts by created_at desc' do
expect(subject.first).to eq(yaml_errors_pipeline) expect(subject.first).to eq dummy_pipelines[:yaml_errors]
expect(subject.last).to eq(tag_pipeline) expect(subject.last).to eq dummy_pipelines[:tag]
end end
end end
...@@ -238,7 +221,7 @@ describe PipelinesFinder do ...@@ -238,7 +221,7 @@ describe PipelinesFinder do
let(:params) { { order_by: 'abnormal_column', sort: 'desc' } } let(:params) { { order_by: 'abnormal_column', sort: 'desc' } }
it 'sorts by default' do it 'sorts by default' do
expect(subject.map(&:id)).to eq dummy_pipelines.map(&:id).sort.reverse expect(subject.map(&:id)).to eq dummy_pipelines.values.map(&:id).sort.reverse
end end
end end
...@@ -246,7 +229,7 @@ describe PipelinesFinder do ...@@ -246,7 +229,7 @@ describe PipelinesFinder do
let(:params) { { order_by: 'created_at', sort: 'abnormal_sort' } } let(:params) { { order_by: 'created_at', sort: 'abnormal_sort' } }
it 'sorts by default' do it 'sorts by default' do
expect(subject.map(&:id)).to eq dummy_pipelines.map(&:id).sort.reverse expect(subject.map(&:id)).to eq dummy_pipelines.values.map(&:id).sort.reverse
end end
end end
end 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