Commit 04c092b5 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'fix/gb/fix-invalid-stage-status-transition' into 'master'

Set a default CI/CD status when it is not known

Closes #36790

See merge request !13737
parents ec784b1e 37881ebb
...@@ -17,6 +17,10 @@ module Ci ...@@ -17,6 +17,10 @@ module Ci
validates :pipeline, presence: true, unless: :importing? validates :pipeline, presence: true, unless: :importing?
validates :name, presence: true, unless: :importing? validates :name, presence: true, unless: :importing?
after_initialize do |stage|
self.status = DEFAULT_STATUS if self.status.nil?
end
state_machine :status, initial: :created do state_machine :status, initial: :created do
event :enqueue do event :enqueue do
transition created: :pending transition created: :pending
......
...@@ -38,6 +38,17 @@ describe Ci::Stage, :models do ...@@ -38,6 +38,17 @@ describe Ci::Stage, :models do
expect(stage.status).to eq 'success' expect(stage.status).to eq 'success'
end end
end end
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
end end
describe 'update_status' do describe 'update_status' do
......
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