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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
503c44ee
Commit
503c44ee
authored
Jul 28, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add badge template class to use with SVG ERB template
parent
0c4fa861
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
0 deletions
+139
-0
lib/gitlab/badge/build/template.rb
lib/gitlab/badge/build/template.rb
+63
-0
spec/lib/gitlab/badge/build/template_spec.rb
spec/lib/gitlab/badge/build/template_spec.rb
+76
-0
No files found.
lib/gitlab/badge/build/template.rb
0 → 100644
View file @
503c44ee
module
Gitlab
module
Badge
class
Build
##
# Abstract class for build badge template.
#
# Template object will be passed to badge.svg.erb template.
#
class
Template
STATUS_COLOR
=
{
success:
'#4c1'
,
failed:
'#e05d44'
,
running:
'#dfb317'
,
pending:
'#dfb317'
,
canceled:
'#9f9f9f'
,
skipped:
'#9f9f9f'
,
unknown:
'#9f9f9f'
}
def
initialize
(
status
)
@status
=
status
end
def
key_text
'build'
end
def
value_text
@status
end
def
key_width
38
end
def
value_width
54
end
def
key_color
'#555'
end
def
value_color
STATUS_COLOR
[
@status
.
to_sym
]
||
STATUS_COLOR
[
:unknown
]
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/build/template_spec.rb
0 → 100644
View file @
503c44ee
require
'spec_helper'
describe
Gitlab
::
Badge
::
Build
::
Template
do
let
(
:status
)
{
'success'
}
let
(
:template
)
{
described_class
.
new
(
status
)
}
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
let
(
:status
)
{
'success'
}
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#4c1'
end
end
context
'when status is failed'
do
let
(
:status
)
{
'failed'
}
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#e05d44'
end
end
context
'when status is running'
do
let
(
:status
)
{
'running'
}
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#dfb317'
end
end
context
'when status is unknown'
do
let
(
:status
)
{
'unknown'
}
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#9f9f9f'
end
end
context
'when status does not match any known statuses'
do
let
(
:status
)
{
'invalid status'
}
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#9f9f9f'
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