Commit 39cf8ae5 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '25327-coverage-badge-rounding' into 'master'

Change rounding on code coverage badge to be consistent with other displays

See merge request gitlab-org/gitlab-ce!10083
parents cf887a8b 1fb4ed21
---
title: Show coverage to two decimal points in coverage badge
merge_request: 10083
author: Jeff Stubler
type: changed
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
@coverage ||= raw_coverage @coverage ||= raw_coverage
return unless @coverage return unless @coverage
@coverage.to_i @coverage.to_f.round(2)
end end
def metadata def metadata
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
end end
def value_text def value_text
@status ? "#{@status}%" : 'unknown' @status ? ("%.2f%%" % @status) : 'unknown'
end end
def key_width def key_width
...@@ -33,7 +33,7 @@ module Gitlab ...@@ -33,7 +33,7 @@ module Gitlab
end end
def value_width def value_width
@status ? 36 : 58 @status ? 54 : 58
end end
def value_color def value_color
......
...@@ -18,7 +18,7 @@ feature 'test coverage badge' do ...@@ -18,7 +18,7 @@ feature 'test coverage badge' do
show_test_coverage_badge show_test_coverage_badge
expect_coverage_badge('95%') expect_coverage_badge('95.00%')
end end
scenario 'user requests coverage badge for specific job' do scenario 'user requests coverage badge for specific job' do
...@@ -30,7 +30,7 @@ feature 'test coverage badge' do ...@@ -30,7 +30,7 @@ feature 'test coverage badge' do
show_test_coverage_badge(job: 'coverage') show_test_coverage_badge(job: 'coverage')
expect_coverage_badge('85%') expect_coverage_badge('85.00%')
end end
scenario 'user requests coverage badge for pipeline without coverage' do scenario 'user requests coverage badge for pipeline without coverage' do
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Badge::Coverage::Template do describe Gitlab::Badge::Coverage::Template do
let(:badge) { double(entity: 'coverage', status: 90) } let(:badge) { double(entity: 'coverage', status: 90.00) }
let(:template) { described_class.new(badge) } let(:template) { described_class.new(badge) }
describe '#key_text' do describe '#key_text' do
...@@ -13,7 +13,17 @@ describe Gitlab::Badge::Coverage::Template do ...@@ -13,7 +13,17 @@ describe Gitlab::Badge::Coverage::Template do
describe '#value_text' do describe '#value_text' do
context 'when coverage is known' do context 'when coverage is known' do
it 'returns coverage percentage' do it 'returns coverage percentage' do
expect(template.value_text).to eq '90%' expect(template.value_text).to eq '90.00%'
end
end
context 'when coverage is known to many digits' do
before do
allow(badge).to receive(:status).and_return(92.349)
end
it 'returns rounded coverage percentage' do
expect(template.value_text).to eq '92.35%'
end end
end end
...@@ -37,7 +47,7 @@ describe Gitlab::Badge::Coverage::Template do ...@@ -37,7 +47,7 @@ describe Gitlab::Badge::Coverage::Template do
describe '#value_width' do describe '#value_width' do
context 'when coverage is known' do context 'when coverage is known' do
it 'is narrower when coverage is known' do it 'is narrower when coverage is known' do
expect(template.value_width).to eq 36 expect(template.value_width).to eq 54
end end
end end
...@@ -113,7 +123,7 @@ describe Gitlab::Badge::Coverage::Template do ...@@ -113,7 +123,7 @@ describe Gitlab::Badge::Coverage::Template do
describe '#width' do describe '#width' do
context 'when coverage is known' do context 'when coverage is known' do
it 'returns the key width plus value width' do it 'returns the key width plus value width' do
expect(template.width).to eq 98 expect(template.width).to eq 116
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment