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
e258e6f1
Commit
e258e6f1
authored
Apr 06, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for presenters
parent
6bf1780a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
4 deletions
+90
-4
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+4
-0
app/presenters/ci/pipeline_presenter.rb
app/presenters/ci/pipeline_presenter.rb
+0
-4
spec/presenters/ci/build_presenter_spec.rb
spec/presenters/ci/build_presenter_spec.rb
+32
-0
spec/presenters/ci/pipeline_presenter_spec.rb
spec/presenters/ci/pipeline_presenter_spec.rb
+54
-0
No files found.
app/models/ci/pipeline.rb
View file @
e258e6f1
...
@@ -219,6 +219,10 @@ module Ci
...
@@ -219,6 +219,10 @@ module Ci
statuses
.
cancelable
.
any?
statuses
.
cancelable
.
any?
end
end
def
auto_canceled?
canceled?
&&
auto_canceled_by_id?
end
def
cancel_running
def
cancel_running
Gitlab
::
OptimisticLocking
.
retry_lock
(
Gitlab
::
OptimisticLocking
.
retry_lock
(
statuses
.
cancelable
)
do
|
cancelable
|
statuses
.
cancelable
)
do
|
cancelable
|
...
...
app/presenters/ci/pipeline_presenter.rb
View file @
e258e6f1
...
@@ -2,10 +2,6 @@ module Ci
...
@@ -2,10 +2,6 @@ module Ci
class
PipelinePresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
class
PipelinePresenter
<
Gitlab
::
View
::
Presenter
::
Delegated
presents
:pipeline
presents
:pipeline
def
auto_canceled?
canceled?
&&
auto_canceled_by_id?
end
def
status_title
def
status_title
"Pipeline is redundant and is auto-canceled by Pipeline #
#{
auto_canceled_by_id
}
"
if
auto_canceled?
"Pipeline is redundant and is auto-canceled by Pipeline #
#{
auto_canceled_by_id
}
"
if
auto_canceled?
end
end
...
...
spec/presenters/ci/build_presenter_spec.rb
View file @
e258e6f1
...
@@ -57,6 +57,38 @@ describe Ci::BuildPresenter do
...
@@ -57,6 +57,38 @@ describe Ci::BuildPresenter do
end
end
end
end
describe
'#status_title'
do
context
'when build is canceled'
do
before
do
expect
(
presenter
).
to
receive
(
:canceled?
).
and_return
(
true
)
end
context
'when pipeline is auto-canceled'
do
before
do
expect
(
pipeline
).
to
receive
(
:auto_canceled?
).
and_return
(
true
)
expect
(
pipeline
).
to
receive
(
:auto_canceled_by_id
).
and_return
(
1
)
end
it
'shows that the job is auto-canceled'
do
status_title
=
presenter
.
status_title
expect
(
status_title
).
to
include
(
'auto-canceled'
)
expect
(
status_title
).
to
include
(
'Pipeline #1'
)
end
end
context
'when pipeline is not auto-canceled'
do
before
do
expect
(
pipeline
).
to
receive
(
:auto_canceled?
).
and_return
(
false
)
end
it
'shows that the job is auto-canceled'
do
expect
(
presenter
.
status_title
).
to
be_nil
end
end
end
end
describe
'quack like a Ci::Build permission-wise'
do
describe
'quack like a Ci::Build permission-wise'
do
context
'user is not allowed'
do
context
'user is not allowed'
do
let
(
:project
)
{
build_stubbed
(
:empty_project
,
public_builds:
false
)
}
let
(
:project
)
{
build_stubbed
(
:empty_project
,
public_builds:
false
)
}
...
...
spec/presenters/ci/pipeline_presenter_spec.rb
0 → 100644
View file @
e258e6f1
require
'spec_helper'
describe
Ci
::
PipelinePresenter
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
subject
(
:presenter
)
do
described_class
.
new
(
pipeline
)
end
it
'inherits from Gitlab::View::Presenter::Delegated'
do
expect
(
described_class
.
superclass
).
to
eq
(
Gitlab
::
View
::
Presenter
::
Delegated
)
end
describe
'#initialize'
do
it
'takes a pipeline and optional params'
do
expect
{
presenter
}.
not_to
raise_error
end
it
'exposes pipeline'
do
expect
(
presenter
.
pipeline
).
to
eq
(
pipeline
)
end
it
'forwards missing methods to pipeline'
do
expect
(
presenter
.
ref
).
to
eq
(
pipeline
.
ref
)
end
end
describe
'#status_title'
do
context
'when pipeline is auto-canceled'
do
before
do
expect
(
pipeline
).
to
receive
(
:auto_canceled?
).
and_return
(
true
)
expect
(
pipeline
).
to
receive
(
:auto_canceled_by_id
).
and_return
(
1
)
end
it
'shows that the pipeline is auto-canceled'
do
status_title
=
presenter
.
status_title
expect
(
status_title
).
to
include
(
'auto-canceled'
)
expect
(
status_title
).
to
include
(
'Pipeline #1'
)
end
end
context
'when pipeline is not auto-canceled'
do
before
do
expect
(
pipeline
).
to
receive
(
:auto_canceled?
).
and_return
(
false
)
end
it
'shows that the job is auto-canceled'
do
expect
(
presenter
.
status_title
).
to
be_nil
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