From 1f314195ea79e0c2610c979c6716134ebe21ec2a Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 20 Jan 2017 12:44:31 +0100 Subject: Do not generate pipeline ref path if ref not present --- app/serializers/pipeline_entity.rb | 10 ++++++---- spec/serializers/pipeline_entity_spec.rb | 12 ++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index d04a4990cb0..61f0f11d7d2 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -40,10 +40,12 @@ class PipelineEntity < Grape::Entity end expose :path do |pipeline| - namespace_project_tree_path( - pipeline.project.namespace, - pipeline.project, - id: pipeline.ref) + if pipeline.ref + namespace_project_tree_path( + pipeline.project.namespace, + pipeline.project, + id: pipeline.ref) + end end expose :tag?, as: :tag diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index b19464c7117..ccb72973f9c 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -134,5 +134,17 @@ describe PipelineEntity do expect(subject).not_to have_key(:yaml_errors) end end + + context 'when pipeline ref is empty' do + let(:pipeline) { create(:ci_empty_pipeline) } + + before do + allow(pipeline).to receive(:ref).and_return(nil) + end + + it 'does not generate branch path' do + expect(subject[:ref][:path]).to be_nil + end + end end end -- cgit v1.2.1