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
433b4581
Commit
433b4581
authored
Feb 29, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve commit status API specs (refactoring)
parent
dcc67ac1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
76 additions
and
41 deletions
+76
-41
spec/requests/api/commit_status_spec.rb
spec/requests/api/commit_status_spec.rb
+76
-41
No files found.
spec/requests/api/commit_status_spec.rb
View file @
433b4581
...
...
@@ -11,6 +11,8 @@ describe API::CommitStatus, api: true do
let
(
:developer
)
{
create_user
(
ProjectMember
::
DEVELOPER
)
}
describe
"GET /projects/:id/repository/commits/:sha/statuses"
do
let
(
:get_url
)
{
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses"
}
context
'ci commit exists'
do
let!
(
:ci_commit
)
{
project
.
ensure_ci_commit
(
commit
.
id
)
}
...
...
@@ -46,46 +48,56 @@ describe API::CommitStatus, api: true do
create
(
:commit_status
,
commit:
ci_commit
,
status:
'success'
)
end
it
"should return latest commit statuses"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses"
,
reporter
)
expect
(
response
.
status
).
to
eq
(
200
)
context
'latest commit statuses'
do
before
{
get
api
(
get_url
,
reporter
)
}
it
'returns latest commit statuses'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status4
.
id
,
status5
.
id
,
status6
.
id
)
json_response
.
sort_by!
{
|
status
|
status
[
'id'
]
}
expect
(
json_response
.
map
{
|
status
|
status
[
'allow_failure'
]
}).
to
eq
([
true
,
false
,
false
,
false
])
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status4
.
id
,
status5
.
id
,
status6
.
id
)
json_response
.
sort_by!
{
|
status
|
status
[
'id'
]
}
expect
(
json_response
.
map
{
|
status
|
status
[
'allow_failure'
]
}).
to
eq
([
true
,
false
,
false
,
false
])
end
end
it
"should return all commit statuses"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses?all=1"
,
reporter
)
expect
(
response
.
status
).
to
eq
(
200
)
context
'all commit statuses'
do
before
{
get
api
(
get_url
,
reporter
),
all:
1
}
it
'returns all commit statuses'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status1
.
id
,
status2
.
id
,
status3
.
id
,
status4
.
id
,
status5
.
id
,
status6
.
id
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status1
.
id
,
status2
.
id
,
status3
.
id
,
status4
.
id
,
status5
.
id
,
status6
.
id
)
end
end
it
"should return latest commit statuses for specific ref"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses?ref=develop"
,
reporter
)
expect
(
response
.
status
).
to
eq
(
200
)
context
'latest commit statuses for specific ref'
do
before
{
get
api
(
get_url
,
reporter
),
ref:
'develop'
}
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status5
.
id
)
it
'returns latest commit statuses for specific ref'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status5
.
id
)
end
end
it
"should return latest commit statuses for specific name"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses?name=coverage"
,
reporter
)
expect
(
response
.
status
).
to
eq
(
200
)
context
'latest commit statues for specific name'
do
before
{
get
api
(
get_url
,
reporter
),
name:
'coverage'
}
it
'return latest commit statuses for specific name'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status4
.
id
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status4
.
id
)
end
end
end
end
context
'ci commit does not exist'
do
before
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses"
,
reporter
)
end
before
{
get
api
(
get_url
,
reporter
)
}
it
'returns empty array'
do
expect
(
response
.
status
).
to
eq
200
...
...
@@ -95,15 +107,17 @@ describe API::CommitStatus, api: true do
end
context
"guest user"
do
before
{
get
api
(
get_url
,
guest
)
}
it
"should not return project commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses"
,
guest
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
"unauthorized user"
do
before
{
get
api
(
get_url
)
}
it
"should not return project commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/statuses"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
...
...
@@ -113,9 +127,10 @@ describe API::CommitStatus, api: true do
let
(
:post_url
)
{
"/projects/
#{
project
.
id
}
/statuses/
#{
commit
.
id
}
"
}
context
'developer user'
do
context
'should create commit status'
do
it
'with only required parameters'
do
post
api
(
post_url
,
developer
),
state:
'success'
context
'only required parameters'
do
before
{
post
api
(
post_url
,
developer
),
state:
'success'
}
it
'creates commit status'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'sha'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
[
'status'
]).
to
eq
(
'success'
)
...
...
@@ -124,9 +139,17 @@ describe API::CommitStatus, api: true do
expect
(
json_response
[
'target_url'
]).
to
be_nil
expect
(
json_response
[
'description'
]).
to
be_nil
end
end
context
'with all optional parameters'
do
before
do
optional_params
=
{
state:
'success'
,
context:
'coverage'
,
ref:
'develop'
,
target_url:
'url'
,
description:
'test'
}
post
api
(
post_url
,
developer
),
optional_params
end
it
'with all optional parameters'
do
post
api
(
post_url
,
developer
),
state:
'success'
,
context:
'coverage'
,
ref:
'develop'
,
target_url:
'url'
,
description:
'test'
it
'creates commit status'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
'sha'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
[
'status'
]).
to
eq
(
'success'
)
...
...
@@ -137,41 +160,53 @@ describe API::CommitStatus, api: true do
end
end
context
'should not create commit status'
do
it
'with invalid state'
do
post
api
(
post_url
,
developer
),
state:
'invalid'
context
'invalid status'
do
before
{
post
api
(
post_url
,
developer
),
state:
'invalid'
}
it
'does not create commit status'
do
expect
(
response
.
status
).
to
eq
(
400
)
end
end
context
'request without state'
do
before
{
post
api
(
post_url
,
developer
)
}
it
'without state'
do
post
api
(
post_url
,
developer
)
it
'does not create commit status'
do
expect
(
response
.
status
).
to
eq
(
400
)
end
end
it
'invalid commit'
do
context
'invalid commit'
do
before
do
post
api
(
"/projects/
#{
project
.
id
}
/statuses/invalid_sha"
,
developer
),
state:
'running'
end
it
'returns not found error'
do
expect
(
response
.
status
).
to
eq
(
404
)
end
end
end
context
'reporter user'
do
before
{
post
api
(
post_url
,
reporter
)
}
it
'should not create commit status'
do
post
api
(
post_url
,
reporter
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'guest user'
do
before
{
post
api
(
post_url
,
guest
)
}
it
'should not create commit status'
do
post
api
(
post_url
,
guest
)
expect
(
response
.
status
).
to
eq
(
403
)
end
end
context
'unauthorized user'
do
before
{
post
api
(
post_url
)
}
it
'should not create commit status'
do
post
api
(
post_url
)
expect
(
response
.
status
).
to
eq
(
401
)
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