From 2086483b24e719ec8d82b3e7a52476626952885a Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Wed, 19 Jul 2017 13:08:47 +0200 Subject: Rename build to pipeline for status badges First commit in probably 2, for resolve gitlab-org/gitlab-ce#15582. This commit is renaming files and classes from build to pipeline. Also wording is editted to pipeline. Given `pipeline` had more characters than `build`, I've made the field a bit wider. The width now matchers the one for the coverage badge, so they look nice when in a table format, or in a list. As soon as this commit is merged to master, and released, the build.svg is deprecated, meaning that all users which already placed a badge should update it. However, to make sure it keeps working tests are added for this case. --- spec/lib/gitlab/badge/build/metadata_spec.rb | 27 ------- spec/lib/gitlab/badge/build/status_spec.rb | 98 ------------------------- spec/lib/gitlab/badge/build/template_spec.rb | 82 --------------------- spec/lib/gitlab/badge/pipeline/metadata_spec.rb | 27 +++++++ spec/lib/gitlab/badge/pipeline/status_spec.rb | 97 ++++++++++++++++++++++++ spec/lib/gitlab/badge/pipeline/template_spec.rb | 82 +++++++++++++++++++++ 6 files changed, 206 insertions(+), 207 deletions(-) delete mode 100644 spec/lib/gitlab/badge/build/metadata_spec.rb delete mode 100644 spec/lib/gitlab/badge/build/status_spec.rb delete mode 100644 spec/lib/gitlab/badge/build/template_spec.rb create mode 100644 spec/lib/gitlab/badge/pipeline/metadata_spec.rb create mode 100644 spec/lib/gitlab/badge/pipeline/status_spec.rb create mode 100644 spec/lib/gitlab/badge/pipeline/template_spec.rb (limited to 'spec/lib/gitlab/badge') diff --git a/spec/lib/gitlab/badge/build/metadata_spec.rb b/spec/lib/gitlab/badge/build/metadata_spec.rb deleted file mode 100644 index 9df96ea04eb..00000000000 --- a/spec/lib/gitlab/badge/build/metadata_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper' -require 'lib/gitlab/badge/shared/metadata' - -describe Gitlab::Badge::Build::Metadata do - let(:badge) { double(project: create(:empty_project), ref: 'feature') } - let(:metadata) { described_class.new(badge) } - - it_behaves_like 'badge metadata' - - describe '#title' do - it 'returns build status title' do - expect(metadata.title).to eq 'build status' - end - end - - describe '#image_url' do - it 'returns valid url' do - expect(metadata.image_url).to include 'badges/feature/build.svg' - end - end - - describe '#link_url' do - it 'returns valid link' do - expect(metadata.link_url).to include 'commits/feature' - end - end -end diff --git a/spec/lib/gitlab/badge/build/status_spec.rb b/spec/lib/gitlab/badge/build/status_spec.rb deleted file mode 100644 index 6abf4ca46a9..00000000000 --- a/spec/lib/gitlab/badge/build/status_spec.rb +++ /dev/null @@ -1,98 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Badge::Build::Status do - let(:project) { create(:project, :repository) } - let(:sha) { project.commit.sha } - let(:branch) { 'master' } - let(:badge) { described_class.new(project, branch) } - - describe '#entity' do - it 'always says build' do - expect(badge.entity).to eq 'build' - end - end - - describe '#template' do - it 'returns badge template' do - expect(badge.template.key_text).to eq 'build' - end - end - - describe '#metadata' do - it 'returns badge metadata' do - expect(badge.metadata.image_url) - .to include 'badges/master/build.svg' - end - end - - context 'build exists' do - let!(:build) { create_build(project, sha, branch) } - - context 'build success' do - before do - build.success! - end - - describe '#status' do - it 'is successful' do - expect(badge.status).to eq 'success' - end - end - end - - context 'build failed' do - before do - build.drop! - end - - describe '#status' do - it 'failed' do - expect(badge.status).to eq 'failed' - end - end - end - - context 'when outdated pipeline for given ref exists' do - before do - build.success! - - old_build = create_build(project, '11eeffdd', branch) - old_build.drop! - end - - it 'does not take outdated pipeline into account' do - expect(badge.status).to eq 'success' - end - end - - context 'when multiple pipelines exist for given sha' do - before do - build.drop! - - new_build = create_build(project, sha, branch) - new_build.success! - end - - it 'does not take outdated pipeline into account' do - expect(badge.status).to eq 'success' - end - end - end - - context 'build does not exist' do - describe '#status' do - it 'is unknown' do - expect(badge.status).to eq 'unknown' - end - end - end - - def create_build(project, sha, branch) - pipeline = create(:ci_empty_pipeline, - project: project, - sha: sha, - ref: branch) - - create(:ci_build, pipeline: pipeline, stage: 'notify') - end -end diff --git a/spec/lib/gitlab/badge/build/template_spec.rb b/spec/lib/gitlab/badge/build/template_spec.rb deleted file mode 100644 index a7e21fb8bb1..00000000000 --- a/spec/lib/gitlab/badge/build/template_spec.rb +++ /dev/null @@ -1,82 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Badge::Build::Template do - let(:badge) { double(entity: 'build', status: 'success') } - let(:template) { described_class.new(badge) } - - describe '#key_text' do - it 'is always says build' do - expect(template.key_text).to eq 'build' - end - end - - describe '#value_text' do - it 'is status value' do - expect(template.value_text).to eq 'success' - end - end - - describe 'widths and text anchors' do - it 'has fixed width and text anchors' do - expect(template.width).to eq 92 - expect(template.key_width).to eq 38 - expect(template.value_width).to eq 54 - expect(template.key_text_anchor).to eq 19 - expect(template.value_text_anchor).to eq 65 - end - end - - describe '#key_color' do - it 'is always the same' do - expect(template.key_color).to eq '#555' - end - end - - describe '#value_color' do - context 'when status is success' do - it 'has expected color' do - expect(template.value_color).to eq '#4c1' - end - end - - context 'when status is failed' do - before do - allow(badge).to receive(:status).and_return('failed') - end - - it 'has expected color' do - expect(template.value_color).to eq '#e05d44' - end - end - - context 'when status is running' do - before do - allow(badge).to receive(:status).and_return('running') - end - - it 'has expected color' do - expect(template.value_color).to eq '#dfb317' - end - end - - context 'when status is unknown' do - before do - allow(badge).to receive(:status).and_return('unknown') - end - - it 'has expected color' do - expect(template.value_color).to eq '#9f9f9f' - end - end - - context 'when status does not match any known statuses' do - before do - allow(badge).to receive(:status).and_return('invalid') - end - - it 'has expected color' do - expect(template.value_color).to eq '#9f9f9f' - end - end - end -end diff --git a/spec/lib/gitlab/badge/pipeline/metadata_spec.rb b/spec/lib/gitlab/badge/pipeline/metadata_spec.rb new file mode 100644 index 00000000000..d537ce8803c --- /dev/null +++ b/spec/lib/gitlab/badge/pipeline/metadata_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' +require 'lib/gitlab/badge/shared/metadata' + +describe Gitlab::Badge::Pipeline::Metadata do + let(:badge) { double(project: create(:empty_project), ref: 'feature') } + let(:metadata) { described_class.new(badge) } + + it_behaves_like 'badge metadata' + + describe '#title' do + it 'returns build status title' do + expect(metadata.title).to eq 'pipeline status' + end + end + + describe '#image_url' do + it 'returns valid url' do + expect(metadata.image_url).to include 'badges/feature/pipeline.svg' + end + end + + describe '#link_url' do + it 'returns valid link' do + expect(metadata.link_url).to include 'commits/feature' + end + end +end diff --git a/spec/lib/gitlab/badge/pipeline/status_spec.rb b/spec/lib/gitlab/badge/pipeline/status_spec.rb new file mode 100644 index 00000000000..dc835375c66 --- /dev/null +++ b/spec/lib/gitlab/badge/pipeline/status_spec.rb @@ -0,0 +1,97 @@ +require 'spec_helper' + +describe Gitlab::Badge::Pipeline::Status do + let(:project) { create(:project, :repository) } + let(:sha) { project.commit.sha } + let(:branch) { 'master' } + let(:badge) { described_class.new(project, branch) } + + describe '#entity' do + it 'always says pipeline' do + expect(badge.entity).to eq 'pipeline' + end + end + + describe '#template' do + it 'returns badge template' do + expect(badge.template.key_text).to eq 'pipeline' + end + end + + describe '#metadata' do + it 'returns badge metadata' do + expect(badge.metadata.image_url).to include 'badges/master/pipeline.svg' + end + end + + context 'pipeline exists' do + let!(:pipeline) { create_pipeline(project, sha, branch) } + + context 'pipeline success' do + before do + pipeline.success! + end + + describe '#status' do + it 'is successful' do + expect(badge.status).to eq 'success' + end + end + end + + context 'pipeline failed' do + before do + pipeline.drop! + end + + describe '#status' do + it 'failed' do + expect(badge.status).to eq 'failed' + end + end + end + + context 'when outdated pipeline for given ref exists' do + before do + pipeline.success! + + old_pipeline = create_pipeline(project, '11eeffdd', branch) + old_pipeline.drop! + end + + it 'does not take outdated pipeline into account' do + expect(badge.status).to eq 'success' + end + end + + context 'when multiple pipelines exist for given sha' do + before do + pipeline.drop! + + new_pipeline = create_pipeline(project, sha, branch) + new_pipeline.success! + end + + it 'does not take outdated pipeline into account' do + expect(badge.status).to eq 'success' + end + end + end + + context 'build does not exist' do + describe '#status' do + it 'is unknown' do + expect(badge.status).to eq 'unknown' + end + end + end + + def create_pipeline(project, sha, branch) + pipeline = create(:ci_empty_pipeline, + project: project, + sha: sha, + ref: branch) + + create(:ci_build, pipeline: pipeline, stage: 'notify') + end +end diff --git a/spec/lib/gitlab/badge/pipeline/template_spec.rb b/spec/lib/gitlab/badge/pipeline/template_spec.rb new file mode 100644 index 00000000000..24a33ecbfda --- /dev/null +++ b/spec/lib/gitlab/badge/pipeline/template_spec.rb @@ -0,0 +1,82 @@ +require 'spec_helper' + +describe Gitlab::Badge::Pipeline::Template do + let(:badge) { double(entity: 'pipeline', status: 'success') } + let(:template) { described_class.new(badge) } + + describe '#key_text' do + it 'is always says pipeline' do + expect(template.key_text).to eq 'pipeline' + end + end + + describe '#value_text' do + it 'is status value' do + expect(template.value_text).to eq 'success' + end + end + + describe 'widths and text anchors' do + it 'has fixed width and text anchors' do + expect(template.width).to eq 116 + expect(template.key_width).to eq 62 + expect(template.value_width).to eq 54 + expect(template.key_text_anchor).to eq 31 + expect(template.value_text_anchor).to eq 89 + end + end + + describe '#key_color' do + it 'is always the same' do + expect(template.key_color).to eq '#555' + end + end + + describe '#value_color' do + context 'when status is success' do + it 'has expected color' do + expect(template.value_color).to eq '#4c1' + end + end + + context 'when status is failed' do + before do + allow(badge).to receive(:status).and_return('failed') + end + + it 'has expected color' do + expect(template.value_color).to eq '#e05d44' + end + end + + context 'when status is running' do + before do + allow(badge).to receive(:status).and_return('running') + end + + it 'has expected color' do + expect(template.value_color).to eq '#dfb317' + end + end + + context 'when status is unknown' do + before do + allow(badge).to receive(:status).and_return('unknown') + end + + it 'has expected color' do + expect(template.value_color).to eq '#9f9f9f' + end + end + + context 'when status does not match any known statuses' do + before do + allow(badge).to receive(:status).and_return('invalid') + end + + it 'has expected color' do + expect(template.value_color).to eq '#9f9f9f' + end + end + end +end -- cgit v1.2.3