From 68569584b728ac2dd5100593e9db302f362994f5 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Fri, 26 May 2017 10:31:42 +0200 Subject: Create PipelineDetailsEntity Now we have a PipelineEntity which is a bit smaller, mostly in bytes needing to send to the frontend. PipelineDetailsEntity is the default for the PipelineSerializer, limiting the changes needed. This commit also incorporates the review. --- spec/serializers/pipeline_details_entity_spec.rb | 120 +++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 spec/serializers/pipeline_details_entity_spec.rb (limited to 'spec/serializers/pipeline_details_entity_spec.rb') diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb new file mode 100644 index 00000000000..ac8d8fa8662 --- /dev/null +++ b/spec/serializers/pipeline_details_entity_spec.rb @@ -0,0 +1,120 @@ +require 'spec_helper' + +describe PipelineDetailsEntity do + set(:user) { create(:user) } + let(:request) { double('request') } + + it 'inherrits from PipelineEntity' do + expect(described_class).to be < PipelineEntity + end + + before do + allow(request).to receive(:current_user).and_return(user) + end + + let(:entity) do + described_class.represent(pipeline, request: request) + end + + describe '#as_json' do + subject { entity.as_json } + + context 'when pipeline is empty' do + let(:pipeline) { create(:ci_empty_pipeline) } + + it 'contains details' do + expect(subject).to include :details + expect(subject[:details]) + .to include :duration, :finished_at + expect(subject[:details]) + .to include :stages, :artifacts, :manual_actions + expect(subject[:details][:status]).to include :icon, :favicon, :text, :label + end + + it 'contains flags' do + expect(subject).to include :flags + expect(subject[:flags]) + .to include :latest, :triggered, :stuck, + :yaml_errors, :retryable, :cancelable + end + end + + context 'when pipeline is retryable' do + let(:project) { create(:empty_project) } + + let(:pipeline) do + create(:ci_pipeline, status: :success, project: project) + end + + before do + create(:ci_build, :failed, pipeline: pipeline) + end + + context 'user has ability to retry pipeline' do + before { project.team << [user, :developer] } + + it 'retryable flag is true' do + expect(subject[:flags][:retryable]).to eq true + end + end + + context 'user does not have ability to retry pipeline' do + it 'retryable flag is false' do + expect(subject[:flags][:retryable]).to eq false + end + end + end + + context 'when pipeline is cancelable' do + let(:project) { create(:empty_project) } + + let(:pipeline) do + create(:ci_pipeline, status: :running, project: project) + end + + before do + create(:ci_build, :pending, pipeline: pipeline) + end + + context 'user has ability to cancel pipeline' do + before { project.add_developer(user) } + + it 'cancelable flag is true' do + expect(subject[:flags][:cancelable]).to eq true + end + end + + context 'user does not have ability to cancel pipeline' do + it 'cancelable flag is false' do + expect(subject[:flags][:cancelable]).to eq false + end + end + end + + context 'when pipeline has YAML errors' do + let(:pipeline) do + create(:ci_pipeline, config: { rspec: { invalid: :value } }) + end + + it 'contains information about error' do + expect(subject[:yaml_errors]).to be_present + end + + it 'contains flag that indicates there are errors' do + expect(subject[:flags][:yaml_errors]).to be true + end + end + + context 'when pipeline does not have YAML errors' do + let(:pipeline) { create(:ci_empty_pipeline) } + + it 'does not contain field that normally holds an error' do + expect(subject).not_to have_key(:yaml_errors) + end + + it 'contains flag that indicates there are no errors' do + expect(subject[:flags][:yaml_errors]).to be false + end + end + end +end -- cgit v1.2.1