Commit c0827455 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add specs for stage detailed status and warnings

parent 887818d3
......@@ -112,7 +112,71 @@ describe Ci::Stage, :models do
end
end
describe '#index' do
describe '#detailed_status' do
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) }
let(:stage) { create(:ci_stage_entity, status: :created) }
subject { stage.detailed_status(user) }
where(:statuses, :label) do
%w[created] | :created
%w[success] | :passed
%w[pending] | :pending
%w[skipped] | :skipped
%w[canceled] | :canceled
%w[success failed] | :failed
%w[running pending] | :running
end
with_them do
before do
statuses.each do |status|
create(:commit_status, project: stage.project,
pipeline: stage.pipeline,
stage_id: stage.id,
status: status)
stage.update_status
end
end
it 'has a correct label' do
expect(subject.label).to eq label.to_s
end
end
context 'when stage has warnings' do
before do
create(:ci_build, project: stage.project,
pipeline: stage.pipeline,
stage_id: stage.id,
status: :failed,
allow_failure: true)
stage.update_status
end
it 'is passed with warnings' do
expect(subject.label).to eq 'passed with warnings'
end
end
end
describe '#groups' do
before do
create(:ci_build, stage_id: stage.id, name: 'rspec 0 1')
create(:ci_build, stage_id: stage.id, name: 'rspec 0 2')
end
it 'groups stage builds by name' do
expect(stage.groups).to be_one
expect(stage.groups.first.name).to eq 'rspec'
end
end
describe '#position' do
context 'when stage has been imported and does not have position index set' do
before do
stage.update_column(:position, nil)
......@@ -143,4 +207,42 @@ describe Ci::Stage, :models do
end
end
end
context 'when stage has warnings' do
before do
create(:ci_build, :failed, :allowed_to_fail, stage_id: stage.id)
end
describe '#has_warnings?' do
it 'returns true' do
expect(stage).to have_warnings
end
end
describe '#number_of_warnings' do
it 'returns a lazy stage warnings counter' do
lazy_queries = ActiveRecord::QueryRecorder.new do
stage.number_of_warnings
end
synced_queries = ActiveRecord::QueryRecorder.new do
stage.number_of_warnings.to_i
end
expect(lazy_queries.count).to eq 0
expect(synced_queries.count).to eq 1
expect(stage.number_of_warnings.inspect).to include 'BatchLoader'
expect(stage.number_of_warnings).to eq 1
end
end
end
context 'when stage does not have warnings' do
describe '#has_warnings?' do
it 'returns false' do
expect(stage).not_to have_warnings
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