2017-07-04 13:31:15 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Ci::Stage, :models do
|
2017-07-20 11:30:05 +00:00
|
|
|
let(:stage) { create(:ci_stage_entity) }
|
2017-07-20 11:05:26 +00:00
|
|
|
|
2017-07-20 11:30:05 +00:00
|
|
|
describe 'associations' do
|
2017-07-20 11:05:26 +00:00
|
|
|
before do
|
|
|
|
create(:ci_build, stage_id: stage.id)
|
|
|
|
create(:commit_status, stage_id: stage.id)
|
|
|
|
end
|
|
|
|
|
2017-08-16 11:30:49 +00:00
|
|
|
describe '#statuses' do
|
2017-07-20 11:05:26 +00:00
|
|
|
it 'returns all commit statuses' do
|
2017-08-16 11:30:49 +00:00
|
|
|
expect(stage.statuses.count).to be 2
|
2017-07-20 11:05:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#builds' do
|
|
|
|
it 'returns only builds' do
|
|
|
|
expect(stage.builds).to be_one
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-04 13:31:15 +00:00
|
|
|
describe '#status' do
|
|
|
|
context 'when stage is pending' do
|
|
|
|
let(:stage) { create(:ci_stage_entity, status: 'pending') }
|
|
|
|
|
|
|
|
it 'has a correct status value' do
|
|
|
|
expect(stage.status).to eq 'pending'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when stage is success' do
|
|
|
|
let(:stage) { create(:ci_stage_entity, status: 'success') }
|
|
|
|
|
|
|
|
it 'has a correct status value' do
|
|
|
|
expect(stage.status).to eq 'success'
|
|
|
|
end
|
|
|
|
end
|
2017-08-22 12:04:34 +00:00
|
|
|
|
|
|
|
context 'when stage status is not defined' do
|
|
|
|
before do
|
|
|
|
stage.update_column(:status, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets the default value' do
|
|
|
|
expect(described_class.find(stage.id).status)
|
|
|
|
.to eq 'created'
|
|
|
|
end
|
|
|
|
end
|
2017-07-04 13:31:15 +00:00
|
|
|
end
|
2017-07-20 11:30:05 +00:00
|
|
|
|
2017-07-26 12:50:48 +00:00
|
|
|
describe 'update_status' do
|
2017-07-20 11:30:05 +00:00
|
|
|
context 'when stage objects needs to be updated' do
|
|
|
|
before do
|
|
|
|
create(:ci_build, :success, stage_id: stage.id)
|
|
|
|
create(:ci_build, :running, stage_id: stage.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates stage status correctly' do
|
2017-07-26 12:50:48 +00:00
|
|
|
expect { stage.update_status }
|
2017-07-20 11:30:05 +00:00
|
|
|
.to change { stage.reload.status }
|
|
|
|
.to 'running'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-24 09:22:01 +00:00
|
|
|
context 'when stage is skipped' do
|
|
|
|
it 'updates status to skipped' do
|
2017-07-26 12:50:48 +00:00
|
|
|
expect { stage.update_status }
|
2017-07-24 09:22:01 +00:00
|
|
|
.to change { stage.reload.status }
|
|
|
|
.to 'skipped'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-20 11:30:05 +00:00
|
|
|
context 'when stage object is locked' do
|
2017-07-24 09:22:01 +00:00
|
|
|
before do
|
|
|
|
create(:ci_build, :failed, stage_id: stage.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'retries a lock to update a stage status' do
|
|
|
|
stage.lock_version = 100
|
|
|
|
|
2017-07-26 12:50:48 +00:00
|
|
|
stage.update_status
|
2017-07-24 09:22:01 +00:00
|
|
|
|
|
|
|
expect(stage.reload).to be_failed
|
|
|
|
end
|
2017-07-20 11:30:05 +00:00
|
|
|
end
|
|
|
|
end
|
2017-07-04 13:31:15 +00:00
|
|
|
end
|