summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2017-08-25 09:54:42 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2017-08-25 09:54:42 +0000
commit04c092b58d2fe68da10b6291955fd5fd50ac1877 (patch)
tree1906223384a6b94eb97a670066ea7b6a028db0c9
parentec784b1e5195848e55185831ee024a756f18a9f0 (diff)
parent37881ebb75be2069f49f6faf6e01ca73223e998f (diff)
downloadgitlab-ce-04c092b58d2fe68da10b6291955fd5fd50ac1877.tar.gz
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
-rw-r--r--app/models/ci/stage.rb4
-rw-r--r--spec/models/ci/stage_spec.rb11
2 files changed, 15 insertions, 0 deletions
diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb
index 4ee972fa68d..754c37518b3 100644
--- a/app/models/ci/stage.rb
+++ b/app/models/ci/stage.rb
@@ -17,6 +17,10 @@ module Ci
validates :pipeline, 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
event :enqueue do
transition created: :pending
diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb
index 74c9d6145e2..586d073eb5e 100644
--- a/spec/models/ci/stage_spec.rb
+++ b/spec/models/ci/stage_spec.rb
@@ -38,6 +38,17 @@ describe Ci::Stage, :models do
expect(stage.status).to eq 'success'
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
describe 'update_status' do