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
Tatuya Kamada
gitlab-ce
Commits
48c19e73
Commit
48c19e73
authored
Jan 12, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose methods that match statuses in status factories
parent
1d01ffb7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
32 deletions
+55
-32
lib/gitlab/ci/status/factory.rb
lib/gitlab/ci/status/factory.rb
+10
-15
spec/lib/gitlab/ci/status/factory_spec.rb
spec/lib/gitlab/ci/status/factory_spec.rb
+45
-17
No files found.
lib/gitlab/ci/status/factory.rb
View file @
48c19e73
...
@@ -5,6 +5,7 @@ module Gitlab
...
@@ -5,6 +5,7 @@ module Gitlab
def
initialize
(
subject
,
user
)
def
initialize
(
subject
,
user
)
@subject
=
subject
@subject
=
subject
@user
=
user
@user
=
user
@status
=
subject
.
status
||
:created
end
end
def
fabricate!
def
fabricate!
...
@@ -17,23 +18,9 @@ module Gitlab
...
@@ -17,23 +18,9 @@ module Gitlab
end
end
end
end
def
self
.
extended_statuses
[]
end
def
self
.
common_helpers
Module
.
new
end
private
def
simple_status
@simple_status
||=
@subject
.
status
||
:created
end
def
core_status
def
core_status
Gitlab
::
Ci
::
Status
Gitlab
::
Ci
::
Status
.
const_get
(
simple_
status
.
capitalize
)
.
const_get
(
@
status
.
capitalize
)
.
new
(
@subject
,
@user
)
.
new
(
@subject
,
@user
)
.
extend
(
self
.
class
.
common_helpers
)
.
extend
(
self
.
class
.
common_helpers
)
end
end
...
@@ -47,6 +34,14 @@ module Gitlab
...
@@ -47,6 +34,14 @@ module Gitlab
@extended_statuses
=
groups
.
flatten
.
compact
@extended_statuses
=
groups
.
flatten
.
compact
end
end
def
self
.
extended_statuses
[]
end
def
self
.
common_helpers
Module
.
new
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/status/factory_spec.rb
View file @
48c19e73
...
@@ -2,17 +2,28 @@ require 'spec_helper'
...
@@ -2,17 +2,28 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Status
::
Factory
do
describe
Gitlab
::
Ci
::
Status
::
Factory
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:status
)
{
factory
.
fabricate!
}
let
(
:
fabricated_
status
)
{
factory
.
fabricate!
}
let
(
:factory
)
{
described_class
.
new
(
resource
,
user
)
}
let
(
:factory
)
{
described_class
.
new
(
resource
,
user
)
}
context
'when object has a core status'
do
context
'when object has a core status'
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
cor
e_status
|
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
simpl
e_status
|
context
"when
core status is
#{
cor
e_status
}
"
do
context
"when
simple core status is
#{
simpl
e_status
}
"
do
let
(
:resource
)
{
double
(
'resource'
,
status:
cor
e_status
)
}
let
(
:resource
)
{
double
(
'resource'
,
status:
simpl
e_status
)
}
it
"fabricates a core status
#{
core_status
}
"
do
let
(
:expected_status
)
do
expect
(
status
).
to
be_a
(
Gitlab
::
Ci
::
Status
.
const_get
(
simple_status
.
capitalize
)
Gitlab
::
Ci
::
Status
.
const_get
(
core_status
.
capitalize
))
end
it
"fabricates a core status
#{
simple_status
}
"
do
expect
(
fabricated_status
).
to
be_a
expected_status
end
it
"matches a valid core status for
#{
simple_status
}
"
do
expect
(
factory
.
core_status
).
to
be_a
expected_status
end
it
"does not match any extended statuses for
#{
simple_status
}
"
do
expect
(
factory
.
extended_statuses
).
to
be_empty
end
end
end
end
end
end
...
@@ -55,17 +66,26 @@ describe Gitlab::Ci::Status::Factory do
...
@@ -55,17 +66,26 @@ describe Gitlab::Ci::Status::Factory do
shared_examples
'compound decorator factory'
do
shared_examples
'compound decorator factory'
do
it
'fabricates compound decorator'
do
it
'fabricates compound decorator'
do
expect
(
status
.
first_method
).
to
eq
'decorated return value'
expect
(
fabricated_
status
.
first_method
).
to
eq
'decorated return value'
expect
(
status
.
second_method
).
to
eq
'second return value'
expect
(
fabricated_
status
.
second_method
).
to
eq
'second return value'
expect
(
status
.
third_method
).
to
eq
'third return value'
expect
(
fabricated_
status
.
third_method
).
to
eq
'third return value'
end
end
it
'delegates to core status'
do
it
'delegates to core status'
do
expect
(
status
.
text
).
to
eq
'passed'
expect
(
fabricated_
status
.
text
).
to
eq
'passed'
end
end
it
'latest matches status becomes a status name'
do
it
'latest matches status becomes a status name'
do
expect
(
status
.
class
).
to
eq
second_extended_status
expect
(
fabricated_status
.
class
).
to
eq
second_extended_status
end
it
'matches correct core status'
do
expect
(
factory
.
core_status
).
to
be_a
Gitlab
::
Ci
::
Status
::
Success
end
it
'matches correct extended statuses'
do
expect
(
factory
.
extended_statuses
)
.
to
eq
[
first_extended_status
,
second_extended_status
]
end
end
end
end
...
@@ -75,14 +95,22 @@ describe Gitlab::Ci::Status::Factory do
...
@@ -75,14 +95,22 @@ describe Gitlab::Ci::Status::Factory do
.
and_return
([[
first_extended_status
,
second_extended_status
]])
.
and_return
([[
first_extended_status
,
second_extended_status
]])
end
end
it
'
fabricates
compound decorator'
do
it
'
does not fabricate
compound decorator'
do
expect
(
status
.
first_method
).
to
eq
'first return value'
expect
(
fabricated_
status
.
first_method
).
to
eq
'first return value'
expect
(
status
.
second_method
).
to
eq
'second return value'
expect
(
fabricated_
status
.
second_method
).
to
eq
'second return value'
expect
(
status
).
not_to
respond_to
(
:third_method
)
expect
(
fabricated_
status
).
not_to
respond_to
(
:third_method
)
end
end
it
'delegates to core status'
do
it
'delegates to core status'
do
expect
(
status
.
text
).
to
eq
'passed'
expect
(
fabricated_status
.
text
).
to
eq
'passed'
end
it
'matches correct core status'
do
expect
(
factory
.
core_status
).
to
be_a
Gitlab
::
Ci
::
Status
::
Success
end
it
'matches correct extended statuses'
do
expect
(
factory
.
extended_statuses
).
to
eq
[
first_extended_status
]
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