From 123da5fbe8f5dee13278b1ef9aff79ff9adcef90 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Tue, 3 Oct 2017 13:18:59 +0200 Subject: [PATCH] Improve specs for pipeline failure reason presenter Conflicts: app/presenters/ci/pipeline_presenter.rb --- app/presenters/ci/pipeline_presenter.rb | 6 +++++- spec/presenters/ci/pipeline_presenter_spec.rb | 17 +++++++++++++++++ spec/serializers/pipeline_entity_spec.rb | 13 +++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/presenters/ci/pipeline_presenter.rb b/app/presenters/ci/pipeline_presenter.rb index 5e393e95c80..099b4720fb6 100644 --- a/app/presenters/ci/pipeline_presenter.rb +++ b/app/presenters/ci/pipeline_presenter.rb @@ -1,6 +1,10 @@ module Ci class PipelinePresenter < Gitlab::View::Presenter::Delegated - FAILURE_REASONS = {} + FAILURE_REASONS = { + config_error: 'CI/CD YAML configuration error!' + }.freeze + + presents :pipeline def failure_reason return unless pipeline.failure_reason? diff --git a/spec/presenters/ci/pipeline_presenter_spec.rb b/spec/presenters/ci/pipeline_presenter_spec.rb index e4886a8f019..f7ceaf844be 100644 --- a/spec/presenters/ci/pipeline_presenter_spec.rb +++ b/spec/presenters/ci/pipeline_presenter_spec.rb @@ -51,4 +51,21 @@ describe Ci::PipelinePresenter do end end end + + context '#failure_reason' do + context 'when pipeline has failure reason' do + it 'represents a failure reason sentence' do + pipeline.failure_reason = :config_error + + expect(presenter.failure_reason) + .to eq 'CI/CD YAML configuration error!' + end + end + + context 'when pipeline does not have failure reason' do + it 'returns nil' do + expect(presenter.failure_reason).to be_nil + end + end + end end diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index f8df461bc81..248552d1858 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -108,5 +108,18 @@ describe PipelineEntity do expect(subject[:ref][:path]).to be_nil end end + + context 'when pipeline has a failure reason set' do + let(:pipeline) { create(:ci_empty_pipeline) } + + before do + pipeline.drop!(:config_error) + end + + it 'has a correct failure reason' do + expect(subject[:failure_reason]) + .to eq 'CI/CD YAML configuration error!' + end + end end end