summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-22 14:04:34 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-08-22 14:04:34 +0200
commit37881ebb75be2069f49f6faf6e01ca73223e998f (patch)
treeef606b8ee83f948089409f20ed65b7a5b7088176
parent78a0d27e98cea4ed1b59377edc93588127b297fe (diff)
downloadgitlab-ce-fix/gb/fix-invalid-stage-status-transition.tar.gz
Set a default CI/CD status when it is not knownfix/gb/fix-invalid-stage-status-transition
-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