From 10499677e2cbabc6331837d20afc0e0fe68ddc37 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 5 Dec 2016 14:38:01 +0100 Subject: Added Stage tests --- app/models/ci/stage.rb | 4 +++ lib/gitlab/ci/status/stage/factory.rb | 2 +- spec/lib/gitlab/ci/status/stage/common_spec.rb | 26 +++++++++++++++++++ spec/lib/gitlab/ci/status/stage/factory_spec.rb | 33 +++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 spec/lib/gitlab/ci/status/stage/common_spec.rb create mode 100644 spec/lib/gitlab/ci/status/stage/factory_spec.rb diff --git a/app/models/ci/stage.rb b/app/models/ci/stage.rb index 2e7f15a16d7..d5ff97c935a 100644 --- a/app/models/ci/stage.rb +++ b/app/models/ci/stage.rb @@ -20,6 +20,10 @@ module Ci @status ||= statuses.latest.status end + def detailed_status + Gitlab::Ci::Status::Stage::Factory.new(self).fabricate! + end + def statuses @statuses ||= pipeline.statuses.where(stage: stage) end diff --git a/lib/gitlab/ci/status/stage/factory.rb b/lib/gitlab/ci/status/stage/factory.rb index 2e485ee22a9..a2f7ad81d39 100644 --- a/lib/gitlab/ci/status/stage/factory.rb +++ b/lib/gitlab/ci/status/stage/factory.rb @@ -24,7 +24,7 @@ module Gitlab Gitlab::Ci::Status .const_get(@status.capitalize) .new(@stage) - .extend(Status::Pipeline::Common) + .extend(Status::Stage::Common) end def extended_status diff --git a/spec/lib/gitlab/ci/status/stage/common_spec.rb b/spec/lib/gitlab/ci/status/stage/common_spec.rb new file mode 100644 index 00000000000..c3cb30a35e4 --- /dev/null +++ b/spec/lib/gitlab/ci/status/stage/common_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Gitlab::Ci::Status::Stage::Common do + let(:pipeline) { create(:ci_pipeline) } + let(:stage) { Ci::Stage.new(pipeline, 'test') } + + subject do + Class.new(Gitlab::Ci::Status::Core) + .new(pipeline).extend(described_class) + end + + it 'does not have action' do + expect(subject).not_to have_action + end + + it 'has details' do + expect(subject).to have_details + end + + it 'links to the pipeline details page' do + expect(subject.details_path) + .to include "pipelines/#{pipeline.id}" + expect(subject.details_path) + .to include "##{stage.name}" + end +end diff --git a/spec/lib/gitlab/ci/status/stage/factory_spec.rb b/spec/lib/gitlab/ci/status/stage/factory_spec.rb new file mode 100644 index 00000000000..a04fd569fc5 --- /dev/null +++ b/spec/lib/gitlab/ci/status/stage/factory_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' + +describe Gitlab::Ci::Status::Stage::Factory do + let(:pipeline) { create(:ci_pipeline) } + let(:stage) { Ci::Stage.new(pipeline, 'test') } + + subject do + described_class.new(stage) + end + + let(:status) do + subject.fabricate! + end + + context 'when stage has a core status' do + HasStatus::AVAILABLE_STATUSES.each do |core_status| + context "when core status is #{core_status}" do + let(:build) { create(:ci_build, pipeline: pipeline, stage: stage.name, status: core_status) } + + it "fabricates a core status #{core_status}" do + expect(status).to be_a( + Gitlab::Ci::Status.const_get(core_status.capitalize)) + end + + it 'extends core status with common pipeline methods' do + expect(status).to have_details + expect(status.details_path).to include "pipelines/#{pipeline.id}" + expect(status.details_path).to include "##{stage.name}" + end + end + end + end +end -- cgit v1.2.1