diff options
Diffstat (limited to 'spec/models/ci/stage_spec.rb')
-rw-r--r-- | spec/models/ci/stage_spec.rb | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb index ae5ab6fe2ab..20db6394e51 100644 --- a/spec/models/ci/stage_spec.rb +++ b/spec/models/ci/stage_spec.rb @@ -92,16 +92,30 @@ describe Ci::Stage, :models do context 'when stage has been imported and does not have index set' do before do stage.update_column(:index, nil) + end + + context 'when stage has statuses' do + before do + create(:ci_build, :running, stage_id: stage.id, stage_idx: 10) + end + + it 'recalculates index before updating status' do + expect(stage.reload.index).to be_nil - create(:ci_build, :running, stage_id: stage.id, stage_idx: 10) + stage.update_status + + expect(stage.reload.index).to eq 10 + end end - it 'recalculates index before updating status' do - expect(stage.reload.index).to be_nil + context 'when stage does not have statuses' do + it 'fallbacks to zero' do + expect(stage.reload.index).to be_nil - stage.update_status + stage.update_status - expect(stage.reload.index).to eq 10 + expect(stage.reload.index).to eq 0 + end end end end |