BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
bc179962
Commit
bc179962
authored
Aug 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve builds badge specs, remove legacy methods
parent
8ae22209
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
40 deletions
+21
-40
build.rb
lib/gitlab/badge/build.rb
+6
-15
build_spec.rb
spec/lib/gitlab/badge/build_spec.rb
+15
-25
No files found.
lib/gitlab/badge/build.rb
View file @
bc179962
...
@@ -4,35 +4,26 @@ module Gitlab
...
@@ -4,35 +4,26 @@ module Gitlab
# Build badge
# Build badge
#
#
class
Build
class
Build
delegate
:key_text
,
:value_text
,
to: :template
def
initialize
(
project
,
ref
)
def
initialize
(
project
,
ref
)
@project
=
project
@project
=
project
@ref
=
ref
@ref
=
ref
@sha
=
@project
.
commit
(
@ref
).
try
(
:sha
)
end
end
def
status
def
status
sha
=
@project
.
commit
(
@ref
).
try
(
:sha
)
@project
.
pipelines
@project
.
pipelines
.
where
(
sha:
sha
,
ref:
@ref
)
.
where
(
sha:
@
sha
,
ref:
@ref
)
.
status
||
'unknown'
.
status
||
'unknown'
end
end
def
metadata
def
metadata
Build
::
Metadata
.
new
(
@project
,
@ref
)
@metadata
||=
Build
::
Metadata
.
new
(
@project
,
@ref
)
end
end
def
template
def
template
Build
::
Template
.
new
(
status
)
@template
||=
Build
::
Template
.
new
(
status
)
end
def
type
'image/svg+xml'
end
def
data
File
.
read
(
Rails
.
root
.
join
(
'public/ci'
,
'build-'
+
status
+
'.svg'
)
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/badge/build_spec.rb
View file @
bc179962
...
@@ -6,11 +6,6 @@ describe Gitlab::Badge::Build do
...
@@ -6,11 +6,6 @@ describe Gitlab::Badge::Build do
let
(
:branch
)
{
'master'
}
let
(
:branch
)
{
'master'
}
let
(
:badge
)
{
described_class
.
new
(
project
,
branch
)
}
let
(
:badge
)
{
described_class
.
new
(
project
,
branch
)
}
describe
'#type'
do
subject
{
badge
.
type
}
it
{
is_expected
.
to
eq
'image/svg+xml'
}
end
describe
'#metadata'
do
describe
'#metadata'
do
it
'returns badge metadata'
do
it
'returns badge metadata'
do
expect
(
badge
.
metadata
.
image_url
)
expect
(
badge
.
metadata
.
image_url
)
...
@@ -18,6 +13,12 @@ describe Gitlab::Badge::Build do
...
@@ -18,6 +13,12 @@ describe Gitlab::Badge::Build do
end
end
end
end
describe
'#key_text'
do
it
'always says build'
do
expect
(
badge
.
key_text
).
to
eq
'build'
end
end
context
'build exists'
do
context
'build exists'
do
let!
(
:build
)
{
create_build
(
project
,
sha
,
branch
)
}
let!
(
:build
)
{
create_build
(
project
,
sha
,
branch
)
}
...
@@ -30,11 +31,9 @@ describe Gitlab::Badge::Build do
...
@@ -30,11 +31,9 @@ describe Gitlab::Badge::Build do
end
end
end
end
describe
'#data'
do
describe
'#value_text'
do
let
(
:data
)
{
badge
.
data
}
it
'returns correct value text'
do
expect
(
badge
.
value_text
).
to
eq
'success'
it
'contains information about success'
do
expect
(
status_node
(
data
,
'success'
)).
to
be_truthy
end
end
end
end
end
end
...
@@ -48,11 +47,9 @@ describe Gitlab::Badge::Build do
...
@@ -48,11 +47,9 @@ describe Gitlab::Badge::Build do
end
end
end
end
describe
'#data'
do
describe
'#value_text'
do
let
(
:data
)
{
badge
.
data
}
it
'has correct value text'
do
expect
(
badge
.
value_text
).
to
eq
'failed'
it
'contains information about failure'
do
expect
(
status_node
(
data
,
'failed'
)).
to
be_truthy
end
end
end
end
end
end
...
@@ -65,11 +62,9 @@ describe Gitlab::Badge::Build do
...
@@ -65,11 +62,9 @@ describe Gitlab::Badge::Build do
end
end
end
end
describe
'#data'
do
describe
'#value_text'
do
let
(
:data
)
{
badge
.
data
}
it
'has correct value text'
do
expect
(
badge
.
value_text
).
to
eq
'unknown'
it
'contains infromation about unknown build'
do
expect
(
status_node
(
data
,
'unknown'
)).
to
be_truthy
end
end
end
end
end
end
...
@@ -95,9 +90,4 @@ describe Gitlab::Badge::Build do
...
@@ -95,9 +90,4 @@ describe Gitlab::Badge::Build do
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'notify'
)
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'notify'
)
end
end
def
status_node
(
data
,
status
)
xml
=
Nokogiri
::
XML
.
parse
(
data
)
xml
.
at
(
%Q{text:contains("
#{
status
}
")}
)
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