summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/commit_status.rb9
-rw-r--r--spec/models/commit_status_spec.rb18
2 files changed, 24 insertions, 3 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 07cec63b939..afdc75f75fb 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -38,6 +38,15 @@ class CommitStatus < ActiveRecord::Base
scope :retried_ordered, -> { retried.ordered.includes(project: :namespace) }
scope :after_stage, -> (index) { where('stage_idx > ?', index) }
+ ##
+ # TODO, we will change this to `belongs_to :stage` when we phase out
+ # `ci_builds.stage` attribute and migrate `ci_builds.stage_id` reference in
+ # one of upcoming releases.
+ #
+ def stage_entity
+ Ci::Stage.find_by(pipeline: pipeline, name: stage)
+ end
+
state_machine :status do
event :enqueue do
transition [:created, :skipped, :manual] => :pending
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index 1e074c7ad26..c0cbf0b2f95 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -7,10 +7,10 @@ describe CommitStatus, :models do
create(:ci_pipeline, project: project, sha: project.commit.id)
end
- let(:commit_status) { create_status }
+ let(:commit_status) { create_status(stage: 'test') }
- def create_status(args = {})
- create(:commit_status, args.merge(pipeline: pipeline))
+ def create_status(**opts)
+ create(:commit_status, pipeline: pipeline, **opts)
end
it { is_expected.to belong_to(:pipeline) }
@@ -408,6 +408,18 @@ describe CommitStatus, :models do
end
end
+ describe '#stage_entity' do
+ let!(:stage) do
+ create(:ci_stage_entity, pipeline: commit_status.pipeline,
+ name: commit_status.stage)
+ end
+
+ it 'has a correct association with persisted stage' do
+ expect(commit_status.stage_entity).to eq stage
+ end
+ end
+
+
describe '#locking_enabled?' do
before do
commit_status.lock_version = 100