From e4efb135e810046b1f4283db4dfe1b386ef15bad Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 7 Dec 2016 16:46:37 +0100 Subject: [PATCH] Add status entity prototype and expose in pipeline --- app/serializers/pipeline_entity.rb | 2 +- app/serializers/status_entity.rb | 8 ++++++++ spec/serializers/status_entity_spec.rb | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 app/serializers/status_entity.rb create mode 100644 spec/serializers/status_entity_spec.rb diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index cf99e628d5f..a07abb4bec0 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -12,7 +12,7 @@ class PipelineEntity < Grape::Entity end expose :details do - expose :status + expose :detailed_status, as: :status, using: StatusEntity expose :duration expose :finished_at expose :stages_with_statuses, as: :stages, using: PipelineStageEntity diff --git a/app/serializers/status_entity.rb b/app/serializers/status_entity.rb new file mode 100644 index 00000000000..ae14dd57f61 --- /dev/null +++ b/app/serializers/status_entity.rb @@ -0,0 +1,8 @@ +class StatusEntity < Grape::Entity + include RequestAwareEntity + + expose :icon, :text, :label, :title + + expose :has_details?, as: :has_details + expose :details_path +end diff --git a/spec/serializers/status_entity_spec.rb b/spec/serializers/status_entity_spec.rb new file mode 100644 index 00000000000..5afa1c25a42 --- /dev/null +++ b/spec/serializers/status_entity_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe StatusEntity do + let(:entity) do + described_class.new(status) + end + + let(:status) do # TODO, add statuses factory + Gitlab::Ci::Status::Success.new(double('object')) + end + + before do + allow(status).to receive(:has_details?).and_return(true) + allow(status).to receive(:details_path).and_return('some/path') + end + + subject { entity.as_json } + + it 'contains status details' do + expect(subject).to include :text, :icon, :label, :title + expect(subject).to include :has_details + expect(subject).to include :details_path + end +end