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
Boxiang Sun
gitlab-ce
Commits
55aa727e
Commit
55aa727e
authored
Apr 12, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract build play specs and extend test examples
parent
7fc6b5b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
34 deletions
+107
-34
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+2
-34
spec/services/ci/play_build_service_spec.rb
spec/services/ci/play_build_service_spec.rb
+105
-0
No files found.
spec/models/ci/build_spec.rb
View file @
55aa727e
...
@@ -959,40 +959,8 @@ describe Ci::Build, :models do
...
@@ -959,40 +959,8 @@ describe Ci::Build, :models do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
end
end
context
'when user does not have ability to trigger action'
do
it
'enqueues the build'
do
before
do
expect
(
build
.
play
(
user
)).
to
be_pending
create
(
:protected_branch
,
:no_one_can_push
,
name:
build
.
ref
,
project:
project
)
end
it
'raises an error'
do
expect
{
build
.
play
(
user
)
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
end
end
context
'when user has ability to trigger manual action'
do
context
'when build is manual'
do
it
'enqueues a build'
do
new_build
=
build
.
play
(
user
)
expect
(
new_build
).
to
be_pending
expect
(
new_build
).
to
eq
(
build
)
end
end
context
'when build is not manual'
do
before
do
build
.
update
(
status:
'success'
)
end
it
'creates a new build'
do
new_build
=
build
.
play
(
user
)
expect
(
new_build
).
to
be_pending
expect
(
new_build
).
not_to
eq
(
build
)
end
end
end
end
end
end
...
...
spec/services/ci/play_build_service_spec.rb
0 → 100644
View file @
55aa727e
require
'spec_helper'
describe
Ci
::
PlayBuildService
,
'#execute'
,
:services
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
let
(
:service
)
do
described_class
.
new
(
project
,
user
)
end
context
'when project does not have repository yet'
do
let
(
:project
)
{
create
(
:empty_project
)
}
it
'allows user with master role to play build'
do
project
.
add_master
(
user
)
service
.
execute
(
build
)
expect
(
build
.
reload
).
to
be_pending
end
it
'does not allow user with developer role to play build'
do
project
.
add_developer
(
user
)
expect
{
service
.
execute
(
build
)
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
end
end
context
'when project has repository'
do
let
(
:project
)
{
create
(
:project
)
}
it
'allows user with developer role to play a build'
do
project
.
add_developer
(
user
)
service
.
execute
(
build
)
expect
(
build
.
reload
).
to
be_pending
end
end
context
'when build is a playable manual action'
do
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline
)
}
before
do
project
.
add_master
(
user
)
end
it
'enqueues the build'
do
expect
(
service
.
execute
(
build
)).
to
eq
build
expect
(
build
.
reload
).
to
be_pending
end
it
'reassignes build user correctly'
do
service
.
execute
(
build
)
expect
(
build
.
reload
.
user
).
to
eq
user
end
end
context
'when build is not a playable manual action'
do
let
(
:build
)
{
create
(
:ci_build
,
when: :manual
,
pipeline:
pipeline
)
}
before
do
project
.
add_master
(
user
)
end
it
'duplicates the build'
do
duplicate
=
service
.
execute
(
build
)
expect
(
duplicate
).
not_to
eq
build
expect
(
duplicate
).
to
be_pending
end
it
'assigns users correctly'
do
duplicate
=
service
.
execute
(
build
)
expect
(
build
.
user
).
not_to
eq
user
expect
(
duplicate
.
user
).
to
eq
user
end
end
context
'when build is not action'
do
let
(
:build
)
{
create
(
:ci_build
,
:success
,
pipeline:
pipeline
)
}
it
'raises an error'
do
expect
{
service
.
execute
(
build
)
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
end
end
context
'when user does not have ability to trigger action'
do
before
do
create
(
:protected_branch
,
:no_one_can_push
,
name:
build
.
ref
,
project:
project
)
end
it
'raises an error'
do
expect
{
service
.
execute
(
build
)
}
.
to
raise_error
Gitlab
::
Access
::
AccessDeniedError
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