summaryrefslogtreecommitdiff
path: root/spec/models/ci/ref_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/ci/ref_spec.rb')
-rw-r--r--spec/models/ci/ref_spec.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/spec/models/ci/ref_spec.rb b/spec/models/ci/ref_spec.rb
index 3d75cb63141..fd4742a8ad2 100644
--- a/spec/models/ci/ref_spec.rb
+++ b/spec/models/ci/ref_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Ci::Ref do
+RSpec.describe Ci::Ref do
it { is_expected.to belong_to(:project) }
describe '.ensure_for' do
@@ -62,6 +62,35 @@ describe Ci::Ref do
end
end
+ describe '#last_finished_pipeline_id' do
+ let(:pipeline_status) { :running }
+ let(:config_source) { Ci::PipelineEnums.config_sources[:repository_source] }
+ let(:pipeline) { create(:ci_pipeline, pipeline_status, config_source: config_source) }
+ let(:ci_ref) { pipeline.ci_ref }
+
+ context 'when there are no finished pipelines' do
+ it 'returns nil' do
+ expect(ci_ref.last_finished_pipeline_id).to be_nil
+ end
+ end
+
+ context 'when there are finished pipelines' do
+ let(:pipeline_status) { :success }
+
+ it 'returns the pipeline id' do
+ expect(ci_ref.last_finished_pipeline_id).to eq(pipeline.id)
+ end
+
+ context 'when the pipeline is not a ci_source' do
+ let(:config_source) { Ci::PipelineEnums.config_sources[:parameter_source] }
+
+ it 'returns nil' do
+ expect(ci_ref.last_finished_pipeline_id).to be_nil
+ end
+ end
+ end
+ end
+
describe '#update_status_by!' do
subject { ci_ref.update_status_by!(pipeline) }