diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-07-22 05:36:02 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-07-22 05:36:02 +0000 |
commit | d950e4d937f06fb9c09847301a908839cf78dae1 (patch) | |
tree | e4ab5d30f0b5059589ef0a34d7f31c58152220b0 /spec | |
parent | f6d2ac2bf14a136bc1d1714a519102b3a023331c (diff) | |
parent | 0d3b8fad9742e6568458f2a8e4d66f0b36d731ec (diff) | |
download | gitlab-ce-d950e4d937f06fb9c09847301a908839cf78dae1.tar.gz |
Merge branch 'zj-pipeline-badge-improvements' into 'master'
Pipeline badge improvements
Closes #15582 and #20961
See merge request !12966
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/badges_controller_spec.rb | 28 | ||||
-rw-r--r-- | spec/features/projects/badges/list_spec.rb | 12 | ||||
-rw-r--r-- | spec/features/projects/badges/pipeline_badge_spec.rb | 70 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/pipeline/metadata_spec.rb (renamed from spec/lib/gitlab/badge/build/metadata_spec.rb) | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/pipeline/status_spec.rb (renamed from spec/lib/gitlab/badge/build/status_spec.rb) | 37 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/pipeline/template_spec.rb (renamed from spec/lib/gitlab/badge/build/template_spec.rb) | 18 |
6 files changed, 134 insertions, 37 deletions
diff --git a/spec/controllers/projects/badges_controller_spec.rb b/spec/controllers/projects/badges_controller_spec.rb new file mode 100644 index 00000000000..d68200164e4 --- /dev/null +++ b/spec/controllers/projects/badges_controller_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Projects::BadgesController do + let(:project) { pipeline.project } + let!(:pipeline) { create(:ci_empty_pipeline) } + let(:user) { create(:user) } + + before do + project.add_master(user) + sign_in(user) + end + + it 'requests the pipeline badge successfully' do + get_badge(:pipeline) + + expect(response).to have_http_status(:ok) + end + + it 'requests the coverage badge successfully' do + get_badge(:coverage) + + expect(response).to have_http_status(:ok) + end + + def get_badge(badge) + get badge, namespace_id: project.namespace.to_param, project_id: project, ref: pipeline.ref, format: :svg + end +end diff --git a/spec/features/projects/badges/list_spec.rb b/spec/features/projects/badges/list_spec.rb index 161d731f524..fd8e9232b02 100644 --- a/spec/features/projects/badges/list_spec.rb +++ b/spec/features/projects/badges/list_spec.rb @@ -10,16 +10,16 @@ feature 'list of badges' do end scenario 'user wants to see build status badge' do - page.within('.build-status') do - expect(page).to have_content 'build status' + page.within('.pipeline-status') do + expect(page).to have_content 'pipeline status' expect(page).to have_content 'Markdown' expect(page).to have_content 'HTML' expect(page).to have_content 'AsciiDoc' expect(page).to have_css('.highlight', count: 3) - expect(page).to have_xpath("//img[@alt='build status']") + expect(page).to have_xpath("//img[@alt='pipeline status']") page.within('.highlight', match: :first) do - expect(page).to have_content 'badges/master/build.svg' + expect(page).to have_content 'badges/master/pipeline.svg' end end end @@ -40,14 +40,14 @@ feature 'list of badges' do end scenario 'user changes current ref of build status badge', js: true do - page.within('.build-status') do + page.within('.pipeline-status') do first('.js-project-refs-dropdown').click page.within '.project-refs-form' do click_link 'improve/awesome' end - expect(page).to have_content 'badges/improve/awesome/build.svg' + expect(page).to have_content 'badges/improve/awesome/pipeline.svg' end end end diff --git a/spec/features/projects/badges/pipeline_badge_spec.rb b/spec/features/projects/badges/pipeline_badge_spec.rb new file mode 100644 index 00000000000..b83ea8f4eaa --- /dev/null +++ b/spec/features/projects/badges/pipeline_badge_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' + +feature 'Pipeline Badge' do + set(:project) { create(:project, :repository, :public) } + let(:ref) { project.default_branch } + + # this can't be tested in the controller, as it bypasses the rails router + # and constructs a route based on the controller being tested + # Keep around until 10.0, see gitlab-org/gitlab-ce#35307 + context 'when the deprecated badge is requested' do + it 'displays the badge' do + visit build_project_badges_path(project, ref: ref, format: :svg) + + expect(page.status_code).to eq(200) + end + end + + context 'when the project has a pipeline' do + let!(:pipeline) { create(:ci_empty_pipeline, project: project, ref: ref, sha: project.commit(ref).sha) } + let!(:job) { create(:ci_build, pipeline: pipeline) } + + context 'when the pipeline was successfull' do + it 'displays so on the badge' do + job.success + + visit pipeline_project_badges_path(project, ref: ref, format: :svg) + + expect(page.status_code).to eq(200) + expect_badge('passed') + end + end + + context 'when the pipeline failed' do + it 'shows displays so on the badge' do + job.drop + + visit pipeline_project_badges_path(project, ref: ref, format: :svg) + + expect(page.status_code).to eq(200) + expect_badge('failed') + end + end + + context 'when the pipeline is running' do + it 'shows displays so on the badge' do + create(:ci_build, pipeline: pipeline, name: 'second build', status_event: 'run') + + visit pipeline_project_badges_path(project, ref: ref, format: :svg) + + expect(page.status_code).to eq(200) + expect_badge('running') + end + end + + context 'when a new pipeline is created' do + it 'shows a fresh badge' do + visit pipeline_project_badges_path(project, ref: ref, format: :svg) + + expect(page.status_code).to eq(200) + expect(page.response_headers['Cache-Control']).to include 'no-cache' + end + end + + def expect_badge(status) + svg = Nokogiri::XML.parse(page.body) + expect(page.response_headers['Content-Type']).to include('image/svg+xml') + expect(svg.at(%Q{text:contains("#{status}")})).to be_truthy + end + end +end diff --git a/spec/lib/gitlab/badge/build/metadata_spec.rb b/spec/lib/gitlab/badge/pipeline/metadata_spec.rb index 9df96ea04eb..d537ce8803c 100644 --- a/spec/lib/gitlab/badge/build/metadata_spec.rb +++ b/spec/lib/gitlab/badge/pipeline/metadata_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'lib/gitlab/badge/shared/metadata' -describe Gitlab::Badge::Build::Metadata do +describe Gitlab::Badge::Pipeline::Metadata do let(:badge) { double(project: create(:empty_project), ref: 'feature') } let(:metadata) { described_class.new(badge) } @@ -9,13 +9,13 @@ describe Gitlab::Badge::Build::Metadata do describe '#title' do it 'returns build status title' do - expect(metadata.title).to eq 'build status' + 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/build.svg' + expect(metadata.image_url).to include 'badges/feature/pipeline.svg' end end diff --git a/spec/lib/gitlab/badge/build/status_spec.rb b/spec/lib/gitlab/badge/pipeline/status_spec.rb index 6abf4ca46a9..dc835375c66 100644 --- a/spec/lib/gitlab/badge/build/status_spec.rb +++ b/spec/lib/gitlab/badge/pipeline/status_spec.rb @@ -1,36 +1,35 @@ require 'spec_helper' -describe Gitlab::Badge::Build::Status do +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 build' do - expect(badge.entity).to eq 'build' + 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 'build' + 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/build.svg' + expect(badge.metadata.image_url).to include 'badges/master/pipeline.svg' end end - context 'build exists' do - let!(:build) { create_build(project, sha, branch) } + context 'pipeline exists' do + let!(:pipeline) { create_pipeline(project, sha, branch) } - context 'build success' do + context 'pipeline success' do before do - build.success! + pipeline.success! end describe '#status' do @@ -40,9 +39,9 @@ describe Gitlab::Badge::Build::Status do end end - context 'build failed' do + context 'pipeline failed' do before do - build.drop! + pipeline.drop! end describe '#status' do @@ -54,10 +53,10 @@ describe Gitlab::Badge::Build::Status do context 'when outdated pipeline for given ref exists' do before do - build.success! + pipeline.success! - old_build = create_build(project, '11eeffdd', branch) - old_build.drop! + old_pipeline = create_pipeline(project, '11eeffdd', branch) + old_pipeline.drop! end it 'does not take outdated pipeline into account' do @@ -67,10 +66,10 @@ describe Gitlab::Badge::Build::Status do context 'when multiple pipelines exist for given sha' do before do - build.drop! + pipeline.drop! - new_build = create_build(project, sha, branch) - new_build.success! + new_pipeline = create_pipeline(project, sha, branch) + new_pipeline.success! end it 'does not take outdated pipeline into account' do @@ -87,7 +86,7 @@ describe Gitlab::Badge::Build::Status do end end - def create_build(project, sha, branch) + def create_pipeline(project, sha, branch) pipeline = create(:ci_empty_pipeline, project: project, sha: sha, diff --git a/spec/lib/gitlab/badge/build/template_spec.rb b/spec/lib/gitlab/badge/pipeline/template_spec.rb index a7e21fb8bb1..20fa4f879c3 100644 --- a/spec/lib/gitlab/badge/build/template_spec.rb +++ b/spec/lib/gitlab/badge/pipeline/template_spec.rb @@ -1,28 +1,28 @@ require 'spec_helper' -describe Gitlab::Badge::Build::Template do - let(:badge) { double(entity: 'build', status: 'success') } +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 build' do - expect(template.key_text).to eq 'build' + 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' + expect(template.value_text).to eq 'passed' 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.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 19 - expect(template.value_text_anchor).to eq 65 + expect(template.key_text_anchor).to eq 31 + expect(template.value_text_anchor).to eq 89 end end |