Add unit tests for CommitStatus and Ci::Stage
This commit is contained in:
parent
cc8b8a60b7
commit
8ed7b34066
4 changed files with 96 additions and 2 deletions
|
@ -41,6 +41,10 @@ FactoryBot.define do
|
|||
status 'manual'
|
||||
end
|
||||
|
||||
trait :scheduled do
|
||||
status 'scheduled'
|
||||
end
|
||||
|
||||
after(:build) do |build, evaluator|
|
||||
build.project = build.pipeline.project
|
||||
end
|
||||
|
|
|
@ -89,6 +89,18 @@ describe Ci::Stage, :models do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when stage is scheduled because of scheduled builds' do
|
||||
before do
|
||||
create(:ci_build, :scheduled, stage_id: stage.id)
|
||||
end
|
||||
|
||||
it 'updates status to scheduled' do
|
||||
expect { stage.update_status }
|
||||
.to change { stage.reload.status }
|
||||
.to 'scheduled'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when stage is skipped because is empty' do
|
||||
it 'updates status to skipped' do
|
||||
expect { stage.update_status }
|
||||
|
@ -188,6 +200,18 @@ describe Ci::Stage, :models do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#schedule' do
|
||||
subject { stage.schedule }
|
||||
|
||||
let(:stage) { create(:ci_stage_entity, status: :created) }
|
||||
|
||||
it 'updates stage status' do
|
||||
subject
|
||||
|
||||
expect(stage).to be_scheduled
|
||||
end
|
||||
end
|
||||
|
||||
describe '#position' do
|
||||
context 'when stage has been imported and does not have position index set' do
|
||||
before do
|
||||
|
|
|
@ -129,6 +129,20 @@ describe CommitStatus do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#cancel' do
|
||||
subject { job.cancel }
|
||||
|
||||
context 'when status is scheduled' do
|
||||
let(:job) { build(:commit_status, :scheduled) }
|
||||
|
||||
it 'updates the status' do
|
||||
subject
|
||||
|
||||
expect(job).to be_canceled
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#auto_canceled?' do
|
||||
subject { commit_status.auto_canceled? }
|
||||
|
||||
|
@ -564,6 +578,12 @@ describe CommitStatus do
|
|||
|
||||
it_behaves_like 'commit status enqueued'
|
||||
end
|
||||
|
||||
context 'when initial state is :scheduled' do
|
||||
let(:commit_status) { create(:commit_status, :scheduled) }
|
||||
|
||||
it_behaves_like 'commit status enqueued'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#present' do
|
||||
|
|
|
@ -270,11 +270,11 @@ describe HasStatus do
|
|||
describe '.cancelable' do
|
||||
subject { CommitStatus.cancelable }
|
||||
|
||||
%i[running pending created].each do |status|
|
||||
%i[running pending created scheduled].each do |status|
|
||||
it_behaves_like 'containing the job', status
|
||||
end
|
||||
|
||||
%i[failed success skipped canceled].each do |status|
|
||||
%i[failed success skipped canceled manual].each do |status|
|
||||
it_behaves_like 'not containing the job', status
|
||||
end
|
||||
end
|
||||
|
@ -290,6 +290,18 @@ describe HasStatus do
|
|||
it_behaves_like 'not containing the job', status
|
||||
end
|
||||
end
|
||||
|
||||
describe '.scheduled' do
|
||||
subject { CommitStatus.scheduled }
|
||||
|
||||
%i[scheduled].each do |status|
|
||||
it_behaves_like 'containing the job', status
|
||||
end
|
||||
|
||||
%i[failed success skipped canceled].each do |status|
|
||||
it_behaves_like 'not containing the job', status
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '::DEFAULT_STATUS' do
|
||||
|
@ -303,4 +315,38 @@ describe HasStatus do
|
|||
expect(described_class::BLOCKED_STATUS).to eq %w[manual scheduled]
|
||||
end
|
||||
end
|
||||
|
||||
describe 'blocked?' do
|
||||
subject { object.blocked? }
|
||||
|
||||
%w[ci_pipeline ci_stage ci_build generic_commit_status].each do |type|
|
||||
let(:object) { build(type, status: status) }
|
||||
|
||||
context 'when status is scheduled' do
|
||||
let(:status) { :scheduled }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when status is manual' do
|
||||
let(:status) { :manual }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when status is created' do
|
||||
let(:status) { :created }
|
||||
|
||||
it { is_expected.to be_falsy }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.status_sql' do
|
||||
subject { Ci::Build.status_sql }
|
||||
|
||||
it 'returns SQL' do
|
||||
puts subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue