Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
796efcc7
Commit
796efcc7
authored
Aug 11, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add template class for coverage report badge
parent
cc244160
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
199 additions
and
0 deletions
+199
-0
lib/gitlab/badge/coverage/template.rb
lib/gitlab/badge/coverage/template.rb
+69
-0
spec/lib/gitlab/badge/coverage/template_spec.rb
spec/lib/gitlab/badge/coverage/template_spec.rb
+130
-0
No files found.
lib/gitlab/badge/coverage/template.rb
0 → 100644
View file @
796efcc7
module
Gitlab
module
Badge
module
Coverage
##
# Class that represents a coverage badge template.
#
# Template object will be passed to badge.svg.erb template.
#
class
Template
STATUS_COLOR
=
{
good:
'#4c1'
,
acceptable:
'#b0c'
,
medium:
'#dfb317'
,
low:
'#e05d44'
,
unknown:
'#9f9f9f'
}
def
initialize
(
badge
)
@entity
=
badge
.
entity
@status
=
badge
.
status
end
def
key_text
@entity
.
to_s
end
def
value_text
@status
?
"
#{
@status
}
%"
:
'unknown'
end
def
key_width
62
end
def
value_width
@status
?
32
:
58
end
def
key_color
'#555'
end
def
value_color
case
@status
when
nil
then
STATUS_COLOR
[
:unknown
]
when
95
..
100
then
STATUS_COLOR
[
:good
]
when
90
..
95
then
STATUS_COLOR
[
:acceptable
]
when
75
..
90
then
STATUS_COLOR
[
:medium
]
when
0
..
75
then
STATUS_COLOR
[
:low
]
else
STATUS_COLOR
[
:unknown
]
end
end
def
key_text_anchor
key_width
/
2
end
def
value_text_anchor
key_width
+
(
value_width
/
2
)
end
def
width
key_width
+
value_width
end
end
end
end
end
spec/lib/gitlab/badge/coverage/template_spec.rb
0 → 100644
View file @
796efcc7
require
'spec_helper'
describe
Gitlab
::
Badge
::
Coverage
::
Template
do
let
(
:badge
)
{
double
(
entity:
'coverage'
,
status:
90
)
}
let
(
:template
)
{
described_class
.
new
(
badge
)
}
describe
'#key_text'
do
it
'is always says coverage'
do
expect
(
template
.
key_text
).
to
eq
'coverage'
end
end
describe
'#value_text'
do
context
'when coverage is known'
do
it
'returns coverage percentage'
do
expect
(
template
.
value_text
).
to
eq
'90%'
end
end
context
'when coverage is unknown'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
nil
)
end
it
'returns string that says coverage is unknown'
do
expect
(
template
.
value_text
).
to
eq
'unknown'
end
end
end
describe
'#key_width'
do
it
'has a fixed key width'
do
expect
(
template
.
key_width
).
to
eq
62
end
end
describe
'#value_width'
do
context
'when coverage is known'
do
it
'is narrower when coverage is known'
do
expect
(
template
.
value_width
).
to
eq
32
end
end
context
'when coverage is unknown'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
nil
)
end
it
'is wider when coverage is unknown to fit text'
do
expect
(
template
.
value_width
).
to
eq
58
end
end
end
describe
'#key_color'
do
it
'always has the same color'
do
expect
(
template
.
key_color
).
to
eq
'#555'
end
end
describe
'#value_color'
do
context
'when coverage is good'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
98
)
end
it
'is green'
do
expect
(
template
.
value_color
).
to
eq
'#4c1'
end
end
context
'when coverage is acceptable'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
90
)
end
it
'is green-orange'
do
expect
(
template
.
value_color
).
to
eq
'#b0c'
end
end
context
'when coverage is medium'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
75
)
end
it
'is orange-yellow'
do
expect
(
template
.
value_color
).
to
eq
'#dfb317'
end
end
context
'when coverage is low'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
50
)
end
it
'is red'
do
expect
(
template
.
value_color
).
to
eq
'#e05d44'
end
end
context
'when coverage is unknown'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
nil
)
end
it
'is grey'
do
expect
(
template
.
value_color
).
to
eq
'#9f9f9f'
end
end
end
describe
'#width'
do
context
'when coverage is known'
do
it
'returns the key width plus value width'
do
expect
(
template
.
width
).
to
eq
94
end
end
context
'when coverage is unknown'
do
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
nil
)
end
it
'returns key width plus wider value width'
do
expect
(
template
.
width
).
to
eq
120
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment