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
Léo-Paul Géneau
gitlab-ce
Commits
f3de46e6
Commit
f3de46e6
authored
Aug 11, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor badge template and metadata classes
parent
9f0b46c0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
58 additions
and
58 deletions
+58
-58
lib/gitlab/badge/base.rb
lib/gitlab/badge/base.rb
+2
-2
lib/gitlab/badge/build/metadata.rb
lib/gitlab/badge/build/metadata.rb
+3
-3
lib/gitlab/badge/build/status.rb
lib/gitlab/badge/build/status.rb
+8
-3
lib/gitlab/badge/build/template.rb
lib/gitlab/badge/build/template.rb
+6
-6
spec/lib/gitlab/badge/build/metadata_spec.rb
spec/lib/gitlab/badge/build/metadata_spec.rb
+13
-12
spec/lib/gitlab/badge/build/status_spec.rb
spec/lib/gitlab/badge/build/status_spec.rb
+12
-24
spec/lib/gitlab/badge/build/template_spec.rb
spec/lib/gitlab/badge/build/template_spec.rb
+14
-8
No files found.
lib/gitlab/badge/base.rb
View file @
f3de46e6
module
Gitlab
module
Badge
class
Base
def
key_text
def
entity
raise
NotImplementedError
end
def
value_text
def
status
raise
NotImplementedError
end
...
...
lib/gitlab/badge/build/metadata.rb
View file @
f3de46e6
...
...
@@ -9,9 +9,9 @@ module Gitlab
include
ActionView
::
Helpers
::
AssetTagHelper
include
ActionView
::
Helpers
::
UrlHelper
def
initialize
(
project
,
ref
)
@project
=
project
@ref
=
ref
def
initialize
(
badge
)
@project
=
badge
.
project
@ref
=
badge
.
ref
end
def
to_html
...
...
lib/gitlab/badge/build/status.rb
View file @
f3de46e6
...
...
@@ -5,14 +5,19 @@ module Gitlab
# Build status badge
#
class
Status
<
Badge
::
Base
delegate
:key_text
,
:value_text
,
to: :template
attr_reader
:project
,
:ref
def
initialize
(
project
,
ref
)
@project
=
project
@ref
=
ref
@sha
=
@project
.
commit
(
@ref
).
try
(
:sha
)
end
def
entity
'build'
end
def
status
@project
.
pipelines
.
where
(
sha:
@sha
,
ref:
@ref
)
...
...
@@ -20,11 +25,11 @@ module Gitlab
end
def
metadata
@metadata
||=
Build
::
Metadata
.
new
(
@project
,
@re
f
)
@metadata
||=
Build
::
Metadata
.
new
(
sel
f
)
end
def
template
@template
||=
Build
::
Template
.
new
(
s
tatus
)
@template
||=
Build
::
Template
.
new
(
s
elf
)
end
end
end
...
...
lib/gitlab/badge/build/template.rb
View file @
f3de46e6
...
...
@@ -17,16 +17,17 @@ module Gitlab
unknown:
'#9f9f9f'
}
def
initialize
(
status
)
@status
=
status
def
initialize
(
badge
)
@entity
=
badge
.
entity
@status
=
badge
.
status
end
def
key_text
'build'
@entity
.
to_s
end
def
value_text
@status
@status
.
to_s
end
def
key_width
...
...
@@ -42,8 +43,7 @@ module Gitlab
end
def
value_color
STATUS_COLOR
[
@status
.
to_sym
]
||
STATUS_COLOR
[
:unknown
]
STATUS_COLOR
[
@status
.
to_sym
]
||
STATUS_COLOR
[
:unknown
]
end
def
key_text_anchor
...
...
spec/lib/gitlab/badge/build/metadata_spec.rb
View file @
f3de46e6
require
'spec_helper'
describe
Gitlab
::
Badge
::
Build
::
Metadata
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:branch
)
{
'master'
}
let
(
:badge
)
{
described_class
.
new
(
project
,
branch
)
}
let
(
:badge
)
{
double
(
project:
create
(
:project
),
ref:
'feature'
)
}
let
(
:metadata
)
{
described_class
.
new
(
badge
)
}
describe
'#to_html'
do
let
(
:html
)
{
Nokogiri
::
HTML
.
parse
(
badge
.
to_html
)
}
let
(
:html
)
{
Nokogiri
::
HTML
.
parse
(
metadata
.
to_html
)
}
let
(
:a_href
)
{
html
.
at
(
'a'
)
}
it
'points to link'
do
expect
(
a_href
[
:href
]).
to
eq
badge
.
link_url
expect
(
a_href
[
:href
]).
to
eq
metadata
.
link_url
end
it
'contains clickable image'
do
...
...
@@ -19,19 +18,21 @@ describe Gitlab::Badge::Build::Metadata do
end
describe
'#to_markdown'
do
subject
{
badge
.
to_markdown
}
subject
{
metadata
.
to_markdown
}
it
{
is_expected
.
to
include
badge
.
image_url
}
it
{
is_expected
.
to
include
badge
.
link_url
}
it
{
is_expected
.
to
include
metadata
.
image_url
}
it
{
is_expected
.
to
include
metadata
.
link_url
}
end
describe
'#image_url'
do
subject
{
badge
.
image_url
}
it
{
is_expected
.
to
include
"badges/
#{
branch
}
/build.svg"
}
it
'returns valid url'
do
expect
(
metadata
.
image_url
).
to
include
'badges/feature/build.svg'
end
end
describe
'#link_url'
do
subject
{
badge
.
link_url
}
it
{
is_expected
.
to
include
"commits/
#{
branch
}
"
}
it
'returns valid link'
do
expect
(
metadata
.
link_url
).
to
include
'commits/feature'
end
end
end
spec/lib/gitlab/badge/build/status_spec.rb
View file @
f3de46e6
...
...
@@ -6,6 +6,18 @@ describe Gitlab::Badge::Build::Status do
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
)
...
...
@@ -13,12 +25,6 @@ describe Gitlab::Badge::Build::Status do
end
end
describe
'#key_text'
do
it
'always says build'
do
expect
(
badge
.
key_text
).
to
eq
'build'
end
end
context
'build exists'
do
let!
(
:build
)
{
create_build
(
project
,
sha
,
branch
)
}
...
...
@@ -30,12 +36,6 @@ describe Gitlab::Badge::Build::Status do
expect
(
badge
.
status
).
to
eq
'success'
end
end
describe
'#value_text'
do
it
'returns correct value text'
do
expect
(
badge
.
value_text
).
to
eq
'success'
end
end
end
context
'build failed'
do
...
...
@@ -46,12 +46,6 @@ describe Gitlab::Badge::Build::Status do
expect
(
badge
.
status
).
to
eq
'failed'
end
end
describe
'#value_text'
do
it
'has correct value text'
do
expect
(
badge
.
value_text
).
to
eq
'failed'
end
end
end
context
'when outdated pipeline for given ref exists'
do
...
...
@@ -87,12 +81,6 @@ describe Gitlab::Badge::Build::Status do
expect
(
badge
.
status
).
to
eq
'unknown'
end
end
describe
'#value_text'
do
it
'has correct value text'
do
expect
(
badge
.
value_text
).
to
eq
'unknown'
end
end
end
def
create_build
(
project
,
sha
,
branch
)
...
...
spec/lib/gitlab/badge/build/template_spec.rb
View file @
f3de46e6
require
'spec_helper'
describe
Gitlab
::
Badge
::
Build
::
Template
do
let
(
:
status
)
{
'success'
}
let
(
:template
)
{
described_class
.
new
(
status
)
}
let
(
:
badge
)
{
double
(
entity:
'build'
,
status:
'success'
)
}
let
(
:template
)
{
described_class
.
new
(
badge
)
}
describe
'#key_text'
do
it
'is always says build'
do
...
...
@@ -34,15 +34,15 @@ describe Gitlab::Badge::Build::Template do
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'
}
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
'failed'
)
end
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#e05d44'
...
...
@@ -50,7 +50,9 @@ describe Gitlab::Badge::Build::Template do
end
context
'when status is running'
do
let
(
:status
)
{
'running'
}
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
'running'
)
end
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#dfb317'
...
...
@@ -58,7 +60,9 @@ describe Gitlab::Badge::Build::Template do
end
context
'when status is unknown'
do
let
(
:status
)
{
'unknown'
}
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
'unknown'
)
end
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#9f9f9f'
...
...
@@ -66,7 +70,9 @@ describe Gitlab::Badge::Build::Template do
end
context
'when status does not match any known statuses'
do
let
(
:status
)
{
'invalid status'
}
before
do
allow
(
badge
).
to
receive
(
:status
).
and_return
(
'invalid'
)
end
it
'has expected color'
do
expect
(
template
.
value_color
).
to
eq
'#9f9f9f'
...
...
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