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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
abca19da
Commit
abca19da
authored
Jun 27, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use HTTP matchers if possible
parent
e0e32562
Changes
67
Show whitespace changes
Inline
Side-by-side
Showing
67 changed files
with
1015 additions
and
1015 deletions
+1015
-1015
spec/controllers/admin/impersonations_controller_spec.rb
spec/controllers/admin/impersonations_controller_spec.rb
+3
-3
spec/controllers/admin/spam_logs_controller_spec.rb
spec/controllers/admin/spam_logs_controller_spec.rb
+3
-3
spec/controllers/admin/users_controller_spec.rb
spec/controllers/admin/users_controller_spec.rb
+1
-1
spec/controllers/application_controller_spec.rb
spec/controllers/application_controller_spec.rb
+4
-4
spec/controllers/autocomplete_controller_spec.rb
spec/controllers/autocomplete_controller_spec.rb
+5
-5
spec/controllers/commit_controller_spec.rb
spec/controllers/commit_controller_spec.rb
+2
-2
spec/controllers/groups/group_members_controller_spec.rb
spec/controllers/groups/group_members_controller_spec.rb
+7
-7
spec/controllers/health_check_controller_spec.rb
spec/controllers/health_check_controller_spec.rb
+5
-5
spec/controllers/invites_controller_spec.rb
spec/controllers/invites_controller_spec.rb
+2
-2
spec/controllers/namespaces_controller_spec.rb
spec/controllers/namespaces_controller_spec.rb
+2
-2
spec/controllers/notification_settings_controller_spec.rb
spec/controllers/notification_settings_controller_spec.rb
+2
-2
spec/controllers/oauth/applications_controller_spec.rb
spec/controllers/oauth/applications_controller_spec.rb
+2
-2
spec/controllers/profiles/accounts_controller_spec.rb
spec/controllers/profiles/accounts_controller_spec.rb
+1
-1
spec/controllers/projects/branches_controller_spec.rb
spec/controllers/projects/branches_controller_spec.rb
+5
-5
spec/controllers/projects/issues_controller_spec.rb
spec/controllers/projects/issues_controller_spec.rb
+6
-6
spec/controllers/projects/merge_requests_controller_spec.rb
spec/controllers/projects/merge_requests_controller_spec.rb
+2
-2
spec/controllers/projects/notes_controller_spec.rb
spec/controllers/projects/notes_controller_spec.rb
+2
-2
spec/controllers/projects/project_members_controller_spec.rb
spec/controllers/projects/project_members_controller_spec.rb
+7
-7
spec/controllers/projects/raw_controller_spec.rb
spec/controllers/projects/raw_controller_spec.rb
+4
-4
spec/controllers/projects/repositories_controller_spec.rb
spec/controllers/projects/repositories_controller_spec.rb
+1
-1
spec/controllers/projects/snippets_controller_spec.rb
spec/controllers/projects/snippets_controller_spec.rb
+8
-8
spec/controllers/projects/todo_controller_spec.rb
spec/controllers/projects/todo_controller_spec.rb
+6
-6
spec/controllers/projects/tree_controller_spec.rb
spec/controllers/projects/tree_controller_spec.rb
+1
-1
spec/controllers/projects/uploads_controller_spec.rb
spec/controllers/projects/uploads_controller_spec.rb
+12
-12
spec/controllers/projects_controller_spec.rb
spec/controllers/projects_controller_spec.rb
+5
-5
spec/controllers/snippets_controller_spec.rb
spec/controllers/snippets_controller_spec.rb
+14
-14
spec/controllers/uploads_controller_spec.rb
spec/controllers/uploads_controller_spec.rb
+14
-14
spec/controllers/users_controller_spec.rb
spec/controllers/users_controller_spec.rb
+5
-5
spec/requests/api/award_emoji_spec.rb
spec/requests/api/award_emoji_spec.rb
+19
-19
spec/requests/api/branches_spec.rb
spec/requests/api/branches_spec.rb
+21
-21
spec/requests/api/builds_spec.rb
spec/requests/api/builds_spec.rb
+20
-20
spec/requests/api/commit_statuses_spec.rb
spec/requests/api/commit_statuses_spec.rb
+14
-14
spec/requests/api/commits_spec.rb
spec/requests/api/commits_spec.rb
+19
-19
spec/requests/api/doorkeeper_access_spec.rb
spec/requests/api/doorkeeper_access_spec.rb
+3
-3
spec/requests/api/files_spec.rb
spec/requests/api/files_spec.rb
+12
-12
spec/requests/api/fork_spec.rb
spec/requests/api/fork_spec.rb
+6
-6
spec/requests/api/group_members_spec.rb
spec/requests/api/group_members_spec.rb
+18
-18
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+38
-38
spec/requests/api/internal_spec.rb
spec/requests/api/internal_spec.rb
+17
-17
spec/requests/api/issues_spec.rb
spec/requests/api/issues_spec.rb
+84
-84
spec/requests/api/keys_spec.rb
spec/requests/api/keys_spec.rb
+3
-3
spec/requests/api/labels_spec.rb
spec/requests/api/labels_spec.rb
+30
-30
spec/requests/api/licenses_spec.rb
spec/requests/api/licenses_spec.rb
+3
-3
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+63
-63
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+18
-18
spec/requests/api/namespaces_spec.rb
spec/requests/api/namespaces_spec.rb
+5
-5
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+41
-41
spec/requests/api/project_hooks_spec.rb
spec/requests/api/project_hooks_spec.rb
+18
-18
spec/requests/api/project_members_spec.rb
spec/requests/api/project_members_spec.rb
+18
-18
spec/requests/api/project_snippets_spec.rb
spec/requests/api/project_snippets_spec.rb
+6
-6
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+85
-85
spec/requests/api/repositories_spec.rb
spec/requests/api/repositories_spec.rb
+20
-20
spec/requests/api/runners_spec.rb
spec/requests/api/runners_spec.rb
+49
-49
spec/requests/api/services_spec.rb
spec/requests/api/services_spec.rb
+6
-6
spec/requests/api/session_spec.rb
spec/requests/api/session_spec.rb
+4
-4
spec/requests/api/settings_spec.rb
spec/requests/api/settings_spec.rb
+2
-2
spec/requests/api/sidekiq_metrics_spec.rb
spec/requests/api/sidekiq_metrics_spec.rb
+4
-4
spec/requests/api/system_hooks_spec.rb
spec/requests/api/system_hooks_spec.rb
+7
-7
spec/requests/api/tags_spec.rb
spec/requests/api/tags_spec.rb
+20
-20
spec/requests/api/templates_spec.rb
spec/requests/api/templates_spec.rb
+3
-3
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+22
-22
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+101
-101
spec/requests/api/variables_spec.rb
spec/requests/api/variables_spec.rb
+19
-19
spec/requests/ci/api/builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+29
-29
spec/requests/ci/api/triggers_spec.rb
spec/requests/ci/api/triggers_spec.rb
+8
-8
spec/requests/git_http_spec.rb
spec/requests/git_http_spec.rb
+24
-24
spec/requests/jwt_controller_spec.rb
spec/requests/jwt_controller_spec.rb
+5
-5
No files found.
spec/controllers/admin/impersonations_controller_spec.rb
View file @
abca19da
...
...
@@ -22,7 +22,7 @@ describe Admin::ImpersonationsController do
it
"responds with status 404"
do
delete
:destroy
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"doesn't sign us in"
do
...
...
@@ -46,7 +46,7 @@ describe Admin::ImpersonationsController do
it
"responds with status 404"
do
delete
:destroy
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"doesn't sign us in as the impersonator"
do
...
...
@@ -65,7 +65,7 @@ describe Admin::ImpersonationsController do
it
"responds with status 404"
do
delete
:destroy
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"doesn't sign us in as the impersonator"
do
...
...
spec/controllers/admin/spam_logs_controller_spec.rb
View file @
abca19da
...
...
@@ -14,7 +14,7 @@ describe Admin::SpamLogsController do
it
'lists all spam logs'
do
get
:index
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -22,14 +22,14 @@ describe Admin::SpamLogsController do
it
'removes only the spam log when removing log'
do
expect
{
delete
:destroy
,
id:
first_spam
.
id
}.
to
change
{
SpamLog
.
count
}.
by
(
-
1
)
expect
(
User
.
find
(
user
.
id
)).
to
be_truthy
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'removes user and his spam logs when removing the user'
do
delete
:destroy
,
id:
first_spam
.
id
,
remove_user:
true
expect
(
flash
[
:notice
]).
to
eq
"User
#{
user
.
username
}
was successfully removed."
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
SpamLog
.
count
).
to
eq
(
0
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
...
...
spec/controllers/admin/users_controller_spec.rb
View file @
abca19da
...
...
@@ -17,7 +17,7 @@ describe Admin::UsersController do
it
'deletes user'
do
delete
:destroy
,
id:
user
.
username
,
format: :json
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_exception
(
ActiveRecord
::
RecordNotFound
)
end
end
...
...
spec/controllers/application_controller_spec.rb
View file @
abca19da
...
...
@@ -44,7 +44,7 @@ describe ApplicationController do
context
"when the 'private_token' param is populated with the private token"
do
it
"logs the user in"
do
get
:index
,
private_token:
user
.
private_token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
body
).
to
eq
(
"authenticated"
)
end
end
...
...
@@ -54,7 +54,7 @@ describe ApplicationController do
it
"logs the user in"
do
@request
.
headers
[
'PRIVATE-TOKEN'
]
=
user
.
private_token
get
:index
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
body
).
to
eq
(
"authenticated"
)
end
end
...
...
@@ -80,7 +80,7 @@ describe ApplicationController do
context
"when the 'personal_access_token' param is populated with the personal access token"
do
it
"logs the user in"
do
get
:index
,
private_token:
personal_access_token
.
token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
body
).
to
eq
(
'authenticated'
)
end
end
...
...
@@ -89,7 +89,7 @@ describe ApplicationController do
it
"logs the user in"
do
@request
.
headers
[
"PRIVATE-TOKEN"
]
=
personal_access_token
.
token
get
:index
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
body
).
to
eq
(
'authenticated'
)
end
end
...
...
spec/controllers/autocomplete_controller_spec.rb
View file @
abca19da
...
...
@@ -29,7 +29,7 @@ describe AutocompleteController do
get
(
:users
,
project_id:
'unknown'
)
end
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
end
...
...
@@ -58,7 +58,7 @@ describe AutocompleteController do
get
(
:users
,
group_id:
'unknown'
)
end
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
end
...
...
@@ -114,7 +114,7 @@ describe AutocompleteController do
get
(
:users
,
project_id:
project
.
id
)
end
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
describe
'GET #users with unknown project'
do
...
...
@@ -122,7 +122,7 @@ describe AutocompleteController do
get
(
:users
,
project_id:
'unknown'
)
end
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
describe
'GET #users with inaccessible group'
do
...
...
@@ -131,7 +131,7 @@ describe AutocompleteController do
get
(
:users
,
group_id:
user
.
namespace
.
id
)
end
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
describe
'GET #users with no project'
do
...
...
spec/controllers/commit_controller_spec.rb
View file @
abca19da
...
...
@@ -155,7 +155,7 @@ describe Projects::CommitController do
id:
commit
.
id
)
expect
(
response
).
not_to
be_success
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -204,7 +204,7 @@ describe Projects::CommitController do
id:
master_pickable_commit
.
id
)
expect
(
response
).
not_to
be_success
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
spec/controllers/groups/group_members_controller_spec.rb
View file @
abca19da
...
...
@@ -13,7 +13,7 @@ describe Groups::GroupMembersController do
it
'renders index with group members'
do
get
:index
,
group_id:
group
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
render_template
(
:index
)
end
end
...
...
@@ -26,7 +26,7 @@ describe Groups::GroupMembersController do
delete
:destroy
,
group_id:
group
,
id:
42
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -48,7 +48,7 @@ describe Groups::GroupMembersController do
delete
:destroy
,
group_id:
group
,
id:
member
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
group
.
users
).
to
include
group_user
end
end
...
...
@@ -89,7 +89,7 @@ describe Groups::GroupMembersController do
it
'returns 403'
do
delete
:leave
,
group_id:
group
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -118,7 +118,7 @@ describe Groups::GroupMembersController do
it
'cannot removes himself from the group'
do
delete
:leave
,
group_id:
group
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -166,7 +166,7 @@ describe Groups::GroupMembersController do
post
:approve_access_request
,
group_id:
group
,
id:
42
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -188,7 +188,7 @@ describe Groups::GroupMembersController do
post
:approve_access_request
,
group_id:
group
,
id:
member
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
group
.
users
).
not_to
include
group_requester
end
end
...
...
spec/controllers/health_check_controller_spec.rb
View file @
abca19da
...
...
@@ -65,21 +65,21 @@ describe HealthCheckController do
it
'supports passing the token in the header'
do
request
.
headers
[
'TOKEN'
]
=
token
get
:index
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
).
to
have_http_status
(
500
)
expect
(
response
.
content_type
).
to
eq
'text/plain'
expect
(
response
.
body
).
to
include
(
'The server is on fire'
)
end
it
'supports failure plaintest response'
do
get
:index
,
token:
token
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
).
to
have_http_status
(
500
)
expect
(
response
.
content_type
).
to
eq
'text/plain'
expect
(
response
.
body
).
to
include
(
'The server is on fire'
)
end
it
'supports failure json response'
do
get
:index
,
token:
token
,
format: :json
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
).
to
have_http_status
(
500
)
expect
(
response
.
content_type
).
to
eq
'application/json'
expect
(
json_response
[
'healthy'
]).
to
be
false
expect
(
json_response
[
'message'
]).
to
include
(
'The server is on fire'
)
...
...
@@ -87,7 +87,7 @@ describe HealthCheckController do
it
'supports failure xml response'
do
get
:index
,
token:
token
,
format: :xml
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
).
to
have_http_status
(
500
)
expect
(
response
.
content_type
).
to
eq
'application/xml'
expect
(
xml_response
[
'healthy'
]).
to
be
false
expect
(
xml_response
[
'message'
]).
to
include
(
'The server is on fire'
)
...
...
@@ -95,7 +95,7 @@ describe HealthCheckController do
it
'supports failure responses for specific checks'
do
get
:index
,
token:
token
,
checks:
'email'
,
format: :json
expect
(
response
.
status
).
to
eq
(
500
)
expect
(
response
).
to
have_http_status
(
500
)
expect
(
response
.
content_type
).
to
eq
'application/json'
expect
(
json_response
[
'healthy'
]).
to
be
false
expect
(
json_response
[
'message'
]).
to
include
(
'Email is on fire'
)
...
...
spec/controllers/invites_controller_spec.rb
View file @
abca19da
...
...
@@ -15,7 +15,7 @@ describe InvitesController do
get
:accept
,
id:
token
member
.
reload
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
member
.
user
).
to
eq
(
user
)
expect
(
flash
[
:notice
]).
to
include
'You have been granted'
end
...
...
@@ -26,7 +26,7 @@ describe InvitesController do
get
:decline
,
id:
token
expect
{
member
.
reload
}.
to
raise_error
ActiveRecord
::
RecordNotFound
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
flash
[
:notice
]).
to
include
'You have declined the invitation to join'
end
end
...
...
spec/controllers/namespaces_controller_spec.rb
View file @
abca19da
...
...
@@ -86,7 +86,7 @@ describe NamespacesController do
it
"responds with status 404"
do
get
:show
,
id:
group
.
path
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -102,7 +102,7 @@ describe NamespacesController do
it
"responds with status 404"
do
get
:show
,
id:
"doesntexist"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
spec/controllers/notification_settings_controller_spec.rb
View file @
abca19da
...
...
@@ -60,7 +60,7 @@ describe NotificationSettingsController do
project:
{
id:
private_project
.
id
},
notification_setting:
{
level: :participating
}
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -118,7 +118,7 @@ describe NotificationSettingsController do
id:
notification_setting
,
notification_setting:
{
level: :participating
}
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/oauth/applications_controller_spec.rb
View file @
abca19da
...
...
@@ -12,7 +12,7 @@ describe Oauth::ApplicationsController do
it
'shows list of applications'
do
get
:index
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'redirects back to profile page if OAuth applications are disabled'
do
...
...
@@ -21,7 +21,7 @@ describe Oauth::ApplicationsController do
get
:index
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
response
).
to
redirect_to
(
profile_path
)
end
end
...
...
spec/controllers/profiles/accounts_controller_spec.rb
View file @
abca19da
...
...
@@ -13,7 +13,7 @@ describe Profiles::AccountsController do
delete
:unlink
,
provider:
'saml'
updated_user
=
User
.
find
(
user
.
id
)
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
updated_user
.
identities
.
size
).
to
eq
(
1
)
expect
(
updated_user
.
identities
).
to
include
(
identity
)
end
...
...
spec/controllers/projects/branches_controller_spec.rb
View file @
abca19da
...
...
@@ -103,7 +103,7 @@ describe Projects::BranchesController do
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
expect
(
response
.
status
).
to
eq
(
303
)
expect
(
response
).
to
have_http_status
(
303
)
end
end
...
...
@@ -121,24 +121,24 @@ describe Projects::BranchesController do
context
"valid branch name, valid source"
do
let
(
:branch
)
{
"feature"
}
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
end
context
"valid branch name with unencoded slashes"
do
let
(
:branch
)
{
"improve/awesome"
}
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
end
context
"valid branch name with encoded slashes"
do
let
(
:branch
)
{
"improve%2Fawesome"
}
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
end
context
"invalid branch name, valid ref"
do
let
(
:branch
)
{
"no-branch"
}
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
end
end
spec/controllers/projects/issues_controller_spec.rb
View file @
abca19da
...
...
@@ -14,7 +14,7 @@ describe Projects::IssuesController do
it
"returns index"
do
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"return 301 if request path doesn't match project path"
do
...
...
@@ -28,7 +28,7 @@ describe Projects::IssuesController do
project
.
save
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"returns 404 when external issue tracker is enabled"
do
...
...
@@ -36,7 +36,7 @@ describe Projects::IssuesController do
allow
(
project
).
to
receive
(
:default_issues_tracker?
).
and_return
(
false
)
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -248,7 +248,7 @@ describe Projects::IssuesController do
before
{
sign_in
(
user
)
}
it
"rejects a developer to destroy an issue"
do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
issue
.
iid
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -262,7 +262,7 @@ describe Projects::IssuesController do
it
"deletes the issue"
do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
issue
.
iid
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
controller
).
to
set_flash
[
:notice
].
to
(
/The issue was successfully deleted\./
).
now
end
end
...
...
@@ -280,7 +280,7 @@ describe Projects::IssuesController do
project_id:
project
.
path
,
id:
issue
.
iid
,
name:
"thumbsup"
)
end
.
to
change
{
issue
.
award_emoji
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
spec/controllers/projects/merge_requests_controller_spec.rb
View file @
abca19da
...
...
@@ -284,7 +284,7 @@ describe Projects::MergeRequestsController do
it
"denies access to users unless they're admin or project owner"
do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
merge_request
.
iid
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
"when the user is owner"
do
...
...
@@ -297,7 +297,7 @@ describe Projects::MergeRequestsController do
it
"deletes the merge request"
do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
merge_request
.
iid
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
controller
).
to
set_flash
[
:notice
].
to
(
/The merge request was successfully deleted\./
).
now
end
end
...
...
spec/controllers/projects/notes_controller_spec.rb
View file @
abca19da
...
...
@@ -18,7 +18,7 @@ describe Projects::NotesController do
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
end
.
to
change
{
note
.
award_emoji
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"removes the already awarded emoji"
do
...
...
@@ -30,7 +30,7 @@ describe Projects::NotesController do
project_id:
project
.
path
,
id:
note
.
id
,
name:
"thumbsup"
)
end
.
to
change
{
AwardEmoji
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
spec/controllers/projects/project_members_controller_spec.rb
View file @
abca19da
...
...
@@ -58,7 +58,7 @@ describe Projects::ProjectMembersController do
get
:index
,
namespace_id:
project
.
namespace
,
project_id:
project
end
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
end
end
...
...
@@ -71,7 +71,7 @@ describe Projects::ProjectMembersController do
project_id:
project
,
id:
42
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -94,7 +94,7 @@ describe Projects::ProjectMembersController do
project_id:
project
,
id:
member
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
project
.
users
).
to
include
team_user
end
end
...
...
@@ -139,7 +139,7 @@ describe Projects::ProjectMembersController do
delete
:leave
,
namespace_id:
project
.
namespace
,
project_id:
project
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -171,7 +171,7 @@ describe Projects::ProjectMembersController do
delete
:leave
,
namespace_id:
project
.
namespace
,
project_id:
project
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -224,7 +224,7 @@ describe Projects::ProjectMembersController do
project_id:
project
,
id:
42
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -247,7 +247,7 @@ describe Projects::ProjectMembersController do
project_id:
project
,
id:
member
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
project
.
users
).
not_to
include
team_requester
end
end
...
...
spec/controllers/projects/raw_controller_spec.rb
View file @
abca19da
...
...
@@ -13,7 +13,7 @@ describe Projects::RawController do
project_id:
public_project
.
to_param
,
id:
id
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'text/plain; charset=utf-8'
)
expect
(
response
.
header
[
'Content-Disposition'
]).
to
eq
(
"inline"
)
...
...
@@ -30,7 +30,7 @@ describe Projects::RawController do
project_id:
public_project
.
to_param
,
id:
id
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
header
[
'Content-Type'
]).
to
eq
(
'image/jpeg'
)
expect
(
response
.
header
[
Gitlab
::
Workhorse
::
SEND_DATA_HEADER
]).
to
start_with
(
"git-blob:"
)
end
...
...
@@ -54,7 +54,7 @@ describe Projects::RawController do
project_id:
public_project
.
to_param
,
id:
id
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -65,7 +65,7 @@ describe Projects::RawController do
project_id:
public_project
.
to_param
,
id:
id
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/projects/repositories_controller_spec.rb
View file @
abca19da
...
...
@@ -36,7 +36,7 @@ describe Projects::RepositoriesController do
it
"renders Not Found"
do
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/projects/snippets_controller_spec.rb
View file @
abca19da
...
...
@@ -19,7 +19,7 @@ describe Projects::SnippetsController do
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
expect
(
assigns
(
:snippets
)).
not_to
include
(
project_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -30,7 +30,7 @@ describe Projects::SnippetsController do
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
expect
(
assigns
(
:snippets
)).
to
include
(
project_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -41,7 +41,7 @@ describe Projects::SnippetsController do
get
:index
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
expect
(
assigns
(
:snippets
)).
to
include
(
project_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -56,7 +56,7 @@ describe Projects::SnippetsController do
it
'responds with status 404'
do
get
action
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
project_snippet
.
to_param
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -67,7 +67,7 @@ describe Projects::SnippetsController do
get
action
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
project_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
project_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -78,7 +78,7 @@ describe Projects::SnippetsController do
get
action
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
project_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
project_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -88,7 +88,7 @@ describe Projects::SnippetsController do
it
'responds with status 404'
do
get
action
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
42
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -98,7 +98,7 @@ describe Projects::SnippetsController do
it
'responds with status 404'
do
get
action
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
id:
42
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/projects/todo_controller_spec.rb
View file @
abca19da
...
...
@@ -22,7 +22,7 @@ describe Projects::TodosController do
issuable_type:
'issue'
)
end
.
to
change
{
user
.
todos
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -36,7 +36,7 @@ describe Projects::TodosController do
issuable_type:
'issue'
)
end
.
to
change
{
user
.
todos
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should not create todo for issue when user not logged in'
do
...
...
@@ -47,7 +47,7 @@ describe Projects::TodosController do
issuable_type:
'issue'
)
end
.
to
change
{
user
.
todos
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
end
end
end
...
...
@@ -69,7 +69,7 @@ describe Projects::TodosController do
issuable_type:
'merge_request'
)
end
.
to
change
{
user
.
todos
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -83,7 +83,7 @@ describe Projects::TodosController do
issuable_type:
'merge_request'
)
end
.
to
change
{
user
.
todos
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should not create todo for merge request user has no access to'
do
...
...
@@ -94,7 +94,7 @@ describe Projects::TodosController do
issuable_type:
'merge_request'
)
end
.
to
change
{
user
.
todos
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
end
end
end
...
...
spec/controllers/projects/tree_controller_spec.rb
View file @
abca19da
...
...
@@ -64,7 +64,7 @@ describe Projects::TreeController do
context
"valid SHA commit ID with path"
do
let
(
:id
)
{
'6d39438/.gitignore'
}
it
{
expect
(
response
.
status
).
to
eq
(
302
)
}
it
{
expect
(
response
).
to
have_http_status
(
302
)
}
end
end
...
...
spec/controllers/projects/uploads_controller_spec.rb
View file @
abca19da
...
...
@@ -18,7 +18,7 @@ describe Projects::UploadsController do
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
format: :json
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
...
...
@@ -79,7 +79,7 @@ describe Projects::UploadsController do
it
"responds with status 200"
do
go
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -87,7 +87,7 @@ describe Projects::UploadsController do
it
"responds with status 404"
do
go
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -106,7 +106,7 @@ describe Projects::UploadsController do
it
"responds with status 200"
do
go
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -114,7 +114,7 @@ describe Projects::UploadsController do
it
"responds with status 404"
do
go
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -140,7 +140,7 @@ describe Projects::UploadsController do
it
"responds with status 200"
do
go
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -192,7 +192,7 @@ describe Projects::UploadsController do
it
"responds with status 200"
do
go
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -224,7 +224,7 @@ describe Projects::UploadsController do
it
"responds with status 200"
do
go
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -232,7 +232,7 @@ describe Projects::UploadsController do
it
"responds with status 404"
do
go
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -253,7 +253,7 @@ describe Projects::UploadsController do
it
"responds with status 200"
do
go
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -261,7 +261,7 @@ describe Projects::UploadsController do
it
"responds with status 404"
do
go
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -270,7 +270,7 @@ describe Projects::UploadsController do
it
"responds with status 404"
do
go
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/projects_controller_spec.rb
View file @
abca19da
...
...
@@ -77,7 +77,7 @@ describe ProjectsController do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
expect
(
assigns
(
:project
)).
to
eq
(
public_project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -101,7 +101,7 @@ describe ProjectsController do
get
:show
,
namespace_id:
public_project
.
namespace
.
path
,
id:
public_project
.
path
.
upcase
expect
(
assigns
(
:project
)).
to
eq
(
other_project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -146,7 +146,7 @@ describe ProjectsController do
expect
(
project
.
repository
.
path
).
to
include
(
new_path
)
expect
(
assigns
(
:repository
).
path
).
to
eq
(
project
.
repository
.
path
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -161,7 +161,7 @@ describe ProjectsController do
delete
:destroy
,
namespace_id:
project
.
namespace
.
path
,
id:
project
.
path
expect
{
Project
.
find
(
orig_id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
response
).
to
redirect_to
(
dashboard_projects_path
)
end
end
...
...
@@ -234,7 +234,7 @@ describe ProjectsController do
delete
(
:remove_fork
,
namespace_id:
project
.
namespace
.
to_param
,
id:
project
.
to_param
,
format: :js
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
spec/controllers/snippets_controller_spec.rb
View file @
abca19da
...
...
@@ -19,7 +19,7 @@ describe SnippetsController do
it
'responds with status 404'
do
get
:show
,
id:
other_personal_snippet
.
to_param
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -28,7 +28,7 @@ describe SnippetsController do
get
:show
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -54,7 +54,7 @@ describe SnippetsController do
get
:show
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -79,7 +79,7 @@ describe SnippetsController do
get
:show
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -88,7 +88,7 @@ describe SnippetsController do
get
:show
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -102,7 +102,7 @@ describe SnippetsController do
it
'responds with status 404'
do
get
:show
,
id:
'doesntexist'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -110,7 +110,7 @@ describe SnippetsController do
it
'responds with status 404'
do
get
:show
,
id:
'doesntexist'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -134,7 +134,7 @@ describe SnippetsController do
it
'responds with status 404'
do
get
:raw
,
id:
other_personal_snippet
.
to_param
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -143,7 +143,7 @@ describe SnippetsController do
get
:raw
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -169,7 +169,7 @@ describe SnippetsController do
get
:raw
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -194,7 +194,7 @@ describe SnippetsController do
get
:raw
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -203,7 +203,7 @@ describe SnippetsController do
get
:raw
,
id:
personal_snippet
.
to_param
expect
(
assigns
(
:snippet
)).
to
eq
(
personal_snippet
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -217,7 +217,7 @@ describe SnippetsController do
it
'responds with status 404'
do
get
:raw
,
id:
'doesntexist'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -225,7 +225,7 @@ describe SnippetsController do
it
'responds with status 404'
do
get
:raw
,
id:
'doesntexist'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/uploads_controller_spec.rb
View file @
abca19da
...
...
@@ -26,7 +26,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"user"
,
mounted_as:
"avatar"
,
id:
user
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -35,7 +35,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"user"
,
mounted_as:
"avatar"
,
id:
user
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -52,7 +52,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"project"
,
mounted_as:
"avatar"
,
id:
project
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -64,7 +64,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"project"
,
mounted_as:
"avatar"
,
id:
project
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -109,7 +109,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"project"
,
mounted_as:
"avatar"
,
id:
project
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -118,7 +118,7 @@ describe UploadsController do
it
"responds with status 404"
do
get
:show
,
model:
"project"
,
mounted_as:
"avatar"
,
id:
project
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -133,7 +133,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"group"
,
mounted_as:
"avatar"
,
id:
group
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -145,7 +145,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"group"
,
mounted_as:
"avatar"
,
id:
group
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -181,7 +181,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"group"
,
mounted_as:
"avatar"
,
id:
group
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -190,7 +190,7 @@ describe UploadsController do
it
"responds with status 404"
do
get
:show
,
model:
"group"
,
mounted_as:
"avatar"
,
id:
group
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -210,7 +210,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"note"
,
mounted_as:
"attachment"
,
id:
note
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -222,7 +222,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"note"
,
mounted_as:
"attachment"
,
id:
note
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -267,7 +267,7 @@ describe UploadsController do
it
"responds with status 200"
do
get
:show
,
model:
"note"
,
mounted_as:
"attachment"
,
id:
note
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -276,7 +276,7 @@ describe UploadsController do
it
"responds with status 404"
do
get
:show
,
model:
"note"
,
mounted_as:
"attachment"
,
id:
note
.
id
,
filename:
"image.png"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/controllers/users_controller_spec.rb
View file @
abca19da
...
...
@@ -33,7 +33,7 @@ describe UsersController do
it
'renders the show template'
do
get
:show
,
username:
user
.
username
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
render_template
(
'show'
)
end
end
...
...
@@ -47,7 +47,7 @@ describe UsersController do
context
'when logged out'
do
it
'renders 404'
do
get
:show
,
username:
user
.
username
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -56,7 +56,7 @@ describe UsersController do
it
'renders show'
do
get
:show
,
username:
user
.
username
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
render_template
(
'show'
)
end
end
...
...
@@ -121,7 +121,7 @@ describe UsersController do
context
'format html'
do
it
'renders snippets page'
do
get
:snippets
,
username:
user
.
username
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
render_template
(
'show'
)
end
end
...
...
@@ -129,7 +129,7 @@ describe UsersController do
context
'format json'
do
it
'response with snippets json data'
do
get
:snippets
,
username:
user
.
username
,
format: :json
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
have_key
(
'html'
)
end
end
...
...
spec/requests/api/award_emoji_spec.rb
View file @
abca19da
...
...
@@ -17,7 +17,7 @@ describe API::API, api: true do
it
"returns an array of award_emoji"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
award_emoji
.
name
)
end
...
...
@@ -25,7 +25,7 @@ describe API::API, api: true do
it
"should return a 404 error when issue id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/12345/award_emoji"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -33,7 +33,7 @@ describe API::API, api: true do
it
"returns an array of award_emoji"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/award_emoji"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
downvote
.
name
)
end
...
...
@@ -45,7 +45,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/award_emoji"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -56,7 +56,7 @@ describe API::API, api: true do
it
'returns an array of award emoji'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/
#{
note
.
id
}
/award_emoji"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
rocket
.
name
)
end
...
...
@@ -68,7 +68,7 @@ describe API::API, api: true do
it
"returns the award emoji"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji/
#{
award_emoji
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
award_emoji
.
name
)
expect
(
json_response
[
'awardable_id'
]).
to
eq
(
issue
.
id
)
expect
(
json_response
[
'awardable_type'
]).
to
eq
(
"Issue"
)
...
...
@@ -77,7 +77,7 @@ describe API::API, api: true do
it
"returns a 404 error if the award is not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -85,7 +85,7 @@ describe API::API, api: true do
it
'returns the award emoji'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/award_emoji/
#{
downvote
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
downvote
.
name
)
expect
(
json_response
[
'awardable_id'
]).
to
eq
(
merge_request
.
id
)
expect
(
json_response
[
'awardable_type'
]).
to
eq
(
"MergeRequest"
)
...
...
@@ -98,7 +98,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/award_emoji/
#{
downvote
.
id
}
"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -109,7 +109,7 @@ describe API::API, api: true do
it
'returns an award emoji'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/
#{
note
.
id
}
/award_emoji/
#{
rocket
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
not_to
be_an
Array
expect
(
json_response
[
'name'
]).
to
eq
(
rocket
.
name
)
end
...
...
@@ -120,7 +120,7 @@ describe API::API, api: true do
it
"creates a new award emoji"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji"
,
user
),
name:
'blowfish'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'blowfish'
)
expect
(
json_response
[
'user'
][
'username'
]).
to
eq
(
user
.
username
)
end
...
...
@@ -128,13 +128,13 @@ describe API::API, api: true do
it
"should return a 400 bad request error if the name is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 401 unauthorized error if the user is not authenticated"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji"
),
name:
'thumbsup'
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -145,7 +145,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/
#{
note
.
id
}
/award_emoji"
,
user
),
name:
'rocket'
end
.
to
change
{
note
.
award_emoji
.
count
}.
from
(
0
).
to
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'user'
][
'username'
]).
to
eq
(
user
.
username
)
end
end
...
...
@@ -157,13 +157,13 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji/
#{
award_emoji
.
id
}
"
,
user
)
end
.
to
change
{
issue
.
award_emoji
.
count
}.
from
(
1
).
to
(
0
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns a 404 error when the award emoji can not be found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/award_emoji/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -173,13 +173,13 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/award_emoji/
#{
downvote
.
id
}
"
,
user
)
end
.
to
change
{
merge_request
.
award_emoji
.
count
}.
from
(
1
).
to
(
0
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'returns a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/notes/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -192,7 +192,7 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/
#{
note
.
id
}
/award_emoji/
#{
rocket
.
id
}
"
,
user
)
end
.
to
change
{
note
.
award_emoji
.
count
}.
from
(
1
).
to
(
0
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
spec/requests/api/branches_spec.rb
View file @
abca19da
...
...
@@ -17,7 +17,7 @@ describe API::API, api: true do
project
.
repository
.
expire_cache
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
branch_names
=
json_response
.
map
{
|
x
|
x
[
'name'
]
}
expect
(
branch_names
).
to
match_array
(
project
.
repository
.
branch_names
)
...
...
@@ -27,7 +27,7 @@ describe API::API, api: true do
describe
"GET /projects/:id/repository/branches/:branch"
do
it
"should return the branch information for a single branch"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
branch_name
)
expect
(
json_response
[
'commit'
][
'id'
]).
to
eq
(
branch_sha
)
...
...
@@ -36,19 +36,19 @@ describe API::API, api: true do
it
"should return a 403 error if guest"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should return a 404 error if branch is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/branches/unknown"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
"PUT /projects/:id/repository/branches/:branch/protect"
do
it
"should protect a single branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/protect"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
branch_name
)
expect
(
json_response
[
'commit'
][
'id'
]).
to
eq
(
branch_sha
)
...
...
@@ -57,25 +57,25 @@ describe API::API, api: true do
it
"should return a 404 error if branch not found"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/unknown/protect"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return a 403 error if guest"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/protect"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should return success when protect branch again"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/protect"
,
user
)
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/protect"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
describe
"PUT /projects/:id/repository/branches/:branch/unprotect"
do
it
"should unprotect a single branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/unprotect"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
branch_name
)
expect
(
json_response
[
'commit'
][
'id'
]).
to
eq
(
branch_sha
)
...
...
@@ -84,13 +84,13 @@ describe API::API, api: true do
it
"should return success when unprotect branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/unknown/unprotect"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return success when unprotect branch again"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/unprotect"
,
user
)
put
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
/unprotect"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -100,7 +100,7 @@ describe API::API, api: true do
branch_name:
'feature1'
,
ref:
branch_sha
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'feature1'
)
expect
(
json_response
[
'commit'
][
'id'
]).
to
eq
(
branch_sha
)
...
...
@@ -110,14 +110,14 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user2
),
branch_name:
branch_name
,
ref:
branch_sha
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should return 400 if branch name is invalid'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new design'
,
ref:
branch_sha
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Branch name is invalid'
)
end
...
...
@@ -125,12 +125,12 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design1'
,
ref:
branch_sha
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design1'
,
ref:
branch_sha
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Branch already exists'
)
end
...
...
@@ -138,7 +138,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/branches"
,
user
),
branch_name:
'new_design3'
,
ref:
'foo'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Invalid reference name'
)
end
end
...
...
@@ -150,25 +150,25 @@ describe API::API, api: true do
it
"should remove branch"
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'branch_name'
]).
to
eq
(
branch_name
)
end
it
'should return 404 if branch not exists'
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/branches/foobar"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should remove protected branch"
do
project
.
protected_branches
.
create
(
name:
branch_name
)
delete
api
(
"/projects/
#{
project
.
id
}
/repository/branches/
#{
branch_name
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Protected branch cant be removed'
)
end
it
"should not remove HEAD branch"
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/branches/master"
,
user
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Cannot remove HEAD branch'
)
end
end
...
...
spec/requests/api/builds_spec.rb
View file @
abca19da
...
...
@@ -19,7 +19,7 @@ describe API::API, api: true do
context
'authorized user'
do
it
'should return project builds'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
end
...
...
@@ -32,7 +32,7 @@ describe API::API, api: true do
let
(
:query
)
{
'scope=pending'
}
it
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
end
end
...
...
@@ -41,7 +41,7 @@ describe API::API, api: true do
let
(
:query
)
{
'scope[0]=pending&scope[1]=running'
}
it
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
end
end
...
...
@@ -49,7 +49,7 @@ describe API::API, api: true do
context
'respond 400 when scope contains invalid state'
do
let
(
:query
)
{
'scope[0]=pending&scope[1]=unknown_status'
}
it
{
expect
(
response
.
status
).
to
eq
(
400
)
}
it
{
expect
(
response
).
to
have_http_status
(
400
)
}
end
end
...
...
@@ -57,7 +57,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not return project builds'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -70,7 +70,7 @@ describe API::API, api: true do
context
'authorized user'
do
it
'should return project builds for specific commit'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
end
end
...
...
@@ -79,7 +79,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not return project builds'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -89,7 +89,7 @@ describe API::API, api: true do
context
'authorized user'
do
it
'should return specific build data'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'test'
)
end
end
...
...
@@ -98,7 +98,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not return specific build data'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -116,7 +116,7 @@ describe API::API, api: true do
end
it
'should return specific build artifacts'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
headers
).
to
include
(
download_headers
)
end
end
...
...
@@ -125,13 +125,13 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not return specific build artifacts'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
it
'should not return build artifacts if not uploaded'
do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -142,7 +142,7 @@ describe API::API, api: true do
context
'authorized user'
do
it
'should return specific build trace'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
body
).
to
eq
(
build
.
trace
)
end
end
...
...
@@ -151,7 +151,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not return specific build trace'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -162,7 +162,7 @@ describe API::API, api: true do
context
'authorized user'
do
context
'user with :update_build persmission'
do
it
'should cancel running or pending build'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
project
.
builds
.
first
.
status
).
to
eq
(
'canceled'
)
end
end
...
...
@@ -171,7 +171,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
user2
}
it
'should not cancel build'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -180,7 +180,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not cancel build'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -193,7 +193,7 @@ describe API::API, api: true do
context
'authorized user'
do
context
'user with :update_build permission'
do
it
'should retry non-running build'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
project
.
builds
.
first
.
status
).
to
eq
(
'canceled'
)
expect
(
json_response
[
'status'
]).
to
eq
(
'pending'
)
end
...
...
@@ -203,7 +203,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
user2
}
it
'should not retry build'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -212,7 +212,7 @@ describe API::API, api: true do
let
(
:api_user
)
{
nil
}
it
'should not retry build'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
spec/requests/api/commit_statuses_spec.rb
View file @
abca19da
...
...
@@ -41,7 +41,7 @@ describe API::CommitStatuses, api: true do
before
{
get
api
(
get_url
,
reporter
)
}
it
'returns latest commit statuses'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status4
.
id
,
status5
.
id
,
status6
.
id
)
...
...
@@ -54,7 +54,7 @@ describe API::CommitStatuses, api: true do
before
{
get
api
(
get_url
,
reporter
),
all:
1
}
it
'returns all commit statuses'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status1
.
id
,
status2
.
id
,
...
...
@@ -67,7 +67,7 @@ describe API::CommitStatuses, api: true do
before
{
get
api
(
get_url
,
reporter
),
ref:
'develop'
}
it
'returns latest commit statuses for specific ref'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status3
.
id
,
status5
.
id
)
...
...
@@ -78,7 +78,7 @@ describe API::CommitStatuses, api: true 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
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
statuses_id
).
to
contain_exactly
(
status4
.
id
,
status5
.
id
)
...
...
@@ -101,7 +101,7 @@ describe API::CommitStatuses, api: true do
before
{
get
api
(
get_url
,
guest
)
}
it
"should not return project commits"
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -109,7 +109,7 @@ describe API::CommitStatuses, api: true do
before
{
get
api
(
get_url
)
}
it
"should not return project commits"
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -122,7 +122,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
,
developer
),
state:
'success'
}
it
'creates commit status'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'sha'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
[
'status'
]).
to
eq
(
'success'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'default'
)
...
...
@@ -141,7 +141,7 @@ describe API::CommitStatuses, api: true do
end
it
'creates commit status'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'sha'
]).
to
eq
(
commit
.
id
)
expect
(
json_response
[
'status'
]).
to
eq
(
'success'
)
expect
(
json_response
[
'name'
]).
to
eq
(
'coverage'
)
...
...
@@ -155,7 +155,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
,
developer
),
state:
'invalid'
}
it
'does not create commit status'
do
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -163,7 +163,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
,
developer
)
}
it
'does not create commit status'
do
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -172,7 +172,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
,
developer
),
state:
'running'
}
it
'returns not found error'
do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -181,7 +181,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
,
reporter
)
}
it
'should not create commit status'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -189,7 +189,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
,
guest
)
}
it
'should not create commit status'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -197,7 +197,7 @@ describe API::CommitStatuses, api: true do
before
{
post
api
(
post_url
)
}
it
'should not create commit status'
do
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
spec/requests/api/commits_spec.rb
View file @
abca19da
...
...
@@ -19,7 +19,7 @@ describe API::API, api: true do
it
"should return project commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
project
.
repository
.
commit
.
id
)
...
...
@@ -29,7 +29,7 @@ describe API::API, api: true do
context
"unauthorized user"
do
it
"should not return project commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -63,7 +63,7 @@ describe API::API, api: true do
it
"should return an invalid parameter error message"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits?since=invalid-date"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
include
"
\"
since
\"
must be a timestamp in ISO 8601 format"
end
end
...
...
@@ -73,26 +73,26 @@ describe API::API, api: true do
context
"authorized user"
do
it
"should return a commit by sha"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
project
.
repository
.
commit
.
id
)
expect
(
json_response
[
'title'
]).
to
eq
(
project
.
repository
.
commit
.
title
)
end
it
"should return a 404 error if not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/invalid_sha"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return nil for commit without CI"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
be_nil
end
it
"should return status for CI"
do
pipeline
=
project
.
ensure_pipeline
(
project
.
repository
.
commit
.
sha
,
'master'
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
pipeline
.
status
)
end
end
...
...
@@ -100,7 +100,7 @@ describe API::API, api: true do
context
"unauthorized user"
do
it
"should not return the selected commit"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -111,7 +111,7 @@ describe API::API, api: true do
it
"should return the diff of the selected commit"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/diff"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
be
>=
1
...
...
@@ -120,14 +120,14 @@ describe API::API, api: true do
it
"should return a 404 error if invalid commit"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/invalid_sha/diff"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"unauthorized user"
do
it
"should not return the diff of the selected commit"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/diff"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -136,7 +136,7 @@ describe API::API, api: true do
context
'authorized user'
do
it
'should return merge_request comments'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/comments"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'note'
]).
to
eq
(
'a comment on a commit'
)
...
...
@@ -145,14 +145,14 @@ describe API::API, api: true do
it
'should return a 404 error if merge_request_id not found'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/1234ab/comments"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'unauthorized user'
do
it
'should not return the diff of the selected commit'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/1234ab/comments"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -161,7 +161,7 @@ describe API::API, api: true do
context
'authorized user'
do
it
'should return comment'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/comments"
,
user
),
note:
'My comment'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'note'
]).
to
eq
(
'My comment'
)
expect
(
json_response
[
'path'
]).
to
be_nil
expect
(
json_response
[
'line'
]).
to
be_nil
...
...
@@ -170,7 +170,7 @@ describe API::API, api: true do
it
'should return the inline comment'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/comments"
,
user
),
note:
'My comment'
,
path:
project
.
repository
.
commit
.
diffs
.
first
.
new_path
,
line:
7
,
line_type:
'new'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'note'
]).
to
eq
(
'My comment'
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
repository
.
commit
.
diffs
.
first
.
new_path
)
expect
(
json_response
[
'line'
]).
to
eq
(
7
)
...
...
@@ -179,19 +179,19 @@ describe API::API, api: true do
it
'should return 400 if note is missing'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/comments"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 404 if note is attached to non existent commit'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/commits/1234ab/comments"
,
user
),
note:
'My comment'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'unauthorized user'
do
it
'should not return the diff of the selected commit'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
project
.
repository
.
commit
.
id
}
/comments"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
spec/requests/api/doorkeeper_access_spec.rb
View file @
abca19da
...
...
@@ -11,21 +11,21 @@ describe API::API, api: true do
describe
"when unauthenticated"
do
it
"returns authentication success"
do
get
api
(
"/user"
),
access_token:
token
.
token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
describe
"when token invalid"
do
it
"returns authentication error"
do
get
api
(
"/user"
),
access_token:
"123a"
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
describe
"authorization by private token"
do
it
"returns authentication success"
do
get
api
(
"/user"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
spec/requests/api/files_spec.rb
View file @
abca19da
...
...
@@ -16,7 +16,7 @@ describe API::API, api: true do
}
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
params
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
file_path
)
expect
(
json_response
[
'file_name'
]).
to
eq
(
'popen.rb'
)
expect
(
json_response
[
'last_commit_id'
]).
to
eq
(
'570e7b2abdd848b95f2f578043fc23bd6f6fd24d'
)
...
...
@@ -25,7 +25,7 @@ describe API::API, api: true do
it
"should return a 400 bad request if no params given"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 404 if such file does not exist"
do
...
...
@@ -35,7 +35,7 @@ describe API::API, api: true do
}
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
params
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -51,13 +51,13 @@ describe API::API, api: true do
it
"should create a new file in project repo"
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
'newfile.rb'
)
end
it
"should return a 400 bad request if no params given"
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 400 if editor fails to create file"
do
...
...
@@ -65,7 +65,7 @@ describe API::API, api: true do
and_return
(
false
)
post
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -81,13 +81,13 @@ describe API::API, api: true do
it
"should update existing file in project repo"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
file_path
)
end
it
"should return a 400 bad request if no params given"
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -102,20 +102,20 @@ describe API::API, api: true do
it
"should delete existing file in project repo"
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
file_path
)
end
it
"should return a 400 bad request if no params given"
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 400 if fails to create file"
do
allow_any_instance_of
(
Repository
).
to
receive
(
:remove_file
).
and_return
(
false
)
delete
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
valid_params
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -143,7 +143,7 @@ describe API::API, api: true do
it
"remains unchanged"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/files"
,
user
),
get_params
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'file_path'
]).
to
eq
(
file_path
)
expect
(
json_response
[
'file_name'
]).
to
eq
(
file_path
)
expect
(
json_response
[
'content'
]).
to
eq
(
put_params
[
:content
])
...
...
spec/requests/api/fork_spec.rb
View file @
abca19da
...
...
@@ -22,7 +22,7 @@ describe API::API, api: true do
context
'when authenticated'
do
it
'should fork if user has sufficient access to project'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
user2
.
id
)
...
...
@@ -32,7 +32,7 @@ describe API::API, api: true do
it
'should fork if user is admin'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
eq
(
project
.
path
)
expect
(
json_response
[
'owner'
][
'id'
]).
to
eq
(
admin
.
id
)
...
...
@@ -42,20 +42,20 @@ describe API::API, api: true do
it
'should fail on missing project access for the project to fork'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user3
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'should fail if forked project exists in the user namespace'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
'has already been taken'
])
expect
(
json_response
[
'message'
][
'path'
]).
to
eq
([
'has already been taken'
])
end
it
'should fail if project to fork from does not exist'
do
post
api
(
'/projects/fork/424242'
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
end
...
...
@@ -63,7 +63,7 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
post
api
(
"/projects/fork/
#{
project
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'message'
]).
to
eq
(
'401 Unauthorized'
)
end
end
...
...
spec/requests/api/group_members_spec.rb
View file @
abca19da
...
...
@@ -31,7 +31,7 @@ describe API::API, api: true do
it
"each user: should return an array of members groups of group3"
do
[
owner
,
master
,
developer
,
reporter
,
guest
].
each
do
|
user
|
get
api
(
"/groups/
#{
group_with_members
.
id
}
/members"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
5
)
expect
(
json_response
.
find
{
|
e
|
e
[
'id'
]
==
owner
.
id
}[
'access_level'
]).
to
eq
(
GroupMember
::
OWNER
)
...
...
@@ -45,7 +45,7 @@ describe API::API, api: true do
it
'users not part of the group should get access error'
do
get
api
(
"/groups/
#{
group_with_members
.
id
}
/members"
,
stranger
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -54,7 +54,7 @@ describe API::API, api: true do
context
"when not a member of the group"
do
it
"should not add guest as member of group_no_members when adding being done by person outside the group"
do
post
api
(
"/groups/
#{
group_no_members
.
id
}
/members"
,
reporter
),
user_id:
guest
.
id
,
access_level:
GroupMember
::
MASTER
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -66,7 +66,7 @@ describe API::API, api: true do
post
api
(
"/groups/
#{
group_no_members
.
id
}
/members"
,
owner
),
user_id:
new_user
.
id
,
access_level:
GroupMember
::
MASTER
end
.
to
change
{
group_no_members
.
members
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
new_user
.
name
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
GroupMember
::
MASTER
)
end
...
...
@@ -78,27 +78,27 @@ describe API::API, api: true do
post
api
(
"/groups/
#{
group_with_members
.
id
}
/members"
,
guest
),
user_id:
new_user
.
id
,
access_level:
GroupMember
::
MASTER
end
.
not_to
change
{
group_with_members
.
members
.
count
}
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should return error if member already exists"
do
post
api
(
"/groups/
#{
group_with_members
.
id
}
/members"
,
owner
),
user_id:
master
.
id
,
access_level:
GroupMember
::
MASTER
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
end
it
"should return a 400 error when user id is not given"
do
post
api
(
"/groups/
#{
group_no_members
.
id
}
/members"
,
owner
),
access_level:
GroupMember
::
MASTER
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 400 error when access level is not given"
do
post
api
(
"/groups/
#{
group_no_members
.
id
}
/members"
,
owner
),
user_id:
master
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 422 error when access level is not known"
do
post
api
(
"/groups/
#{
group_no_members
.
id
}
/members"
,
owner
),
user_id:
master
.
id
,
access_level:
1234
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
end
...
...
@@ -110,7 +110,7 @@ describe API::API, api: true do
api
(
"/groups/
#{
group_no_members
.
id
}
/members/
#{
developer
.
id
}
"
,
owner
),
access_level:
GroupMember
::
MASTER
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -122,7 +122,7 @@ describe API::API, api: true do
access_level:
GroupMember
::
MASTER
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
get
api
(
"/groups/
#{
group_with_members
.
id
}
/members"
,
owner
)
json_reporter
=
json_response
.
find
do
|
e
|
...
...
@@ -139,7 +139,7 @@ describe API::API, api: true do
access_level:
GroupMember
::
MASTER
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
get
api
(
"/groups/
#{
group_with_members
.
id
}
/members"
,
owner
)
json_developer
=
json_response
.
find
do
|
e
|
...
...
@@ -153,7 +153,7 @@ describe API::API, api: true do
put
(
api
(
"/groups/
#{
group_with_members
.
id
}
/members/
#{
master
.
id
}
"
,
owner
)
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return a 422 error when access level is not known'
do
...
...
@@ -161,7 +161,7 @@ describe API::API, api: true do
api
(
"/groups/
#{
group_with_members
.
id
}
/members/
#{
master
.
id
}
"
,
owner
),
access_level:
1234
)
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
end
...
...
@@ -172,7 +172,7 @@ describe API::API, api: true do
random_user
=
create
(
:user
)
delete
api
(
"/groups/
#{
group_with_members
.
id
}
/members/
#{
owner
.
id
}
"
,
random_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -182,17 +182,17 @@ describe API::API, api: true do
delete
api
(
"/groups/
#{
group_with_members
.
id
}
/members/
#{
guest
.
id
}
"
,
owner
)
end
.
to
change
{
group_with_members
.
members
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return a 404 error when user id is not known"
do
delete
api
(
"/groups/
#{
group_with_members
.
id
}
/members/1328"
,
owner
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should not allow guest to modify group members"
do
delete
api
(
"/groups/
#{
group_with_members
.
id
}
/members/
#{
master
.
id
}
"
,
guest
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
spec/requests/api/groups_spec.rb
View file @
abca19da
...
...
@@ -23,14 +23,14 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/groups"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
"when authenticated as user"
do
it
"normal user: should return an array of groups of user1"
do
get
api
(
"/groups"
,
user1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
group1
.
name
)
...
...
@@ -40,7 +40,7 @@ describe API::API, api: true do
context
"when authenticated as admin"
do
it
"admin: should return an array of all groups"
do
get
api
(
"/groups"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
end
...
...
@@ -51,51 +51,51 @@ describe API::API, api: true do
context
"when authenticated as user"
do
it
"should return one of user1's groups"
do
get
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
json_response
[
'name'
]
==
group1
.
name
end
it
"should not return a non existing group"
do
get
api
(
"/groups/1328"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should not return a group not attached to user1"
do
get
api
(
"/groups/
#{
group2
.
id
}
"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"when authenticated as admin"
do
it
"should return any existing group"
do
get
api
(
"/groups/
#{
group2
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
group2
.
name
)
end
it
"should not return a non existing group"
do
get
api
(
"/groups/1328"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when using group path in URL'
do
it
'should return any existing group'
do
get
api
(
"/groups/
#{
group1
.
path
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
group1
.
name
)
end
it
'should not return a non existing group'
do
get
api
(
'/groups/unknown'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should not return a group not attached to user1'
do
get
api
(
"/groups/
#{
group2
.
path
}
"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -107,14 +107,14 @@ describe API::API, api: true do
it
'updates the group'
do
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
),
name:
new_group_name
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
new_group_name
)
end
it
'returns 404 for a non existing group'
do
put
api
(
'/groups/1328'
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -122,7 +122,7 @@ describe API::API, api: true do
it
'updates the group'
do
put
api
(
"/groups/
#{
group1
.
id
}
"
,
admin
),
name:
new_group_name
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
new_group_name
)
end
end
...
...
@@ -131,7 +131,7 @@ describe API::API, api: true do
it
'does not updates the group'
do
put
api
(
"/groups/
#{
group1
.
id
}
"
,
user2
),
name:
new_group_name
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -139,7 +139,7 @@ describe API::API, api: true do
it
'returns 404 when trying to update the group'
do
put
api
(
"/groups/
#{
group2
.
id
}
"
,
user1
),
name:
new_group_name
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -149,7 +149,7 @@ describe API::API, api: true do
it
"should return the group's projects"
do
get
api
(
"/groups/
#{
group1
.
id
}
/projects"
,
user1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
.
length
).
to
eq
(
2
)
project_names
=
json_response
.
map
{
|
proj
|
proj
[
'name'
]
}
expect
(
project_names
).
to
match_array
([
project1
.
name
,
project3
.
name
])
...
...
@@ -157,13 +157,13 @@ describe API::API, api: true do
it
"should not return a non existing group"
do
get
api
(
"/groups/1328/projects"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should not return a group not attached to user1"
do
get
api
(
"/groups/
#{
group2
.
id
}
/projects"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should only return projects to which user has access"
do
...
...
@@ -171,7 +171,7 @@ describe API::API, api: true do
get
api
(
"/groups/
#{
group1
.
id
}
/projects"
,
user3
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
project3
.
name
)
end
...
...
@@ -180,14 +180,14 @@ describe API::API, api: true do
context
"when authenticated as admin"
do
it
"should return any existing group"
do
get
api
(
"/groups/
#{
group2
.
id
}
/projects"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
project2
.
name
)
end
it
"should not return a non existing group"
do
get
api
(
"/groups/1328/projects"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -195,20 +195,20 @@ describe API::API, api: true do
it
'should return any existing group'
do
get
api
(
"/groups/
#{
group1
.
path
}
/projects"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_names
=
json_response
.
map
{
|
proj
|
proj
[
'name'
]
}
expect
(
project_names
).
to
match_array
([
project1
.
name
,
project3
.
name
])
end
it
'should not return a non existing group'
do
get
api
(
'/groups/unknown/projects'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should not return a group not attached to user1'
do
get
api
(
"/groups/
#{
group2
.
path
}
/projects"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -217,30 +217,30 @@ describe API::API, api: true do
context
"when authenticated as user without group permissions"
do
it
"should not create group"
do
post
api
(
"/groups"
,
user1
),
attributes_for
(
:group
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
"when authenticated as user with group permissions"
do
it
"should create group"
do
post
api
(
"/groups"
,
user3
),
attributes_for
(
:group
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
"should not create group, duplicate"
do
post
api
(
"/groups"
,
user3
),
{
name:
'Duplicate Test'
,
path:
group2
.
path
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
.
message
).
to
eq
(
"Bad Request"
)
end
it
"should return 400 bad request error if name not given"
do
post
api
(
"/groups"
,
user3
),
{
path:
group2
.
path
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return 400 bad request error if path not given"
do
post
api
(
"/groups"
,
user3
),
{
name:
'test'
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
end
...
...
@@ -249,37 +249,37 @@ describe API::API, api: true do
context
"when authenticated as user"
do
it
"should remove group"
do
delete
api
(
"/groups/
#{
group1
.
id
}
"
,
user1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should not remove a group if not an owner"
do
user4
=
create
(
:user
)
group1
.
add_master
(
user4
)
delete
api
(
"/groups/
#{
group1
.
id
}
"
,
user3
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should not remove a non existing group"
do
delete
api
(
"/groups/1328"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should not remove a group not attached to user1"
do
delete
api
(
"/groups/
#{
group2
.
id
}
"
,
user1
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"when authenticated as admin"
do
it
"should remove any existing group"
do
delete
api
(
"/groups/
#{
group2
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should not remove a non existing group"
do
delete
api
(
"/groups/1328"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -295,14 +295,14 @@ describe API::API, api: true do
context
"when authenticated as user"
do
it
"should not transfer project to group"
do
post
api
(
"/groups/
#{
group1
.
id
}
/projects/
#{
project
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
"when authenticated as admin"
do
it
"should transfer project to group"
do
post
api
(
"/groups/
#{
group1
.
id
}
/projects/
#{
project
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
end
end
...
...
spec/requests/api/internal_spec.rb
View file @
abca19da
...
...
@@ -11,7 +11,7 @@ describe API::API, api: true do
it
do
get
api
(
"/internal/check"
),
secret_token:
secret_token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'api_version'
]).
to
eq
(
API
::
API
.
version
)
end
end
...
...
@@ -23,7 +23,7 @@ describe API::API, api: true do
it
do
get
api
(
"/internal/broadcast_message"
),
secret_token:
secret_token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"message"
]).
to
eq
(
broadcast_message
.
message
)
end
end
...
...
@@ -32,7 +32,7 @@ describe API::API, api: true do
it
do
get
api
(
"/internal/broadcast_message"
),
secret_token:
secret_token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_empty
end
end
...
...
@@ -42,7 +42,7 @@ describe API::API, api: true do
it
do
get
(
api
(
"/internal/discover"
),
key_id:
key
.
id
,
secret_token:
secret_token
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
user
.
name
)
end
...
...
@@ -61,7 +61,7 @@ describe API::API, api: true do
push
(
key
,
project_wiki
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_truthy
end
end
...
...
@@ -70,7 +70,7 @@ describe API::API, api: true do
it
do
pull
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_truthy
end
end
...
...
@@ -79,7 +79,7 @@ describe API::API, api: true do
it
do
push
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_truthy
end
end
...
...
@@ -94,7 +94,7 @@ describe API::API, api: true do
it
do
pull
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -103,7 +103,7 @@ describe API::API, api: true do
it
do
push
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -120,7 +120,7 @@ describe API::API, api: true do
it
do
pull
(
key
,
personal_project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -129,7 +129,7 @@ describe API::API, api: true do
it
do
push
(
key
,
personal_project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -147,7 +147,7 @@ describe API::API, api: true do
it
do
pull
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_truthy
end
end
...
...
@@ -156,7 +156,7 @@ describe API::API, api: true do
it
do
push
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -173,7 +173,7 @@ describe API::API, api: true do
it
do
archive
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_truthy
end
end
...
...
@@ -182,7 +182,7 @@ describe API::API, api: true do
it
do
archive
(
key
,
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -192,7 +192,7 @@ describe API::API, api: true do
it
do
pull
(
key
,
OpenStruct
.
new
(
path_with_namespace:
'gitlab/notexists'
))
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
@@ -201,7 +201,7 @@ describe API::API, api: true do
it
do
pull
(
OpenStruct
.
new
(
id:
0
),
project
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"status"
]).
to
be_falsey
end
end
...
...
spec/requests/api/issues_spec.rb
View file @
abca19da
...
...
@@ -51,14 +51,14 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/issues"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
"when authenticated"
do
it
"should return an array of issues"
do
get
api
(
"/issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
end
...
...
@@ -72,7 +72,7 @@ describe API::API, api: true do
it
'should return an array of closed issues'
do
get
api
(
'/issues?state=closed'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
closed_issue
.
id
)
...
...
@@ -80,7 +80,7 @@ describe API::API, api: true do
it
'should return an array of opened issues'
do
get
api
(
'/issues?state=opened'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
issue
.
id
)
...
...
@@ -88,7 +88,7 @@ describe API::API, api: true do
it
'should return an array of all issues'
do
get
api
(
'/issues?state=all'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
issue
.
id
)
...
...
@@ -97,7 +97,7 @@ describe API::API, api: true do
it
'should return an array of labeled issues'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label
.
title
])
...
...
@@ -105,7 +105,7 @@ describe API::API, api: true do
it
'should return an array of labeled issues when at least one label matches'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
,foo,bar"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label
.
title
])
...
...
@@ -113,14 +113,14 @@ describe API::API, api: true do
it
'should return an empty array if no issue matches labels'
do
get
api
(
'/issues?labels=foo,bar'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
it
'should return an array of labeled issues matching given state'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
&state=opened"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label
.
title
])
...
...
@@ -129,7 +129,7 @@ describe API::API, api: true do
it
'should return an empty array if no issue matches labels and state filters'
do
get
api
(
"/issues?labels=
#{
label
.
title
}
&state=closed"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
...
...
@@ -179,7 +179,7 @@ describe API::API, api: true do
it
'returns group issues without confidential issues for non project members'
do
get
api
(
base_url
,
non_member
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
group_issue
.
title
)
...
...
@@ -188,7 +188,7 @@ describe API::API, api: true do
it
'returns group confidential issues for author'
do
get
api
(
base_url
,
author
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
end
...
...
@@ -196,7 +196,7 @@ describe API::API, api: true do
it
'returns group confidential issues for assignee'
do
get
api
(
base_url
,
assignee
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
end
...
...
@@ -204,7 +204,7 @@ describe API::API, api: true do
it
'returns group issues with confidential issues for project members'
do
get
api
(
base_url
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
end
...
...
@@ -212,7 +212,7 @@ describe API::API, api: true do
it
'returns group confidential issues for admin'
do
get
api
(
base_url
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
end
...
...
@@ -220,7 +220,7 @@ describe API::API, api: true do
it
'returns an array of labeled group issues'
do
get
api
(
"
#{
base_url
}
?labels=
#{
group_label
.
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
group_label
.
title
])
...
...
@@ -229,7 +229,7 @@ describe API::API, api: true do
it
'returns an array of labeled group issues where all labels match'
do
get
api
(
"
#{
base_url
}
?labels=
#{
group_label
.
title
}
,foo,bar"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
...
...
@@ -237,7 +237,7 @@ describe API::API, api: true do
it
'returns an empty array if no group issue matches labels'
do
get
api
(
"
#{
base_url
}
?labels=foo,bar"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
...
...
@@ -245,7 +245,7 @@ describe API::API, api: true do
it
'returns an empty array if no issue matches milestone'
do
get
api
(
"
#{
base_url
}
?milestone=
#{
group_empty_milestone
.
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
...
...
@@ -253,7 +253,7 @@ describe API::API, api: true do
it
'returns an empty array if milestone does not exist'
do
get
api
(
"
#{
base_url
}
?milestone=foo"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
...
...
@@ -261,7 +261,7 @@ describe API::API, api: true do
it
'returns an array of issues in given milestone'
do
get
api
(
"
#{
base_url
}
?milestone=
#{
group_milestone
.
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
group_issue
.
id
)
...
...
@@ -271,7 +271,7 @@ describe API::API, api: true do
get
api
(
"
#{
base_url
}
?milestone=
#{
group_milestone
.
title
}
"
\
'&state=closed'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
group_closed_issue
.
id
)
...
...
@@ -284,7 +284,7 @@ describe API::API, api: true do
it
'should return project issues without confidential issues for non project members'
do
get
api
(
"
#{
base_url
}
/issues"
,
non_member
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -292,7 +292,7 @@ describe API::API, api: true do
it
'should return project issues without confidential issues for project members with guest role'
do
get
api
(
"
#{
base_url
}
/issues"
,
guest
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -300,7 +300,7 @@ describe API::API, api: true do
it
'should return project confidential issues for author'
do
get
api
(
"
#{
base_url
}
/issues"
,
author
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -308,7 +308,7 @@ describe API::API, api: true do
it
'should return project confidential issues for assignee'
do
get
api
(
"
#{
base_url
}
/issues"
,
assignee
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -316,7 +316,7 @@ describe API::API, api: true do
it
'should return project issues with confidential issues for project members'
do
get
api
(
"
#{
base_url
}
/issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -324,7 +324,7 @@ describe API::API, api: true do
it
'should return project confidential issues for admin'
do
get
api
(
"
#{
base_url
}
/issues"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -332,7 +332,7 @@ describe API::API, api: true do
it
'should return an array of labeled project issues'
do
get
api
(
"
#{
base_url
}
/issues?labels=
#{
label
.
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label
.
title
])
...
...
@@ -340,7 +340,7 @@ describe API::API, api: true do
it
'should return an array of labeled project issues when at least one label matches'
do
get
api
(
"
#{
base_url
}
/issues?labels=
#{
label
.
title
}
,foo,bar"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'labels'
]).
to
eq
([
label
.
title
])
...
...
@@ -348,28 +348,28 @@ describe API::API, api: true do
it
'should return an empty array if no project issue matches labels'
do
get
api
(
"
#{
base_url
}
/issues?labels=foo,bar"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
it
'should return an empty array if no issue matches milestone'
do
get
api
(
"
#{
base_url
}
/issues?milestone=
#{
empty_milestone
.
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
it
'should return an empty array if milestone does not exist'
do
get
api
(
"
#{
base_url
}
/issues?milestone=foo"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
it
'should return an array of issues in given milestone'
do
get
api
(
"
#{
base_url
}
/issues?milestone=
#{
title
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
issue
.
id
)
...
...
@@ -379,7 +379,7 @@ describe API::API, api: true do
it
'should return an array of issues matching state in milestone'
do
get
api
(
"
#{
base_url
}
/issues?milestone=
#{
milestone
.
title
}
"
\
'&state=closed'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
closed_issue
.
id
)
...
...
@@ -390,7 +390,7 @@ describe API::API, api: true do
it
'exposes known attributes'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
issue
.
id
)
expect
(
json_response
[
'iid'
]).
to
eq
(
issue
.
iid
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
issue
.
project
.
id
)
...
...
@@ -408,7 +408,7 @@ describe API::API, api: true do
it
"should return a project issue by id"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
issue
.
iid
)
end
...
...
@@ -423,44 +423,44 @@ describe API::API, api: true do
it
"should return 404 if issue id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/54321"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
'confidential issues'
do
it
"should return 404 for non project members"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
non_member
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return 404 for project members with guest role"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
guest
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return confidential issue for project members"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
it
"should return confidential issue for author"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
author
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
it
"should return confidential issue for assignee"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
assignee
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
it
"should return confidential issue for admin"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
confidential_issue
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
confidential_issue
.
iid
)
end
...
...
@@ -471,7 +471,7 @@ describe API::API, api: true do
it
"should create a new project issue"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
title:
'new issue'
,
labels:
'label, label2'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'new issue'
)
expect
(
json_response
[
'description'
]).
to
be_nil
expect
(
json_response
[
'labels'
]).
to
eq
([
'label'
,
'label2'
])
...
...
@@ -479,21 +479,21 @@ describe API::API, api: true do
it
"should return a 400 bad request if title not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
labels:
'label, label2'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 on invalid label names'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
title:
'new issue'
,
labels:
'label, ?'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'labels'
][
'?'
][
'title'
]).
to
eq
([
'is invalid'
])
end
it
'should return 400 if title is too long'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
title:
'g'
*
256
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is too long (maximum is 255 characters)'
])
...
...
@@ -505,7 +505,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
title:
'new issue'
,
labels:
'label, label2'
,
created_at:
creation_time
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
Time
.
parse
(
json_response
[
'created_at'
])).
to
be_within
(
1
.
second
).
of
(
creation_time
)
end
end
...
...
@@ -529,7 +529,7 @@ describe API::API, api: true do
it
"should not create a new project issue"
do
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
),
params
}.
not_to
change
(
Issue
,
:count
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
({
"error"
=>
"Spam detected"
})
spam_logs
=
SpamLog
.
all
...
...
@@ -546,7 +546,7 @@ describe API::API, api: true do
it
"should update a project issue"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
...
...
@@ -554,14 +554,14 @@ describe API::API, api: true do
it
"should return 404 error if issue id not found"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/44444"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should return 400 on invalid label names'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
title:
'updated title'
,
labels:
'label, ?'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'labels'
][
'?'
][
'title'
]).
to
eq
([
'is invalid'
])
end
...
...
@@ -569,33 +569,33 @@ describe API::API, api: true do
it
"should return 403 for non project members"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
non_member
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should return 403 for project members with guest role"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
guest
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should update a confidential issue for project members"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
it
"should update a confidential issue for author"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
author
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
it
"should update a confidential issue for admin"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
"
,
admin
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
end
...
...
@@ -608,21 +608,21 @@ describe API::API, api: true do
it
'should not update labels if not present'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
eq
([
label
.
title
])
end
it
'should remove all labels'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
labels:
''
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
eq
([])
end
it
'should update labels'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
labels:
'foo,bar'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
include
'foo'
expect
(
json_response
[
'labels'
]).
to
include
'bar'
end
...
...
@@ -630,14 +630,14 @@ describe API::API, api: true do
it
'should return 400 on invalid label names'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
labels:
'label, ?'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'labels'
][
'?'
][
'title'
]).
to
eq
([
'is invalid'
])
end
it
'should allow special label names'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
labels:
'label:foo, label-bar,label_bar,label/bar'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
include
'label:foo'
expect
(
json_response
[
'labels'
]).
to
include
'label-bar'
expect
(
json_response
[
'labels'
]).
to
include
'label_bar'
...
...
@@ -647,7 +647,7 @@ describe API::API, api: true do
it
'should return 400 if title is too long'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
title:
'g'
*
256
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is too long (maximum is 255 characters)'
])
...
...
@@ -658,7 +658,7 @@ describe API::API, api: true do
it
"should update a project issue"
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
labels:
'label2'
,
state_event:
"close"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
include
'label2'
expect
(
json_response
[
'state'
]).
to
eq
"closed"
...
...
@@ -669,7 +669,7 @@ describe API::API, api: true do
update_time
=
2
.
weeks
.
ago
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
user
),
labels:
'label3'
,
state_event:
'close'
,
updated_at:
update_time
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'labels'
]).
to
include
'label3'
expect
(
Time
.
parse
(
json_response
[
'updated_at'
])).
to
be_within
(
1
.
second
).
of
(
update_time
)
...
...
@@ -680,12 +680,12 @@ describe API::API, api: true do
describe
"DELETE /projects/:id/issues/:issue_id"
do
it
"rejects a non member from deleting an issue"
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
non_member
)
expect
(
response
.
status
).
to
be
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"rejects a developer from deleting an issue"
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
author
)
expect
(
response
.
status
).
to
be
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
context
"when the user is project owner"
do
...
...
@@ -694,7 +694,7 @@ describe API::API, api: true do
it
"deletes the issue if an admin requests it"
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
"
,
owner
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'state'
]).
to
eq
'opened'
end
end
...
...
@@ -708,7 +708,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/move"
,
user
),
to_project_id:
target_project
.
id
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
target_project
.
id
)
end
...
...
@@ -717,7 +717,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/move"
,
user
),
to_project_id:
project
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Cannot move issue to project it originates from!'
)
end
end
...
...
@@ -727,7 +727,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/move"
,
user
),
to_project_id:
target_project2
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Cannot move issue due to insufficient permissions!'
)
end
end
...
...
@@ -736,7 +736,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/move"
,
admin
),
to_project_id:
target_project2
.
id
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
target_project2
.
id
)
end
...
...
@@ -745,7 +745,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/123/move"
,
user
),
to_project_id:
target_project
.
id
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -754,7 +754,7 @@ describe API::API, api: true do
post
api
(
"/projects/123/issues/
#{
issue
.
id
}
/move"
,
user
),
to_project_id:
target_project
.
id
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -763,7 +763,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/move"
,
user
),
to_project_id:
123
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -772,26 +772,26 @@ describe API::API, api: true do
it
'subscribes to an issue'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscription"
,
user2
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
true
)
end
it
'returns 304 if already subscribed'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
it
'returns 404 if the issue is not found'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/123/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'returns 404 if the issue is confidential'
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
/subscription"
,
non_member
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -799,26 +799,26 @@ describe API::API, api: true do
it
'unsubscribes from an issue'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
false
)
end
it
'returns 304 if not subscribed'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/subscription"
,
user2
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
it
'returns 404 if the issue is not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/123/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'returns 404 if the issue is confidential'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
confidential_issue
.
id
}
/subscription"
,
non_member
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
spec/requests/api/keys_spec.rb
View file @
abca19da
...
...
@@ -14,14 +14,14 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
"/keys/
#{
key
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when authenticated'
do
it
'should return 404 for non-existing key'
do
get
api
(
'/keys/999999'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
...
...
@@ -29,7 +29,7 @@ describe API::API, api: true do
user
.
keys
<<
key
user
.
save
get
api
(
"/keys/
#{
key
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
key
.
title
)
expect
(
json_response
[
'user'
][
'id'
]).
to
eq
(
user
.
id
)
expect
(
json_response
[
'user'
][
'username'
]).
to
eq
(
user
.
username
)
...
...
spec/requests/api/labels_spec.rb
View file @
abca19da
...
...
@@ -15,7 +15,7 @@ describe API::API, api: true do
describe
'GET /projects/:id/labels'
do
it
'should return project labels'
do
get
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
label1
.
name
)
...
...
@@ -28,7 +28,7 @@ describe API::API, api: true do
name:
'Foo'
,
color:
'#FFAABB'
,
description:
'test'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'Foo'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFAABB'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
...
...
@@ -38,7 +38,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAABB'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'Foo'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFAABB'
)
expect
(
json_response
[
'description'
]).
to
be_nil
...
...
@@ -46,19 +46,19 @@ describe API::API, api: true do
it
'should return a 400 bad request if name not given'
do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
color:
'#FFAABB'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return a 400 bad request if color not given'
do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'Foobar'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 for invalid color'
do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAA'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
...
...
@@ -66,7 +66,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAAFFFF'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
...
...
@@ -74,7 +74,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'?'
,
color:
'#FFAABB'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is invalid'
])
end
...
...
@@ -82,7 +82,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
color:
'#FFAABB'
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Label already exists'
)
end
end
...
...
@@ -90,18 +90,18 @@ describe API::API, api: true do
describe
'DELETE /projects/:id/labels'
do
it
'should return 200 for existing label'
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should return 404 for non existing label'
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label2'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Label Not Found'
)
end
it
'should return 400 for wrong parameters'
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -112,7 +112,7 @@ describe API::API, api: true do
new_name:
'New Label'
,
color:
'#FFFFFF'
,
description:
'test'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
...
...
@@ -122,7 +122,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
new_name:
'New Label'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
'New Label'
)
expect
(
json_response
[
'color'
]).
to
eq
(
label1
.
color
)
end
...
...
@@ -131,7 +131,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
color:
'#FFFFFF'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
name
)
expect
(
json_response
[
'color'
]).
to
eq
(
'#FFFFFF'
)
end
...
...
@@ -140,7 +140,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
description:
'test'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
label1
.
name
)
expect
(
json_response
[
'description'
]).
to
eq
(
'test'
)
end
...
...
@@ -149,18 +149,18 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label2'
,
new_name:
'label3'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should return 400 if no label name given'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
new_name:
'label2'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "name" not given'
)
end
it
'should return 400 if no new parameters given'
do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Required parameters '
\
'"new_name" or "color" missing'
)
end
...
...
@@ -170,7 +170,7 @@ describe API::API, api: true do
name:
'label1'
,
new_name:
'?'
,
color:
'#FFFFFF'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'is invalid'
])
end
...
...
@@ -178,7 +178,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'label1'
,
color:
'#FF'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
...
...
@@ -186,7 +186,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/labels"
,
user
),
name:
'Foo'
,
color:
'#FFAAFFFF'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'color'
]).
to
eq
([
'must be a valid color code'
])
end
end
...
...
@@ -196,7 +196,7 @@ describe API::API, api: true do
it
"should subscribe to the label"
do
post
api
(
"/projects/
#{
project
.
id
}
/labels/
#{
label1
.
title
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"name"
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
"subscribed"
]).
to
be_truthy
end
...
...
@@ -206,7 +206,7 @@ describe API::API, api: true do
it
"should subscribe to the label"
do
post
api
(
"/projects/
#{
project
.
id
}
/labels/
#{
label1
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"name"
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
"subscribed"
]).
to
be_truthy
end
...
...
@@ -218,7 +218,7 @@ describe API::API, api: true do
it
"should return 304"
do
post
api
(
"/projects/
#{
project
.
id
}
/labels/
#{
label1
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
end
...
...
@@ -226,7 +226,7 @@ describe API::API, api: true do
it
"should a return 404 error"
do
post
api
(
"/projects/
#{
project
.
id
}
/labels/1234/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -238,7 +238,7 @@ describe API::API, api: true do
it
"should unsubscribe from the label"
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels/
#{
label1
.
title
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"name"
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
"subscribed"
]).
to
be_falsey
end
...
...
@@ -248,7 +248,7 @@ describe API::API, api: true do
it
"should unsubscribe from the label"
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels/
#{
label1
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"name"
]).
to
eq
(
label1
.
title
)
expect
(
json_response
[
"subscribed"
]).
to
be_falsey
end
...
...
@@ -260,7 +260,7 @@ describe API::API, api: true do
it
"should return 304"
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels/
#{
label1
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
end
...
...
@@ -268,7 +268,7 @@ describe API::API, api: true do
it
"should a return 404 error"
do
delete
api
(
"/projects/
#{
project
.
id
}
/labels/1234/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/requests/api/licenses_spec.rb
View file @
abca19da
...
...
@@ -23,7 +23,7 @@ describe API::Licenses, api: true do
it
'returns a list of available license templates'
do
get
api
(
'/licenses'
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
15
)
expect
(
json_response
.
map
{
|
l
|
l
[
'key'
]
}).
to
include
(
'agpl-3.0'
)
...
...
@@ -34,7 +34,7 @@ describe API::Licenses, api: true do
it
'returns a list of available popular license templates'
do
get
api
(
'/licenses?popular=1'
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
3
)
expect
(
json_response
.
map
{
|
l
|
l
[
'key'
]
}).
to
include
(
'apache-2.0'
)
...
...
@@ -116,7 +116,7 @@ describe API::Licenses, api: true do
let
(
:license_type
)
{
'muth-over9000'
}
it
'returns a 404'
do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/requests/api/merge_requests_spec.rb
View file @
abca19da
...
...
@@ -22,14 +22,14 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
"when authenticated"
do
it
"should return an array of all merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
...
...
@@ -37,7 +37,7 @@ describe API::API, api: true do
it
"should return an array of all merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
...
...
@@ -45,7 +45,7 @@ describe API::API, api: true do
it
"should return an array of open merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state=opened"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
last
[
'title'
]).
to
eq
(
merge_request
.
title
)
...
...
@@ -53,7 +53,7 @@ describe API::API, api: true do
it
"should return an array of closed merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state=closed"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
merge_request_closed
.
title
)
...
...
@@ -61,7 +61,7 @@ describe API::API, api: true do
it
"should return an array of merged merge_requests"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?state=merged"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
merge_request_merged
.
title
)
...
...
@@ -75,7 +75,7 @@ describe API::API, api: true do
it
"should return an array of merge_requests in ascending order"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?sort=asc"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'created_at'
]
}
...
...
@@ -84,7 +84,7 @@ describe API::API, api: true do
it
"should return an array of merge_requests in descending order"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?sort=desc"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'created_at'
]
}
...
...
@@ -93,7 +93,7 @@ describe API::API, api: true do
it
"should return an array of merge_requests ordered by updated_at"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?order_by=updated_at"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'updated_at'
]
}
...
...
@@ -102,7 +102,7 @@ describe API::API, api: true do
it
"should return an array of merge_requests ordered by created_at"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests?order_by=created_at&sort=asc"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
3
)
response_dates
=
json_response
.
map
{
|
merge_request
|
merge_request
[
'created_at'
]
}
...
...
@@ -116,7 +116,7 @@ describe API::API, api: true do
it
'exposes known attributes'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
merge_request
.
id
)
expect
(
json_response
[
'iid'
]).
to
eq
(
merge_request
.
iid
)
expect
(
json_response
[
'project_id'
]).
to
eq
(
merge_request
.
project
.
id
)
...
...
@@ -142,7 +142,7 @@ describe API::API, api: true do
it
"should return merge_request"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
merge_request
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
merge_request
.
iid
)
expect
(
json_response
[
'work_in_progress'
]).
to
eq
(
false
)
...
...
@@ -159,7 +159,7 @@ describe API::API, api: true do
it
"should return a 404 error if merge_request_id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/999"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
'Work in Progress'
do
...
...
@@ -167,7 +167,7 @@ describe API::API, api: true do
it
"should return merge_request"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request_wip
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'work_in_progress'
]).
to
eq
(
true
)
end
end
...
...
@@ -186,7 +186,7 @@ describe API::API, api: true do
it
'returns a 404 when merge_request_id not found'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/999/commits"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -199,7 +199,7 @@ describe API::API, api: true do
it
'returns a 404 when merge_request_id not found'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/999/changes"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -213,7 +213,7 @@ describe API::API, api: true do
author:
user
,
labels:
'label, label2'
,
milestone_id:
milestone
.
id
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'Test merge_request'
)
expect
(
json_response
[
'labels'
]).
to
eq
([
'label'
,
'label2'
])
expect
(
json_response
[
'milestone'
][
'id'
]).
to
eq
(
milestone
.
id
)
...
...
@@ -222,25 +222,25 @@ describe API::API, api: true do
it
"should return 422 when source_branch equals target_branch"
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
),
title:
"Test merge_request"
,
source_branch:
"master"
,
target_branch:
"master"
,
author:
user
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
it
"should return 400 when source_branch is missing"
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
),
title:
"Test merge_request"
,
target_branch:
"master"
,
author:
user
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return 400 when target_branch is missing"
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
),
title:
"Test merge_request"
,
source_branch:
"markdown"
,
author:
user
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return 400 when title is missing"
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests"
,
user
),
target_branch:
'master'
,
source_branch:
'markdown'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 on invalid label names'
do
...
...
@@ -250,7 +250,7 @@ describe API::API, api: true do
target_branch:
'master'
,
author:
user
,
labels:
'label, ?'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'labels'
][
'?'
][
'title'
]).
to
eq
(
[
'is invalid'
]
)
...
...
@@ -274,7 +274,7 @@ describe API::API, api: true do
target_branch:
'master'
,
author:
user
end
.
to
change
{
MergeRequest
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
end
end
end
...
...
@@ -292,7 +292,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
fork_project
.
id
}
/merge_requests"
,
user2
),
title:
'Test merge_request'
,
source_branch:
"feature_conflict"
,
target_branch:
"master"
,
author:
user2
,
target_project_id:
project
.
id
,
description:
'Test description for Test merge_request'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'Test merge_request'
)
expect
(
json_response
[
'description'
]).
to
eq
(
'Test description for Test merge_request'
)
end
...
...
@@ -303,26 +303,26 @@ describe API::API, api: true do
expect
(
fork_project
.
forked_from_project
).
to
eq
(
project
)
post
api
(
"/projects/
#{
fork_project
.
id
}
/merge_requests"
,
user2
),
title:
'Test merge_request'
,
source_branch:
"master"
,
target_branch:
"master"
,
author:
user2
,
target_project_id:
project
.
id
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'Test merge_request'
)
end
it
"should return 400 when source_branch is missing"
do
post
api
(
"/projects/
#{
fork_project
.
id
}
/merge_requests"
,
user2
),
title:
'Test merge_request'
,
target_branch:
"master"
,
author:
user2
,
target_project_id:
project
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return 400 when target_branch is missing"
do
post
api
(
"/projects/
#{
fork_project
.
id
}
/merge_requests"
,
user2
),
title:
'Test merge_request'
,
target_branch:
"master"
,
author:
user2
,
target_project_id:
project
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return 400 when title is missing"
do
post
api
(
"/projects/
#{
fork_project
.
id
}
/merge_requests"
,
user2
),
target_branch:
'master'
,
source_branch:
'markdown'
,
author:
user2
,
target_project_id:
project
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
context
'when target_branch is specified'
do
...
...
@@ -333,7 +333,7 @@ describe API::API, api: true do
source_branch:
'markdown'
,
author:
user
,
target_project_id:
fork_project
.
id
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
it
'should return 422 if targeting a different fork'
do
...
...
@@ -343,14 +343,14 @@ describe API::API, api: true do
source_branch:
'markdown'
,
author:
user2
,
target_project_id:
unrelated_project
.
id
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
it
"should return 201 when target_branch is specified and for the same project"
do
post
api
(
"/projects/
#{
fork_project
.
id
}
/merge_requests"
,
user2
),
title:
'Test merge_request'
,
target_branch:
'master'
,
source_branch:
'markdown'
,
author:
user2
,
target_project_id:
fork_project
.
id
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
end
end
...
...
@@ -365,7 +365,7 @@ describe API::API, api: true do
it
"denies the deletion of the merge request"
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
developer
)
expect
(
response
.
status
).
to
be
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -373,7 +373,7 @@ describe API::API, api: true do
it
"destroys the merge request owners can destroy"
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -381,7 +381,7 @@ describe API::API, api: true do
describe
"PUT /projects/:id/merge_requests/:merge_request_id to close MR"
do
it
"should return merge_request"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
state_event:
"close"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'state'
]).
to
eq
(
'closed'
)
end
end
...
...
@@ -392,7 +392,7 @@ describe API::API, api: true do
it
"should return merge_request in case of success"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return 406 if branch can't be merged"
do
...
...
@@ -401,21 +401,21 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
)
expect
(
response
.
status
).
to
eq
(
406
)
expect
(
response
).
to
have_http_status
(
406
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Branch cannot be merged'
)
end
it
"should return 405 if merge_request is not open"
do
merge_request
.
close
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
expect
(
json_response
[
'message'
]).
to
eq
(
'405 Method Not Allowed'
)
end
it
"should return 405 if merge_request is a work in progress"
do
merge_request
.
update_attribute
(
:title
,
"WIP:
#{
merge_request
.
title
}
"
)
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
expect
(
json_response
[
'message'
]).
to
eq
(
'405 Method Not Allowed'
)
end
...
...
@@ -424,7 +424,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
expect
(
json_response
[
'message'
]).
to
eq
(
'405 Method Not Allowed'
)
end
...
...
@@ -432,21 +432,21 @@ describe API::API, api: true do
user2
=
create
(
:user
)
project
.
team
<<
[
user2
,
:reporter
]
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user2
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'message'
]).
to
eq
(
'401 Unauthorized'
)
end
it
"returns 409 if the SHA parameter doesn't match"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
),
sha:
merge_request
.
source_sha
.
succ
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
start_with
(
'SHA does not match HEAD of source branch'
)
end
it
"succeeds if the SHA parameter matches"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
),
sha:
merge_request
.
source_sha
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"enables merge when build succeeds if the ci is active"
do
...
...
@@ -455,7 +455,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/merge"
,
user
),
merge_when_build_succeeds:
true
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'Test'
)
expect
(
json_response
[
'merge_when_build_succeeds'
]).
to
eq
(
true
)
end
...
...
@@ -464,31 +464,31 @@ describe API::API, api: true do
describe
"PUT /projects/:id/merge_requests/:merge_request_id"
do
it
"updates title and returns merge_request"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
title:
"New title"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'New title'
)
end
it
"updates description and returns merge_request"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
description:
"New description"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'description'
]).
to
eq
(
'New description'
)
end
it
"updates milestone_id and returns merge_request"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
milestone_id:
milestone
.
id
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'milestone'
][
'id'
]).
to
eq
(
milestone
.
id
)
end
it
"should return 400 when source_branch is specified"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
source_branch:
"master"
,
target_branch:
"master"
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return merge_request with renamed target_branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
target_branch:
"wiki"
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'target_branch'
]).
to
eq
(
'wiki'
)
end
...
...
@@ -497,7 +497,7 @@ describe API::API, api: true do
user
),
title:
'new issue'
,
labels:
'label, ?'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'labels'
][
'?'
][
'title'
]).
to
eq
([
'is invalid'
])
end
end
...
...
@@ -507,7 +507,7 @@ describe API::API, api: true do
original_count
=
merge_request
.
notes
.
size
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/comments"
,
user
),
note:
"My comment"
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'note'
]).
to
eq
(
'My comment'
)
expect
(
json_response
[
'author'
][
'name'
]).
to
eq
(
user
.
name
)
expect
(
json_response
[
'author'
][
'username'
]).
to
eq
(
user
.
username
)
...
...
@@ -516,20 +516,20 @@ describe API::API, api: true do
it
"should return 400 if note is missing"
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/comments"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return 404 if note is attached to non existent merge request"
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/404/comments"
,
user
),
note:
'My comment'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
"GET :id/merge_requests/:merge_request_id/comments"
do
it
"should return merge_request comments ordered by created_at"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/comments"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'note'
]).
to
eq
(
"a comment on a MR"
)
...
...
@@ -539,7 +539,7 @@ describe API::API, api: true do
it
"should return a 404 error if merge_request_id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/999/comments"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -551,7 +551,7 @@ describe API::API, api: true do
end
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
mr
.
id
}
/closes_issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
issue
.
id
)
...
...
@@ -559,7 +559,7 @@ describe API::API, api: true do
it
'returns an empty array when there are no issues to be closed'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/closes_issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
0
)
end
...
...
@@ -572,7 +572,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
jira_project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/closes_issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
issue
.
title
)
...
...
@@ -584,20 +584,20 @@ describe API::API, api: true do
it
'subscribes to a merge request'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscription"
,
admin
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
true
)
end
it
'returns 304 if already subscribed'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
it
'returns 404 if the merge request is not found'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/123/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -605,20 +605,20 @@ describe API::API, api: true do
it
'unsubscribes from a merge request'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'subscribed'
]).
to
eq
(
false
)
end
it
'returns 304 if not subscribed'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/subscription"
,
admin
)
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
it
'returns 404 if the merge request is not found'
do
post
api
(
"/projects/
#{
project
.
id
}
/merge_requests/123/subscription"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
spec/requests/api/milestones_spec.rb
View file @
abca19da
...
...
@@ -12,20 +12,20 @@ describe API::API, api: true do
describe
'GET /projects/:id/milestones'
do
it
'should return project milestones'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
milestone
.
title
)
end
it
'should return a 401 error if user not authenticated'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
'returns an array of active milestones'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones?state=active"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
milestone
.
id
)
...
...
@@ -34,7 +34,7 @@ describe API::API, api: true do
it
'returns an array of closed milestones'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones?state=closed"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
closed_milestone
.
id
)
...
...
@@ -44,7 +44,7 @@ describe API::API, api: true do
describe
'GET /projects/:id/milestones/:milestone_id'
do
it
'should return a project milestone by id'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
milestone
.
title
)
expect
(
json_response
[
'iid'
]).
to
eq
(
milestone
.
iid
)
end
...
...
@@ -60,19 +60,19 @@ describe API::API, api: true do
it
'should return 401 error if user not authenticated'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
'should return a 404 error if milestone id not found'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones/1234"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'POST /projects/:id/milestones'
do
it
'should create a new project milestone'
do
post
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
),
title:
'new milestone'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'new milestone'
)
expect
(
json_response
[
'description'
]).
to
be_nil
end
...
...
@@ -80,14 +80,14 @@ describe API::API, api: true do
it
'should create a new project milestone with description and due date'
do
post
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
),
title:
'new milestone'
,
description:
'release'
,
due_date:
'2013-03-02'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'description'
]).
to
eq
(
'release'
)
expect
(
json_response
[
'due_date'
]).
to
eq
(
'2013-03-02'
)
end
it
'should return a 400 error if title is missing'
do
post
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -95,14 +95,14 @@ describe API::API, api: true do
it
'should update a project milestone'
do
put
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
it
'should return a 404 error if milestone id not found'
do
put
api
(
"/projects/
#{
project
.
id
}
/milestones/1234"
,
user
),
title:
'updated title'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -110,7 +110,7 @@ describe API::API, api: true do
it
'should update a project milestone'
do
put
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
"
,
user
),
state_event:
'close'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'state'
]).
to
eq
(
'closed'
)
end
...
...
@@ -131,14 +131,14 @@ describe API::API, api: true do
end
it
'should return project issues for a particular milestone'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
/issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'milestone'
][
'title'
]).
to
eq
(
milestone
.
title
)
end
it
'should return a 401 error if user not authenticated'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
/issues"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
describe
'confidential issues'
do
...
...
@@ -155,7 +155,7 @@ describe API::API, api: true do
it
'returns confidential issues to team members'
do
get
api
(
"/projects/
#{
public_project
.
id
}
/milestones/
#{
milestone
.
id
}
/issues"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
2
)
expect
(
json_response
.
map
{
|
issue
|
issue
[
'id'
]
}).
to
include
(
issue
.
id
,
confidential_issue
.
id
)
...
...
@@ -167,7 +167,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
public_project
.
id
}
/milestones/
#{
milestone
.
id
}
/issues"
,
member
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
map
{
|
issue
|
issue
[
'id'
]
}).
to
include
(
issue
.
id
)
...
...
@@ -176,7 +176,7 @@ describe API::API, api: true do
it
'does not return confidential issues to regular users'
do
get
api
(
"/projects/
#{
public_project
.
id
}
/milestones/
#{
milestone
.
id
}
/issues"
,
create
(
:user
))
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
map
{
|
issue
|
issue
[
'id'
]
}).
to
include
(
issue
.
id
)
...
...
spec/requests/api/namespaces_spec.rb
View file @
abca19da
...
...
@@ -11,14 +11,14 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/namespaces"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
"when authenticated as admin"
do
it
"admin: should return an array of all namespaces"
do
get
api
(
"/namespaces"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
Namespace
.
count
)
...
...
@@ -26,7 +26,7 @@ describe API::API, api: true do
it
"admin: should return an array of matched namespaces"
do
get
api
(
"/namespaces?search=
#{
group1
.
name
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
...
...
@@ -36,7 +36,7 @@ describe API::API, api: true do
context
"when authenticated as a regular user"
do
it
"user: should return an array of namespaces"
do
get
api
(
"/namespaces"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
...
...
@@ -44,7 +44,7 @@ describe API::API, api: true do
it
"admin: should return an array of matched namespaces"
do
get
api
(
"/namespaces?search=
#{
user
.
username
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
...
...
spec/requests/api/notes_spec.rb
View file @
abca19da
...
...
@@ -40,7 +40,7 @@ describe API::API, api: true do
it
"should return an array of issue notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'body'
]).
to
eq
(
issue_note
.
note
)
end
...
...
@@ -48,14 +48,14 @@ describe API::API, api: true do
it
"should return a 404 error when issue id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/12345/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
"and current user cannot view the notes"
do
it
"should return an empty array"
do
get
api
(
"/projects/
#{
ext_proj
.
id
}
/issues/
#{
ext_issue
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
be_empty
end
...
...
@@ -66,7 +66,7 @@ describe API::API, api: true do
it
"returns 404"
do
get
api
(
"/projects/
#{
ext_proj
.
id
}
/issues/
#{
ext_issue
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -74,7 +74,7 @@ describe API::API, api: true do
it
"should return an empty array"
do
get
api
(
"/projects/
#{
ext_proj
.
id
}
/issues/
#{
ext_issue
.
id
}
/notes"
,
private_user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'body'
]).
to
eq
(
cross_reference_note
.
note
)
end
...
...
@@ -86,7 +86,7 @@ describe API::API, api: true do
it
"should return an array of snippet notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'body'
]).
to
eq
(
snippet_note
.
note
)
end
...
...
@@ -94,13 +94,13 @@ describe API::API, api: true do
it
"should return a 404 error when snippet id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/42/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"returns 404 when not authorized"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
private_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -108,7 +108,7 @@ describe API::API, api: true do
it
"should return an array of merge_requests notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'body'
]).
to
eq
(
merge_request_note
.
note
)
end
...
...
@@ -116,13 +116,13 @@ describe API::API, api: true do
it
"should return a 404 error if merge request id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/4444/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"returns 404 when not authorized"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/4444/notes"
,
private_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -132,21 +132,21 @@ describe API::API, api: true do
it
"should return an issue note by id"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'body'
]).
to
eq
(
issue_note
.
note
)
end
it
"should return a 404 error if issue note not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
"and current user cannot view the note"
do
it
"should return a 404 error"
do
get
api
(
"/projects/
#{
ext_proj
.
id
}
/issues/
#{
ext_issue
.
id
}
/notes/
#{
cross_reference_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
"when issue is confidential"
do
...
...
@@ -155,7 +155,7 @@ describe API::API, api: true do
it
"returns 404"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/
#{
issue_note
.
id
}
"
,
private_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -164,7 +164,7 @@ describe API::API, api: true do
it
"should return an issue note by id"
do
get
api
(
"/projects/
#{
ext_proj
.
id
}
/issues/
#{
ext_issue
.
id
}
/notes/
#{
cross_reference_note
.
id
}
"
,
private_user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'body'
]).
to
eq
(
cross_reference_note
.
note
)
end
end
...
...
@@ -175,14 +175,14 @@ describe API::API, api: true do
it
"should return a snippet note by id"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes/
#{
snippet_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'body'
]).
to
eq
(
snippet_note
.
note
)
end
it
"should return a 404 error if snippet note not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -192,7 +192,7 @@ describe API::API, api: true do
it
"should create a new issue note"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
),
body:
'hi!'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'body'
]).
to
eq
(
'hi!'
)
expect
(
json_response
[
'author'
][
'username'
]).
to
eq
(
user
.
username
)
end
...
...
@@ -200,13 +200,13 @@ describe API::API, api: true do
it
"should return a 400 bad request error if body not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 401 unauthorized error if user not authenticated"
do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
),
body:
'hi!'
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
context
'when an admin or owner makes the request'
do
...
...
@@ -215,7 +215,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes"
,
user
),
body:
'hi!'
,
created_at:
creation_time
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'body'
]).
to
eq
(
'hi!'
)
expect
(
json_response
[
'author'
][
'username'
]).
to
eq
(
user
.
username
)
expect
(
Time
.
parse
(
json_response
[
'created_at'
])).
to
be_within
(
1
.
second
).
of
(
creation_time
)
...
...
@@ -228,7 +228,7 @@ describe API::API, api: true do
it
"should create a new snippet note"
do
post
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
user
),
body:
'hi!'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'body'
]).
to
eq
(
'hi!'
)
expect
(
json_response
[
'author'
][
'username'
]).
to
eq
(
user
.
username
)
end
...
...
@@ -236,13 +236,13 @@ describe API::API, api: true do
it
"should return a 400 bad request error if body not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 401 unauthorized error if user not authenticated"
do
post
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
),
body:
'hi!'
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -282,7 +282,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
),
body:
'Hello!'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'body'
]).
to
eq
(
'Hello!'
)
end
...
...
@@ -290,14 +290,14 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/12345"
,
user
),
body:
'Hello!'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should return a 400 bad request error if body not given'
do
put
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -306,7 +306,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
),
body:
'Hello!'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'body'
]).
to
eq
(
'Hello!'
)
end
...
...
@@ -314,7 +314,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/12345"
,
user
),
body:
"Hello!"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -323,7 +323,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/"
\
"notes/
#{
merge_request_note
.
id
}
"
,
user
),
body:
'Hello!'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'body'
]).
to
eq
(
'Hello!'
)
end
...
...
@@ -331,7 +331,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
/"
\
"notes/12345"
,
user
),
body:
"Hello!"
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -342,17 +342,17 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
# Check if note is really deleted
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/"
\
"notes/
#{
issue_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'returns a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
id
}
/notes/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -361,18 +361,18 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
# Check if note is really deleted
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/
#{
snippet_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'returns a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
\
"notes/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -381,18 +381,18 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/
#{
merge_request_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
# Check if note is really deleted
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/
#{
merge_request_note
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'returns a 404 error when note id not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/merge_requests/"
\
"
#{
merge_request
.
id
}
/notes/12345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/requests/api/project_hooks_spec.rb
View file @
abca19da
...
...
@@ -22,7 +22,7 @@ describe API::API, 'ProjectHooks', api: true do
context
"authorized user"
do
it
"should return project hooks"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
count
).
to
eq
(
1
)
...
...
@@ -40,7 +40,7 @@ describe API::API, 'ProjectHooks', api: true do
context
"unauthorized user"
do
it
"should not access project hooks"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user3
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -49,7 +49,7 @@ describe API::API, 'ProjectHooks', api: true do
context
"authorized user"
do
it
"should return a project hook"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'url'
]).
to
eq
(
hook
.
url
)
expect
(
json_response
[
'issues_events'
]).
to
eq
(
hook
.
issues_events
)
expect
(
json_response
[
'push_events'
]).
to
eq
(
hook
.
push_events
)
...
...
@@ -61,20 +61,20 @@ describe API::API, 'ProjectHooks', api: true do
it
"should return a 404 error if hook id is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
"unauthorized user"
do
it
"should not access an existing hook"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user3
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
it
"should return a 404 error if hook id is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -83,7 +83,7 @@ describe API::API, 'ProjectHooks', api: true do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
url:
"http://example.com"
,
issues_events:
true
end
.
to
change
{
project
.
hooks
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'url'
]).
to
eq
(
'http://example.com'
)
expect
(
json_response
[
'issues_events'
]).
to
eq
(
true
)
expect
(
json_response
[
'push_events'
]).
to
eq
(
true
)
...
...
@@ -96,12 +96,12 @@ describe API::API, 'ProjectHooks', api: true do
it
"should return a 400 error if url not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 422 error if url not valid"
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
"url"
=>
"ftp://example.com"
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
...
...
@@ -109,7 +109,7 @@ describe API::API, 'ProjectHooks', api: true do
it
"should update an existing project hook"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
),
url:
'http://example.org'
,
push_events:
false
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'url'
]).
to
eq
(
'http://example.org'
)
expect
(
json_response
[
'issues_events'
]).
to
eq
(
hook
.
issues_events
)
expect
(
json_response
[
'push_events'
]).
to
eq
(
false
)
...
...
@@ -121,17 +121,17 @@ describe API::API, 'ProjectHooks', api: true do
it
"should return 404 error if hook id not found"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
),
url:
'http://example.org'
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return 400 error if url is not given"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 422 error if url is not valid"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
),
url:
'ftp://example.com'
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
...
...
@@ -140,22 +140,22 @@ describe API::API, 'ProjectHooks', api: true do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
end
.
to
change
{
project
.
hooks
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return success when deleting hook"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return a 404 error when deleting non existent hook"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/42"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return a 405 error if hook id not given"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
end
it
"shold return a 404 if a user attempts to delete project hooks he/she does not own"
do
...
...
@@ -164,7 +164,7 @@ describe API::API, 'ProjectHooks', api: true do
other_project
.
team
<<
[
test_user
,
:master
]
delete
api
(
"/projects/
#{
other_project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
test_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
WebHook
.
exists?
(
hook
.
id
)).
to
be_truthy
end
end
...
...
spec/requests/api/project_members_spec.rb
View file @
abca19da
...
...
@@ -15,7 +15,7 @@ describe API::API, api: true do
it
"should return project team members"
do
get
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
count
).
to
eq
(
2
)
expect
(
json_response
.
map
{
|
u
|
u
[
'username'
]
}).
to
include
user
.
username
...
...
@@ -23,7 +23,7 @@ describe API::API, api: true do
it
"finds team members with query string"
do
get
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
query:
user
.
username
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
count
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'username'
]).
to
eq
(
user
.
username
)
...
...
@@ -31,7 +31,7 @@ describe API::API, api: true do
it
"should return a 404 error if id not found"
do
get
api
(
"/projects/9999/members"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -40,14 +40,14 @@ describe API::API, api: true do
it
"should return project team member"
do
get
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'username'
]).
to
eq
(
user
.
username
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
MASTER
)
end
it
"should return a 404 error if user id not found"
do
get
api
(
"/projects/
#{
project
.
id
}
/members/1234"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -57,7 +57,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
ProjectMember
::
DEVELOPER
end
.
to
change
{
ProjectMember
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'username'
]).
to
eq
(
user2
.
username
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
DEVELOPER
)
end
...
...
@@ -70,24 +70,24 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
ProjectMember
::
DEVELOPER
end
.
not_to
change
{
ProjectMember
.
count
}
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'username'
]).
to
eq
(
user2
.
username
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
DEVELOPER
)
end
it
"should return a 400 error when user id is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
access_level:
ProjectMember
::
MASTER
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 400 error when access level is not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 422 error when access level is not known"
do
post
api
(
"/projects/
#{
project
.
id
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
1234
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
...
...
@@ -96,24 +96,24 @@ describe API::API, api: true do
it
"should update project team member"
do
put
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
ProjectMember
::
MASTER
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'username'
]).
to
eq
(
user3
.
username
)
expect
(
json_response
[
'access_level'
]).
to
eq
(
ProjectMember
::
MASTER
)
end
it
"should return a 404 error if user_id is not found"
do
put
api
(
"/projects/
#{
project
.
id
}
/members/1234"
,
user
),
access_level:
ProjectMember
::
MASTER
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return a 400 error when access level is not given"
do
put
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should return a 422 error when access level is not known"
do
put
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
123
expect
(
response
.
status
).
to
eq
(
422
)
expect
(
response
).
to
have_http_status
(
422
)
end
end
...
...
@@ -134,20 +134,20 @@ describe API::API, api: true do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
)
end
.
not_to
change
{
ProjectMember
.
count
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return 200 if team member already removed"
do
delete
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
)
delete
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return 200 OK when the user was not member"
do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/members/1000000"
,
user
)
end
.
to
change
{
ProjectMember
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
1000000
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Access revoked'
)
end
...
...
@@ -158,7 +158,7 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
project
.
id
}
/members/
#{
user3
.
id
}
"
,
user3
)
end
.
to
change
{
ProjectMember
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'id'
]).
to
eq
(
project_member2
.
id
)
end
end
...
...
spec/requests/api/project_snippets_spec.rb
View file @
abca19da
...
...
@@ -27,7 +27,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
.
size
).
to
eq
(
3
)
expect
(
json_response
.
map
{
|
snippet
|
snippet
[
'id'
]}
).
to
include
(
public_snippet
.
id
,
internal_snippet
.
id
,
private_snippet
.
id
)
end
...
...
@@ -38,7 +38,7 @@ describe API::API, api: true do
create
(
:project_snippet
,
:private
,
project:
project
)
get
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
.
size
).
to
eq
(
0
)
end
end
...
...
@@ -56,7 +56,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/snippets/"
,
admin
),
params
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
snippet
=
ProjectSnippet
.
find
(
json_response
[
'id'
])
expect
(
snippet
.
content
).
to
eq
(
params
[
:code
])
expect
(
snippet
.
title
).
to
eq
(
params
[
:title
])
...
...
@@ -73,7 +73,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
,
admin
),
code:
new_content
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
snippet
.
reload
expect
(
snippet
.
content
).
to
eq
(
new_content
)
end
...
...
@@ -86,7 +86,7 @@ describe API::API, api: true do
delete
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
/"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -97,7 +97,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
snippet
.
project
.
id
}
/snippets/
#{
snippet
.
id
}
/raw"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
content_type
).
to
eq
'text/plain'
expect
(
response
.
body
).
to
eq
(
snippet
.
content
)
end
...
...
spec/requests/api/projects_spec.rb
View file @
abca19da
...
...
@@ -45,14 +45,14 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
'/projects'
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when authenticated'
do
it
'should return an array of projects'
do
get
api
(
'/projects'
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
.
first
[
'owner'
][
'username'
]).
to
eq
(
user
.
username
)
...
...
@@ -84,7 +84,7 @@ describe API::API, api: true do
context
'and using search'
do
it
'should return searched project'
do
get
api
(
'/projects'
,
user
),
{
search:
project
.
name
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
end
...
...
@@ -93,21 +93,21 @@ describe API::API, api: true do
context
'and using the visibility filter'
do
it
'should filter based on private visibility param'
do
get
api
(
'/projects'
,
user
),
{
visibility:
'private'
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
user
.
namespace
.
projects
.
where
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
).
count
)
end
it
'should filter based on internal visibility param'
do
get
api
(
'/projects'
,
user
),
{
visibility:
'internal'
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
user
.
namespace
.
projects
.
where
(
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
).
count
)
end
it
'should filter based on public visibility param'
do
get
api
(
'/projects'
,
user
),
{
visibility:
'public'
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
user
.
namespace
.
projects
.
where
(
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
).
count
)
end
...
...
@@ -121,7 +121,7 @@ describe API::API, api: true do
it
'should return the correct order when sorted by id'
do
get
api
(
'/projects'
,
user
),
{
order_by:
'id'
,
sort:
'desc'
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'id'
]).
to
eq
(
project3
.
id
)
end
...
...
@@ -135,21 +135,21 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
'/projects/all'
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when authenticated as regular user'
do
it
'should return authentication error'
do
get
api
(
'/projects/all'
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'when authenticated as admin'
do
it
'should return an array of all projects'
do
get
api
(
'/projects/all'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
).
to
satisfy
do
|
response
|
...
...
@@ -173,7 +173,7 @@ describe API::API, api: true do
it
'should return the starred projects viewable by the user'
do
get
api
(
'/projects/starred'
,
user3
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
map
{
|
project
|
project
[
'id'
]
}).
to
contain_exactly
(
project
.
id
,
public_project
.
id
)
end
...
...
@@ -185,25 +185,25 @@ describe API::API, api: true do
allow_any_instance_of
(
User
).
to
receive
(
:projects_limit_left
).
and_return
(
0
)
expect
{
post
api
(
'/projects'
,
user2
),
name:
'foo'
}.
to
change
{
Project
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
it
'should create new project without path and return 201'
do
expect
{
post
api
(
'/projects'
,
user
),
name:
'foo'
}.
to
change
{
Project
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
'should create last project before reaching project limit'
do
allow_any_instance_of
(
User
).
to
receive
(
:projects_limit_left
).
and_return
(
1
)
post
api
(
'/projects'
,
user2
),
name:
'foo'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
'should not create new project without name and return 400'
do
expect
{
post
api
(
'/projects'
,
user
)
}.
not_to
change
{
Project
.
count
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should assign attributes to project"
do
...
...
@@ -273,7 +273,7 @@ describe API::API, api: true do
it
'should not allow a non-admin to use a restricted visibility level'
do
post
api
(
'/projects'
,
user
),
@project
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'visibility_level'
].
first
).
to
(
match
(
'restricted by your GitLab administrator'
)
)
...
...
@@ -295,14 +295,14 @@ describe API::API, api: true do
it
'should create new project without path and return 201'
do
expect
{
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
),
name:
'foo'
}.
to
change
{
Project
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
'should respond with 400 on failure and not project'
do
expect
{
post
api
(
"/projects/user/
#{
user
.
id
}
"
,
admin
)
}.
not_to
change
{
Project
.
count
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
,
...
...
@@ -380,7 +380,7 @@ describe API::API, api: true do
it
"uploads the file and returns its info"
do
post
api
(
"/projects/
#{
project
.
id
}
/uploads"
,
user
),
file:
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/dk.png"
,
"image/png"
)
expect
(
response
.
status
).
to
be
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'alt'
]).
to
eq
(
"dk"
)
expect
(
json_response
[
'url'
]).
to
start_with
(
"/uploads/"
)
expect
(
json_response
[
'url'
]).
to
end_with
(
"/dk.png"
)
...
...
@@ -394,27 +394,27 @@ describe API::API, api: true do
it
'should return a project by id'
do
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'owner'
][
'username'
]).
to
eq
(
user
.
username
)
end
it
'should return a project by path name'
do
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
end
it
'should return a 404 error if not found'
do
get
api
(
'/projects/42'
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'should return a 404 error if user is not a member'
do
other_user
=
create
(
:user
)
get
api
(
"/projects/
#{
project
.
id
}
"
,
other_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should handle users with dots'
do
...
...
@@ -422,7 +422,7 @@ describe API::API, api: true do
project
=
create
(
:project
,
creator_id:
dot_user
.
id
,
namespace:
dot_user
.
namespace
)
get
api
(
"/projects/
#{
dot_user
.
namespace
.
name
}
%2F
#{
project
.
path
}
"
,
dot_user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
end
...
...
@@ -433,7 +433,7 @@ describe API::API, api: true do
it
'contains permission information'
do
get
api
(
"/projects"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
.
first
[
'permissions'
][
'project_access'
][
'access_level'
]).
to
eq
(
Gitlab
::
Access
::
MASTER
)
expect
(
json_response
.
first
[
'permissions'
][
'group_access'
]).
to
be_nil
...
...
@@ -445,7 +445,7 @@ describe API::API, api: true do
project
.
team
<<
[
user
,
:master
]
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'permissions'
][
'project_access'
][
'access_level'
]).
to
eq
(
Gitlab
::
Access
::
MASTER
)
expect
(
json_response
[
'permissions'
][
'group_access'
]).
to
be_nil
...
...
@@ -460,7 +460,7 @@ describe API::API, api: true do
it
'should set the owner and return 200'
do
get
api
(
"/projects/
#{
project2
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'permissions'
][
'project_access'
]).
to
be_nil
expect
(
json_response
[
'permissions'
][
'group_access'
][
'access_level'
]).
to
eq
(
Gitlab
::
Access
::
OWNER
)
...
...
@@ -479,7 +479,7 @@ describe API::API, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/events"
,
user
)
end
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
context
'joined event'
do
let
(
:json_event
)
{
json_response
[
1
]
}
...
...
@@ -500,14 +500,14 @@ describe API::API, api: true do
it
'should return a 404 error if not found'
do
get
api
(
'/projects/42/events'
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Project Not Found'
)
end
it
'should return a 404 error if user is not a member'
do
other_user
=
create
(
:user
)
get
api
(
"/projects/
#{
project
.
id
}
/events"
,
other_user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -516,7 +516,7 @@ describe API::API, api: true do
it
'should return an array of project snippets'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
snippet
.
title
)
end
...
...
@@ -525,13 +525,13 @@ describe API::API, api: true do
describe
'GET /projects/:id/snippets/:snippet_id'
do
it
'should return a project snippet'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
snippet
.
title
)
end
it
'should return a 404 error if snippet id not found'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/1234"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -540,7 +540,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/snippets"
,
user
),
title:
'api test'
,
file_name:
'sample.rb'
,
code:
'test'
,
visibility_level:
'0'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'api test'
)
end
...
...
@@ -554,7 +554,7 @@ describe API::API, api: true do
it
'should update an existing project snippet'
do
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
),
code:
'updated code'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'example'
)
expect
(
snippet
.
reload
.
content
).
to
eq
(
'updated code'
)
end
...
...
@@ -562,7 +562,7 @@ describe API::API, api: true do
it
'should update an existing project snippet with new title'
do
put
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
),
title:
'other api test'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
'other api test'
)
end
end
...
...
@@ -574,24 +574,24 @@ describe API::API, api: true do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
"
,
user
)
end
.
to
change
{
Snippet
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should return 404 when deleting unknown snippet id'
do
delete
api
(
"/projects/
#{
project
.
id
}
/snippets/1234"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'GET /projects/:id/snippets/:snippet_id/raw'
do
it
'should get a raw project snippet'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/raw"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should return a 404 error if raw project snippet not found'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/5555/raw"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -604,7 +604,7 @@ describe API::API, api: true do
it
'should return array of ssh keys'
do
get
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
...
...
@@ -613,20 +613,20 @@ describe API::API, api: true do
describe
'GET /projects/:id/keys/:key_id'
do
it
'should return a single key'
do
get
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
deploy_key
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'title'
]).
to
eq
(
deploy_key
.
title
)
end
it
'should return 404 Not Found with invalid ID'
do
get
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'POST /projects/:id/keys'
do
it
'should not create an invalid ssh key'
do
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
{
title:
'invalid key'
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'key'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
,
...
...
@@ -636,7 +636,7 @@ describe API::API, api: true do
it
'should not create a key without title'
do
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
key:
'some key'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'title'
]).
to
eq
([
'can\'t be blank'
,
'is too short (minimum is 0 characters)'
...
...
@@ -662,7 +662,7 @@ describe API::API, api: true do
it
'should return 404 Not Found with invalid ID'
do
delete
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -676,13 +676,13 @@ describe API::API, api: true do
it
"shouldn't available for non admin users"
do
post
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork/
#{
project_fork_source
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should allow project to be forked from an existing project'
do
expect
(
project_fork_target
.
forked?
).
not_to
be_truthy
post
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork/
#{
project_fork_source
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
project_fork_target
.
reload
expect
(
project_fork_target
.
forked_from_project
.
id
).
to
eq
(
project_fork_source
.
id
)
expect
(
project_fork_target
.
forked_project_link
).
not_to
be_nil
...
...
@@ -691,7 +691,7 @@ describe API::API, api: true do
it
'should fail if forked_from project which does not exist'
do
post
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork/9999"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should fail with 409 if already forked'
do
...
...
@@ -699,7 +699,7 @@ describe API::API, api: true do
project_fork_target
.
reload
expect
(
project_fork_target
.
forked_from_project
.
id
).
to
eq
(
project_fork_source
.
id
)
post
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork/
#{
new_project_fork_source
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
project_fork_target
.
reload
expect
(
project_fork_target
.
forked_from_project
.
id
).
to
eq
(
project_fork_source
.
id
)
expect
(
project_fork_target
.
forked?
).
to
be_truthy
...
...
@@ -710,7 +710,7 @@ describe API::API, api: true do
it
"shouldn't be visible to users outside group"
do
delete
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
context
'when users belong to project group'
do
...
...
@@ -723,7 +723,7 @@ describe API::API, api: true do
it
'should be forbidden to non-owner users'
do
delete
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should make forked project unforked'
do
...
...
@@ -732,7 +732,7 @@ describe API::API, api: true do
expect
(
project_fork_target
.
forked_from_project
).
not_to
be_nil
expect
(
project_fork_target
.
forked?
).
to
be_truthy
delete
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_fork_target
.
reload
expect
(
project_fork_target
.
forked_from_project
).
to
be_nil
expect
(
project_fork_target
.
forked?
).
not_to
be_truthy
...
...
@@ -741,7 +741,7 @@ describe API::API, api: true do
it
'should be idempotent if not forked'
do
expect
(
project_fork_target
.
forked_from_project
).
to
be_nil
delete
api
(
"/projects/
#{
project_fork_target
.
id
}
/fork"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
project_fork_target
.
reload
.
forked_from_project
).
to
be_nil
end
end
...
...
@@ -799,14 +799,14 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
"/projects/search/
#{
query
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when authenticated'
do
it
'should return an array of projects'
do
get
api
(
"/projects/search/
#{
query
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
6
)
json_response
.
each
{
|
project
|
expect
(
project
[
'name'
]).
to
match
(
/.*query.*/
)}
...
...
@@ -816,7 +816,7 @@ describe API::API, api: true do
context
'when authenticated as a different user'
do
it
'should return matching public projects'
do
get
api
(
"/projects/search/
#{
query
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
eq
(
2
)
json_response
.
each
{
|
project
|
expect
(
project
[
'name'
]).
to
match
(
/(internal|public) query/
)}
...
...
@@ -838,7 +838,7 @@ describe API::API, api: true do
it
'should return authentication error'
do
project_param
=
{
name:
'bar'
}
put
api
(
"/projects/
#{
project
.
id
}
"
),
project_param
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -846,7 +846,7 @@ describe API::API, api: true do
it
'should update name'
do
project_param
=
{
name:
'bar'
}
put
api
(
"/projects/
#{
project
.
id
}
"
,
user
),
project_param
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_param
.
each_pair
do
|
k
,
v
|
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
end
...
...
@@ -855,7 +855,7 @@ describe API::API, api: true do
it
'should update visibility_level'
do
project_param
=
{
visibility_level:
20
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user
),
project_param
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_param
.
each_pair
do
|
k
,
v
|
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
end
...
...
@@ -866,7 +866,7 @@ describe API::API, api: true do
project_param
=
{
public:
false
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user
),
project_param
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_param
.
each_pair
do
|
k
,
v
|
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
end
...
...
@@ -876,14 +876,14 @@ describe API::API, api: true do
it
'should not update name to existing name'
do
project_param
=
{
name:
project3
.
name
}
put
api
(
"/projects/
#{
project
.
id
}
"
,
user
),
project_param
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'name'
]).
to
eq
([
'has already been taken'
])
end
it
'should update path & name to existing path & name in different namespace'
do
project_param
=
{
path:
project4
.
path
,
name:
project4
.
name
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user
),
project_param
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_param
.
each_pair
do
|
k
,
v
|
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
end
...
...
@@ -894,7 +894,7 @@ describe API::API, api: true do
it
'should update path'
do
project_param
=
{
path:
'bar'
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user4
),
project_param
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_param
.
each_pair
do
|
k
,
v
|
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
end
...
...
@@ -908,7 +908,7 @@ describe API::API, api: true do
description:
'new description'
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user4
),
project_param
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project_param
.
each_pair
do
|
k
,
v
|
expect
(
json_response
[
k
.
to_s
]).
to
eq
(
v
)
end
...
...
@@ -917,20 +917,20 @@ describe API::API, api: true do
it
'should not update path to existing path'
do
project_param
=
{
path:
project
.
path
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user4
),
project_param
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'path'
]).
to
eq
([
'has already been taken'
])
end
it
'should not update name'
do
project_param
=
{
name:
'bar'
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user4
),
project_param
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should not update visibility_level'
do
project_param
=
{
visibility_level:
20
}
put
api
(
"/projects/
#{
project3
.
id
}
"
,
user4
),
project_param
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -943,7 +943,7 @@ describe API::API, api: true do
merge_requests_enabled:
true
,
description:
'new description'
}
put
api
(
"/projects/
#{
project
.
id
}
"
,
user3
),
project_param
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -953,7 +953,7 @@ describe API::API, api: true do
it
'archives the project'
do
post
api
(
"/projects/
#{
project
.
id
}
/archive"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'archived'
]).
to
be_truthy
end
end
...
...
@@ -966,7 +966,7 @@ describe API::API, api: true do
it
'remains archived'
do
post
api
(
"/projects/
#{
project
.
id
}
/archive"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'archived'
]).
to
be_truthy
end
end
...
...
@@ -979,7 +979,7 @@ describe API::API, api: true do
it
'rejects the action'
do
post
api
(
"/projects/
#{
project
.
id
}
/archive"
,
user3
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -989,7 +989,7 @@ describe API::API, api: true do
it
'remains unarchived'
do
post
api
(
"/projects/
#{
project
.
id
}
/unarchive"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'archived'
]).
to
be_falsey
end
end
...
...
@@ -1002,7 +1002,7 @@ describe API::API, api: true do
it
'unarchives the project'
do
post
api
(
"/projects/
#{
project
.
id
}
/unarchive"
,
user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'archived'
]).
to
be_falsey
end
end
...
...
@@ -1015,7 +1015,7 @@ describe API::API, api: true do
it
'rejects the action'
do
post
api
(
"/projects/
#{
project
.
id
}
/unarchive"
,
user3
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -1025,7 +1025,7 @@ describe API::API, api: true do
it
'stars the project'
do
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/star"
,
user
)
}.
to
change
{
project
.
reload
.
star_count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'star_count'
]).
to
eq
(
1
)
end
end
...
...
@@ -1039,7 +1039,7 @@ describe API::API, api: true do
it
'does not modify the star count'
do
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/star"
,
user
)
}.
not_to
change
{
project
.
reload
.
star_count
}
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
end
end
...
...
@@ -1054,7 +1054,7 @@ describe API::API, api: true do
it
'unstars the project'
do
expect
{
delete
api
(
"/projects/
#{
project
.
id
}
/star"
,
user
)
}.
to
change
{
project
.
reload
.
star_count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'star_count'
]).
to
eq
(
0
)
end
end
...
...
@@ -1063,7 +1063,7 @@ describe API::API, api: true do
it
'does not modify the star count'
do
expect
{
delete
api
(
"/projects/
#{
project
.
id
}
/star"
,
user
)
}.
not_to
change
{
project
.
reload
.
star_count
}
expect
(
response
.
status
).
to
eq
(
304
)
expect
(
response
).
to
have_http_status
(
304
)
end
end
end
...
...
@@ -1072,36 +1072,36 @@ describe API::API, api: true do
context
'when authenticated as user'
do
it
'should remove project'
do
delete
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should not remove a project if not an owner'
do
user3
=
create
(
:user
)
project
.
team
<<
[
user3
,
:developer
]
delete
api
(
"/projects/
#{
project
.
id
}
"
,
user3
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should not remove a non existing project'
do
delete
api
(
'/projects/1328'
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should not remove a project not attached to user'
do
delete
api
(
"/projects/
#{
project
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when authenticated as admin'
do
it
'should remove any existing project'
do
delete
api
(
"/projects/
#{
project
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should not remove a non existing project'
do
delete
api
(
'/projects/1328'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/requests/api/repositories_spec.rb
View file @
abca19da
...
...
@@ -18,7 +18,7 @@ describe API::API, api: true do
it
"should return project commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tree"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
'encoding'
)
...
...
@@ -28,7 +28,7 @@ describe API::API, api: true do
it
'should return a 404 for unknown ref'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tree?ref_name=foo"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
).
to
be_an
Object
json_response
[
'message'
]
==
'404 Tree Not Found'
...
...
@@ -38,7 +38,7 @@ describe API::API, api: true do
context
"unauthorized user"
do
it
"should not return project commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tree"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -46,41 +46,41 @@ describe API::API, api: true do
describe
"GET /projects/:id/repository/blobs/:sha"
do
it
"should get the raw file contents"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/blobs/master?filepath=README.md"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return 404 for invalid branch_name"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/blobs/invalid_branch_name?filepath=README.md"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return 404 for invalid file"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/blobs/master?filepath=README.invalid"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return a 400 error if filepath is missing"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/blobs/master"
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
describe
"GET /projects/:id/repository/commits/:sha/blob"
do
it
"should get the raw file contents"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/master/blob?filepath=README.md"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
describe
"GET /projects/:id/repository/raw_blobs/:sha"
do
it
"should get the raw file contents"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/raw_blobs/
#{
sample_blob
.
oid
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should return a 404 for unknown blob'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/raw_blobs/123456"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
).
to
be_an
Object
json_response
[
'message'
]
==
'404 Blob Not Found'
...
...
@@ -91,7 +91,7 @@ describe API::API, api: true do
it
"should get the archive"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive"
,
user
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
type
,
params
=
workhorse_send_data
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
repo_name
}
\-[^\.]+\.tar.gz/
)
...
...
@@ -100,7 +100,7 @@ describe API::API, api: true do
it
"should get the archive.zip"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive.zip"
,
user
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
type
,
params
=
workhorse_send_data
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
repo_name
}
\-[^\.]+\.zip/
)
...
...
@@ -109,7 +109,7 @@ describe API::API, api: true do
it
"should get the archive.tar.bz2"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive.tar.bz2"
,
user
)
repo_name
=
project
.
repository
.
name
.
gsub
(
"
\.
git"
,
""
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
type
,
params
=
workhorse_send_data
expect
(
type
).
to
eq
(
'git-archive'
)
expect
(
params
[
'ArchivePath'
]).
to
match
(
/
#{
repo_name
}
\-[^\.]+\.tar.bz2/
)
...
...
@@ -117,28 +117,28 @@ describe API::API, api: true do
it
"should return 404 for invalid sha"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/archive/?sha=xxx"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
describe
'GET /projects/:id/repository/compare'
do
it
"should compare branches"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'master'
,
to:
'feature'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'commits'
]).
to
be_present
expect
(
json_response
[
'diffs'
]).
to
be_present
end
it
"should compare tags"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'v1.0.0'
,
to:
'v1.1.0'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'commits'
]).
to
be_present
expect
(
json_response
[
'diffs'
]).
to
be_present
end
it
"should compare commits"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
sample_commit
.
id
,
to:
sample_commit
.
parent_id
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'commits'
]).
to
be_empty
expect
(
json_response
[
'diffs'
]).
to
be_empty
expect
(
json_response
[
'compare_same_ref'
]).
to
be_falsey
...
...
@@ -146,14 +146,14 @@ describe API::API, api: true do
it
"should compare commits in reverse order"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
sample_commit
.
parent_id
,
to:
sample_commit
.
id
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'commits'
]).
to
be_present
expect
(
json_response
[
'diffs'
]).
to
be_present
end
it
"should compare same refs"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/compare"
,
user
),
from:
'master'
,
to:
'master'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'commits'
]).
to
be_empty
expect
(
json_response
[
'diffs'
]).
to
be_empty
expect
(
json_response
[
'compare_same_ref'
]).
to
be_truthy
...
...
@@ -163,7 +163,7 @@ describe API::API, api: true do
describe
'GET /projects/:id/repository/contributors'
do
it
'should return valid data'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/contributors"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
contributor
=
json_response
.
first
expect
(
contributor
[
'email'
]).
to
eq
(
'dmitriy.zaporozhets@gmail.com'
)
...
...
spec/requests/api/runners_spec.rb
View file @
abca19da
...
...
@@ -39,7 +39,7 @@ describe API::Runners, api: true do
get
api
(
'/runners'
,
user
)
shared
=
json_response
.
any?
{
|
r
|
r
[
'is_shared'
]
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_falsey
end
...
...
@@ -48,14 +48,14 @@ describe API::Runners, api: true do
get
api
(
'/runners?scope=active'
,
user
)
shared
=
json_response
.
any?
{
|
r
|
r
[
'is_shared'
]
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_falsey
end
it
'should avoid filtering if scope is invalid'
do
get
api
(
'/runners?scope=unknown'
,
user
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -63,7 +63,7 @@ describe API::Runners, api: true do
it
'should not return runners'
do
get
api
(
'/runners'
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -75,7 +75,7 @@ describe API::Runners, api: true do
get
api
(
'/runners/all'
,
admin
)
shared
=
json_response
.
any?
{
|
r
|
r
[
'is_shared'
]
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_truthy
end
...
...
@@ -85,7 +85,7 @@ describe API::Runners, api: true do
it
'should not return runners list'
do
get
api
(
'/runners/all'
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -93,14 +93,14 @@ describe API::Runners, api: true do
get
api
(
'/runners/all?scope=specific'
,
admin
)
shared
=
json_response
.
any?
{
|
r
|
r
[
'is_shared'
]
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_falsey
end
it
'should avoid filtering if scope is invalid'
do
get
api
(
'/runners?scope=unknown'
,
admin
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -108,7 +108,7 @@ describe API::Runners, api: true do
it
'should not return runners'
do
get
api
(
'/runners'
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -119,7 +119,7 @@ describe API::Runners, api: true do
it
"should return runner's details"
do
get
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'description'
]).
to
eq
(
shared_runner
.
description
)
end
end
...
...
@@ -128,7 +128,7 @@ describe API::Runners, api: true do
it
"should return runner's details"
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'description'
]).
to
eq
(
specific_runner
.
description
)
end
end
...
...
@@ -136,7 +136,7 @@ describe API::Runners, api: true do
it
'should return 404 if runner does not exists'
do
get
api
(
'/runners/9999'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -145,7 +145,7 @@ describe API::Runners, api: true do
it
"should return runner's details"
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'description'
]).
to
eq
(
specific_runner
.
description
)
end
end
...
...
@@ -154,7 +154,7 @@ describe API::Runners, api: true do
it
"should return runner's details"
do
get
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'description'
]).
to
eq
(
shared_runner
.
description
)
end
end
...
...
@@ -164,7 +164,7 @@ describe API::Runners, api: true do
it
"should not return runner's details"
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -172,7 +172,7 @@ describe API::Runners, api: true do
it
"should not return runner's details"
do
get
api
(
"/runners/
#{
specific_runner
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -191,7 +191,7 @@ describe API::Runners, api: true do
locked:
'true'
)
shared_runner
.
reload
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
shared_runner
.
description
).
to
eq
(
"
#{
description
}
_updated"
)
expect
(
shared_runner
.
active
).
to
eq
(
!
active
)
expect
(
shared_runner
.
tag_list
).
to
include
(
'ruby2.1'
,
'pgsql'
,
'mysql'
)
...
...
@@ -206,7 +206,7 @@ describe API::Runners, api: true do
update_runner
(
specific_runner
.
id
,
admin
,
description:
'test'
)
specific_runner
.
reload
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
specific_runner
.
description
).
to
eq
(
'test'
)
expect
(
specific_runner
.
description
).
not_to
eq
(
description
)
end
...
...
@@ -215,7 +215,7 @@ describe API::Runners, api: true do
it
'should return 404 if runner does not exists'
do
update_runner
(
9999
,
admin
,
description:
'test'
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
def
update_runner
(
id
,
user
,
args
)
...
...
@@ -228,7 +228,7 @@ describe API::Runners, api: true do
it
'should not update runner'
do
put
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -236,7 +236,7 @@ describe API::Runners, api: true do
it
'should not update runner without access to it'
do
put
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should update runner with access to it'
do
...
...
@@ -244,7 +244,7 @@ describe API::Runners, api: true do
put
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
admin
),
description:
'test'
specific_runner
.
reload
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
specific_runner
.
description
).
to
eq
(
'test'
)
expect
(
specific_runner
.
description
).
not_to
eq
(
description
)
end
...
...
@@ -255,7 +255,7 @@ describe API::Runners, api: true do
it
'should not delete runner'
do
put
api
(
"/runners/
#{
specific_runner
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -267,7 +267,7 @@ describe API::Runners, api: true do
expect
do
delete
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
admin
)
end
.
to
change
{
Ci
::
Runner
.
shared
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -276,21 +276,21 @@ describe API::Runners, api: true do
expect
do
delete
api
(
"/runners/
#{
unused_specific_runner
.
id
}
"
,
admin
)
end
.
to
change
{
Ci
::
Runner
.
specific
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should delete used runner'
do
expect
do
delete
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
admin
)
end
.
to
change
{
Ci
::
Runner
.
specific
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
it
'should return 404 if runner does not exists'
do
delete
api
(
'/runners/9999'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -298,26 +298,26 @@ describe API::Runners, api: true do
context
'when runner is shared'
do
it
'should not delete runner'
do
delete
api
(
"/runners/
#{
shared_runner
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
'when runner is not shared'
do
it
'should not delete runner without access to it'
do
delete
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should not delete runner with more than one associated project'
do
delete
api
(
"/runners/
#{
two_projects_runner
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should delete runner for one owned project'
do
expect
do
delete
api
(
"/runners/
#{
specific_runner
.
id
}
"
,
user
)
end
.
to
change
{
Ci
::
Runner
.
specific
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -326,7 +326,7 @@ describe API::Runners, api: true do
it
'should not delete runner'
do
delete
api
(
"/runners/
#{
specific_runner
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -337,7 +337,7 @@ describe API::Runners, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user
)
shared
=
json_response
.
any?
{
|
r
|
r
[
'is_shared'
]
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
shared
).
to
be_truthy
end
...
...
@@ -347,7 +347,7 @@ describe API::Runners, api: true do
it
"should not return project's runners"
do
get
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -355,7 +355,7 @@ describe API::Runners, api: true do
it
"should not return project's runners"
do
get
api
(
"/projects/
#{
project
.
id
}
/runners"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -372,14 +372,14 @@ describe API::Runners, api: true do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user
),
runner_id:
specific_runner2
.
id
end
.
to
change
{
project
.
runners
.
count
}.
by
(
+
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
'should avoid changes when enabling already enabled runner'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user
),
runner_id:
specific_runner
.
id
end
.
to
change
{
project
.
runners
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
end
it
'should not enable locked runner'
do
...
...
@@ -389,13 +389,13 @@ describe API::Runners, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user
),
runner_id:
specific_runner2
.
id
end
.
to
change
{
project
.
runners
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should not enable shared runner'
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user
),
runner_id:
shared_runner
.
id
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
context
'user is admin'
do
...
...
@@ -403,7 +403,7 @@ describe API::Runners, api: true do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
admin
),
runner_id:
unused_specific_runner
.
id
end
.
to
change
{
project
.
runners
.
count
}.
by
(
+
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
end
...
...
@@ -411,14 +411,14 @@ describe API::Runners, api: true do
it
'should not enable runner without access to'
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user
),
runner_id:
unused_specific_runner
.
id
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
it
'should raise an error when no runner_id param is provided'
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
admin
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -426,7 +426,7 @@ describe API::Runners, api: true do
it
'should not enable runner'
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -434,7 +434,7 @@ describe API::Runners, api: true do
it
'should not enable runner'
do
post
api
(
"/projects/
#{
project
.
id
}
/runners"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -446,7 +446,7 @@ describe API::Runners, api: true do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/runners/
#{
two_projects_runner
.
id
}
"
,
user
)
end
.
to
change
{
project
.
runners
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -455,14 +455,14 @@ describe API::Runners, api: true do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/runners/
#{
specific_runner
.
id
}
"
,
user
)
end
.
to
change
{
project
.
runners
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
it
'should return 404 is runner is not found'
do
delete
api
(
"/projects/
#{
project
.
id
}
/runners/9999"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -470,7 +470,7 @@ describe API::Runners, api: true do
it
"should not disable project's runner"
do
delete
api
(
"/projects/
#{
project
.
id
}
/runners/
#{
specific_runner
.
id
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -478,7 +478,7 @@ describe API::Runners, api: true do
it
"should not disable project's runner"
do
delete
api
(
"/projects/
#{
project
.
id
}
/runners/
#{
specific_runner
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
spec/requests/api/services_spec.rb
View file @
abca19da
...
...
@@ -14,7 +14,7 @@ describe API::API, api: true do
it
"should update
#{
service
}
settings"
do
put
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user
),
service_attrs
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return if required fields missing"
do
...
...
@@ -45,7 +45,7 @@ describe API::API, api: true do
it
"should delete
#{
service
}
"
do
delete
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
project
.
send
(
service_method
).
reload
expect
(
project
.
send
(
service_method
).
activated?
).
to
be_falsey
end
...
...
@@ -64,20 +64,20 @@ describe API::API, api: true do
it
'should return authentication error when unauthenticated'
do
get
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"should return all properties of service
#{
service
}
when authenticated as admin"
do
get
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'properties'
].
keys
.
map
(
&
:to_sym
)).
to
match_array
(
service_attrs_list
.
map
)
end
it
"should return properties of service
#{
service
}
other than passwords when authenticated as project owner"
do
get
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'properties'
].
keys
.
map
(
&
:to_sym
)).
to
match_array
(
service_attrs_list_without_passwords
)
end
...
...
@@ -85,7 +85,7 @@ describe API::API, api: true do
project
.
team
<<
[
user2
,
:developer
]
get
api
(
"/projects/
#{
project
.
id
}
/services/
#{
dashed_service
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
spec/requests/api/session_spec.rb
View file @
abca19da
...
...
@@ -9,7 +9,7 @@ describe API::API, api: true do
context
"when valid password"
do
it
"should return private token"
do
post
api
(
"/session"
),
email:
user
.
email
,
password:
'12345678'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'email'
]).
to
eq
(
user
.
email
)
expect
(
json_response
[
'private_token'
]).
to
eq
(
user
.
private_token
)
...
...
@@ -48,7 +48,7 @@ describe API::API, api: true do
context
"when invalid password"
do
it
"should return authentication error"
do
post
api
(
"/session"
),
email:
user
.
email
,
password:
'123'
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'email'
]).
to
be_nil
expect
(
json_response
[
'private_token'
]).
to
be_nil
...
...
@@ -58,7 +58,7 @@ describe API::API, api: true do
context
"when empty password"
do
it
"should return authentication error"
do
post
api
(
"/session"
),
email:
user
.
email
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'email'
]).
to
be_nil
expect
(
json_response
[
'private_token'
]).
to
be_nil
...
...
@@ -68,7 +68,7 @@ describe API::API, api: true do
context
"when empty name"
do
it
"should return authentication error"
do
post
api
(
"/session"
),
password:
user
.
password
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
expect
(
json_response
[
'email'
]).
to
be_nil
expect
(
json_response
[
'private_token'
]).
to
be_nil
...
...
spec/requests/api/settings_spec.rb
View file @
abca19da
...
...
@@ -10,7 +10,7 @@ describe API::API, 'Settings', api: true do
describe
"GET /application/settings"
do
it
"should return application settings"
do
get
api
(
"/application/settings"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'default_projects_limit'
]).
to
eq
(
42
)
expect
(
json_response
[
'signin_enabled'
]).
to
be_truthy
...
...
@@ -21,7 +21,7 @@ describe API::API, 'Settings', api: true do
it
"should update application settings"
do
put
api
(
"/application/settings"
,
admin
),
default_projects_limit:
3
,
signin_enabled:
false
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'default_projects_limit'
]).
to
eq
(
3
)
expect
(
json_response
[
'signin_enabled'
]).
to
be_falsey
end
...
...
spec/requests/api/sidekiq_metrics_spec.rb
View file @
abca19da
...
...
@@ -9,28 +9,28 @@ describe API::SidekiqMetrics, api: true do
it
'defines the `queue_metrics` endpoint'
do
get
api
(
'/sidekiq/queue_metrics'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
Hash
end
it
'defines the `process_metrics` endpoint'
do
get
api
(
'/sidekiq/process_metrics'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'processes'
]).
to
be_an
Array
end
it
'defines the `job_stats` endpoint'
do
get
api
(
'/sidekiq/job_stats'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
Hash
end
it
'defines the `compound_metrics` endpoint'
do
get
api
(
'/sidekiq/compound_metrics'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
Hash
expect
(
json_response
[
'queues'
]).
to
be_a
Hash
expect
(
json_response
[
'processes'
]).
to
be_an
Array
...
...
spec/requests/api/system_hooks_spec.rb
View file @
abca19da
...
...
@@ -13,21 +13,21 @@ describe API::API, api: true do
context
"when no user"
do
it
"should return authentication error"
do
get
api
(
"/hooks"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
"when not an admin"
do
it
"should return forbidden error"
do
get
api
(
"/hooks"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
context
"when authenticated as admin"
do
it
"should return an array of hooks"
do
get
api
(
"/hooks"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'url'
]).
to
eq
(
hook
.
url
)
end
...
...
@@ -43,7 +43,7 @@ describe API::API, api: true do
it
"should respond with 400 if url not given"
do
post
api
(
"/hooks"
,
admin
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
"should not create new hook without url"
do
...
...
@@ -56,13 +56,13 @@ describe API::API, api: true do
describe
"GET /hooks/:id"
do
it
"should return hook by id"
do
get
api
(
"/hooks/
#{
hook
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'event_name'
]).
to
eq
(
'project_create'
)
end
it
"should return 404 on failure"
do
get
api
(
"/hooks/404"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -75,7 +75,7 @@ describe API::API, api: true do
it
"should return success if hook id not found"
do
delete
api
(
"/hooks/12345"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
spec/requests/api/tags_spec.rb
View file @
abca19da
...
...
@@ -18,7 +18,7 @@ describe API::API, api: true do
context
'without releases'
do
it
"should return an array of project tags"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
tag_name
)
end
...
...
@@ -33,7 +33,7 @@ describe API::API, api: true do
it
"should return an array of project tags with release info"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
tag_name
)
expect
(
json_response
.
first
[
'message'
]).
to
eq
(
'Version 1.1.0'
)
...
...
@@ -48,14 +48,14 @@ describe API::API, api: true do
it
'returns a specific tag'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'name'
]).
to
eq
(
tag_name
)
end
it
'returns 404 for an invalid tag name'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags/foobar"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -66,7 +66,7 @@ describe API::API, api: true do
tag_name:
'v7.0.1'
,
ref:
'master'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'v7.0.1'
)
end
end
...
...
@@ -78,7 +78,7 @@ describe API::API, api: true do
ref:
'master'
,
release_description:
'Wow'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'v7.0.1'
)
expect
(
json_response
[
'release'
][
'description'
]).
to
eq
(
'Wow'
)
end
...
...
@@ -94,13 +94,13 @@ describe API::API, api: true do
context
'delete tag'
do
it
'should delete an existing tag'
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'tag_name'
]).
to
eq
(
tag_name
)
end
it
'should raise 404 if the tag does not exist'
do
delete
api
(
"/projects/
#{
project
.
id
}
/repository/tags/foobar"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -117,7 +117,7 @@ describe API::API, api: true do
ref:
'master'
,
message:
'Release 7.1.0'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'name'
]).
to
eq
(
'v7.1.0'
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Release 7.1.0'
)
end
...
...
@@ -127,14 +127,14 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user2
),
tag_name:
'v1.9.0'
,
ref:
'621491c677087aa243f165eab467bfdfbee00be1'
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
'should return 400 if tag name is invalid'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v 1.0.0'
,
ref:
'master'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Tag name invalid'
)
end
...
...
@@ -142,11 +142,11 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v8.0.0'
,
ref:
'master'
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'v8.0.0'
,
ref:
'master'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Tag v8.0.0 already exists'
)
end
...
...
@@ -154,7 +154,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
),
tag_name:
'mytag'
,
ref:
'foo'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Target foo is invalid'
)
end
end
...
...
@@ -167,7 +167,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
/release"
,
user
),
description:
description
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'tag_name'
]).
to
eq
(
tag_name
)
expect
(
json_response
[
'description'
]).
to
eq
(
description
)
end
...
...
@@ -176,7 +176,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags/foobar/release"
,
user
),
description:
description
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Tag does not exist'
)
end
...
...
@@ -190,7 +190,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
/release"
,
user
),
description:
description
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Release already exists'
)
end
end
...
...
@@ -211,7 +211,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
/release"
,
user
),
description:
new_description
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'tag_name'
]).
to
eq
(
tag_name
)
expect
(
json_response
[
'description'
]).
to
eq
(
new_description
)
end
...
...
@@ -221,7 +221,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/repository/tags/foobar/release"
,
user
),
description:
new_description
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Tag does not exist'
)
end
...
...
@@ -229,7 +229,7 @@ describe API::API, api: true do
put
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
/release"
,
user
),
description:
new_description
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Release does not exist'
)
end
end
...
...
spec/requests/api/templates_spec.rb
View file @
abca19da
...
...
@@ -22,7 +22,7 @@ describe API::Templates, api: true do
it
'returns a list of available gitignore templates'
do
get
api
(
'/gitignores'
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
size
).
to
be
>
15
end
...
...
@@ -34,7 +34,7 @@ describe API::Templates, api: true do
it
'returns a list of available gitlab_ci_ymls'
do
get
api
(
'/gitlab_ci_ymls'
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
not_to
be_nil
end
...
...
@@ -45,7 +45,7 @@ describe API::Templates, api: true do
it
'adds a disclaimer on the top'
do
get
api
(
'/gitlab_ci_ymls/Ruby'
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'content'
]).
to
start_with
(
"# This file is a template,"
)
end
end
...
...
spec/requests/api/triggers_spec.rb
View file @
abca19da
...
...
@@ -29,17 +29,17 @@ describe API::API do
context
'Handles errors'
do
it
'should return bad request if token is missing'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
ref:
'master'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return not found if project is not found'
do
post
api
(
'/projects/0/trigger/builds'
),
options
.
merge
(
ref:
'master'
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should return unauthorized if token is for different project'
do
post
api
(
"/projects/
#{
project2
.
id
}
/trigger/builds"
),
options
.
merge
(
ref:
'master'
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -48,14 +48,14 @@ describe API::API do
it
'should create builds'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
ref:
'master'
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
pipeline
.
builds
.
reload
expect
(
pipeline
.
builds
.
size
).
to
eq
(
2
)
end
it
'should return bad request with no builds created if there\'s no commit for that ref'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
ref:
'other-branch'
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'No builds created'
)
end
...
...
@@ -66,19 +66,19 @@ describe API::API do
it
'should validate variables to be a hash'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
'value'
,
ref:
'master'
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'variables needs to be a hash'
)
end
it
'should validate variables needs to be a map of key-valued strings'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
{
key:
%w(1 2)
},
ref:
'master'
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'variables needs to be a map of key-valued strings'
)
end
it
'create trigger request with variables'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
variables:
variables
,
ref:
'master'
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
pipeline
.
builds
.
reload
expect
(
pipeline
.
builds
.
first
.
trigger_request
.
variables
).
to
eq
(
variables
)
end
...
...
@@ -91,7 +91,7 @@ describe API::API do
it
'should return list of triggers'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
expect
(
json_response
[
0
]).
to
have_key
(
'token'
)
end
...
...
@@ -101,7 +101,7 @@ describe API::API do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -109,7 +109,7 @@ describe API::API do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -119,14 +119,14 @@ describe API::API do
it
'should return trigger details'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
(
Hash
)
end
it
'should respond with 404 Not Found if requesting non-existing trigger'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/abcdef012345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -134,7 +134,7 @@ describe API::API do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -142,7 +142,7 @@ describe API::API do
it
'should not return triggers list'
do
get
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -154,7 +154,7 @@ describe API::API do
post
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user
)
end
.
to
change
{
project
.
triggers
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
).
to
be_a
(
Hash
)
end
end
...
...
@@ -163,7 +163,7 @@ describe API::API do
it
'should not create trigger'
do
post
api
(
"/projects/
#{
project
.
id
}
/triggers"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -171,7 +171,7 @@ describe API::API do
it
'should not create trigger'
do
post
api
(
"/projects/
#{
project
.
id
}
/triggers"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -182,13 +182,13 @@ describe API::API do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user
)
end
.
to
change
{
project
.
triggers
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should respond with 404 Not Found if requesting non-existing trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/abcdef012345"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -196,7 +196,7 @@ describe API::API do
it
'should not delete trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -204,7 +204,7 @@ describe API::API do
it
'should not delete trigger'
do
delete
api
(
"/projects/
#{
project
.
id
}
/triggers/
#{
trigger
.
token
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
spec/requests/api/users_spec.rb
View file @
abca19da
...
...
@@ -15,7 +15,7 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/users"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -29,18 +29,18 @@ describe API::API, api: true do
it
"renders 403"
do
get
api
(
"/users"
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"renders 404"
do
get
api
(
"/users/
#{
user
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
it
"should return an array of users"
do
get
api
(
"/users"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
username
=
user
.
username
expect
(
json_response
.
detect
do
|
user
|
...
...
@@ -50,7 +50,7 @@ describe API::API, api: true do
it
"should return one user"
do
get
api
(
"/users?username=
#{
omniauth_user
.
username
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'username'
]).
to
eq
(
omniauth_user
.
username
)
end
...
...
@@ -59,7 +59,7 @@ describe API::API, api: true do
context
"when admin"
do
it
"should return an array of users"
do
get
api
(
"/users"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
.
keys
).
to
include
'email'
expect
(
json_response
.
first
.
keys
).
to
include
'identities'
...
...
@@ -74,24 +74,24 @@ describe API::API, api: true do
describe
"GET /users/:id"
do
it
"should return a user by id"
do
get
api
(
"/users/
#{
user
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'username'
]).
to
eq
(
user
.
username
)
end
it
"should return a 401 if unauthenticated"
do
get
api
(
"/users/9998"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"should return a 404 error if user id not found"
do
get
api
(
"/users/9999"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
it
"should return a 404 if invalid ID"
do
get
api
(
"/users/1ASDF"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -106,7 +106,7 @@ describe API::API, api: true do
it
"should create user with correct attributes"
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
,
admin:
true
,
can_create_group:
true
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
expect
(
new_user
).
not_to
eq
(
nil
)
...
...
@@ -116,7 +116,7 @@ describe API::API, api: true do
it
"should create non-admin user"
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
,
admin:
false
,
can_create_group:
false
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
expect
(
new_user
).
not_to
eq
(
nil
)
...
...
@@ -126,7 +126,7 @@ describe API::API, api: true do
it
"should create non-admin users by default"
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
expect
(
new_user
).
not_to
eq
(
nil
)
...
...
@@ -135,12 +135,12 @@ describe API::API, api: true do
it
"should return 201 Created on success"
do
post
api
(
"/users"
,
admin
),
attributes_for
(
:user
,
projects_limit:
3
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
'creates non-external users by default'
do
post
api
(
"/users"
,
admin
),
attributes_for
(
:user
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
...
...
@@ -150,7 +150,7 @@ describe API::API, api: true do
it
'should allow an external user to be created'
do
post
api
(
"/users"
,
admin
),
attributes_for
(
:user
,
external:
true
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
user_id
=
json_response
[
'id'
]
new_user
=
User
.
find
(
user_id
)
...
...
@@ -163,27 +163,27 @@ describe API::API, api: true do
email:
'invalid email'
,
password:
'password'
,
name:
'test'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 error if name not given'
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
).
except
(
:name
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 error if password not given'
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
).
except
(
:password
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 error if email not given'
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
).
except
(
:email
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 error if username not given'
do
post
api
(
'/users'
,
admin
),
attributes_for
(
:user
).
except
(
:username
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return 400 error if user does not validate'
do
...
...
@@ -194,7 +194,7 @@ describe API::API, api: true do
name:
'test'
,
bio:
'g'
*
256
,
projects_limit:
-
1
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'password'
]).
to
eq
([
'is too short (minimum is 8 characters)'
])
expect
(
json_response
[
'message'
][
'bio'
]).
...
...
@@ -207,7 +207,7 @@ describe API::API, api: true do
it
"shouldn't available for non admin users"
do
post
api
(
"/users"
,
user
),
attributes_for
(
:user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
context
'with existing user'
do
...
...
@@ -227,7 +227,7 @@ describe API::API, api: true do
password:
'password'
,
username:
'foo'
end
.
to
change
{
User
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Email has already been taken'
)
end
...
...
@@ -239,7 +239,7 @@ describe API::API, api: true do
password:
'password'
,
username:
'test'
end
.
to
change
{
User
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Username has already been taken'
)
end
end
...
...
@@ -249,7 +249,7 @@ describe API::API, api: true do
it
"should redirect to sign in page"
do
get
"/users/sign_up"
expect
(
response
.
status
).
to
eq
(
302
)
expect
(
response
).
to
have_http_status
(
302
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
...
...
@@ -261,41 +261,41 @@ describe API::API, api: true do
it
"should update user with new bio"
do
put
api
(
"/users/
#{
user
.
id
}
"
,
admin
),
{
bio:
'new test bio'
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'bio'
]).
to
eq
(
'new test bio'
)
expect
(
user
.
reload
.
bio
).
to
eq
(
'new test bio'
)
end
it
'should update user with his own email'
do
put
api
(
"/users/
#{
user
.
id
}
"
,
admin
),
email:
user
.
email
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'email'
]).
to
eq
(
user
.
email
)
expect
(
user
.
reload
.
email
).
to
eq
(
user
.
email
)
end
it
'should update user with his own username'
do
put
api
(
"/users/
#{
user
.
id
}
"
,
admin
),
username:
user
.
username
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'username'
]).
to
eq
(
user
.
username
)
expect
(
user
.
reload
.
username
).
to
eq
(
user
.
username
)
end
it
"should update user's existing identity"
do
put
api
(
"/users/
#{
omniauth_user
.
id
}
"
,
admin
),
provider:
'ldapmain'
,
extern_uid:
'654321'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
omniauth_user
.
reload
.
identities
.
first
.
extern_uid
).
to
eq
(
'654321'
)
end
it
'should update user with new identity'
do
put
api
(
"/users/
#{
user
.
id
}
"
,
admin
),
provider:
'github'
,
extern_uid:
'67890'
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
user
.
reload
.
identities
.
first
.
extern_uid
).
to
eq
(
'67890'
)
expect
(
user
.
reload
.
identities
.
first
.
provider
).
to
eq
(
'github'
)
end
it
"should update admin status"
do
put
api
(
"/users/
#{
user
.
id
}
"
,
admin
),
{
admin:
true
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'is_admin'
]).
to
eq
(
true
)
expect
(
user
.
reload
.
admin
).
to
eq
(
true
)
end
...
...
@@ -309,7 +309,7 @@ describe API::API, api: true do
it
"should not update admin status"
do
put
api
(
"/users/
#{
admin_user
.
id
}
"
,
admin
),
{
can_create_group:
false
}
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'is_admin'
]).
to
eq
(
true
)
expect
(
admin_user
.
reload
.
admin
).
to
eq
(
true
)
expect
(
admin_user
.
can_create_group
).
to
eq
(
false
)
...
...
@@ -317,18 +317,18 @@ describe API::API, api: true do
it
"should not allow invalid update"
do
put
api
(
"/users/
#{
user
.
id
}
"
,
admin
),
{
email:
'invalid email'
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
user
.
reload
.
email
).
not_to
eq
(
'invalid email'
)
end
it
"shouldn't available for non admin users"
do
put
api
(
"/users/
#{
user
.
id
}
"
,
user
),
attributes_for
(
:user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should return 404 for non-existing user"
do
put
api
(
"/users/999999"
,
admin
),
{
bio:
'update should fail'
}
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
...
...
@@ -344,7 +344,7 @@ describe API::API, api: true do
name:
'test'
,
bio:
'g'
*
256
,
projects_limit:
-
1
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'password'
]).
to
eq
([
'is too short (minimum is 8 characters)'
])
expect
(
json_response
[
'message'
][
'bio'
]).
...
...
@@ -364,14 +364,14 @@ describe API::API, api: true do
it
'should return 409 conflict error if email address exists'
do
put
api
(
"/users/
#{
@user
.
id
}
"
,
admin
),
email:
'test@example.com'
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
@user
.
reload
.
email
).
to
eq
(
@user
.
email
)
end
it
'should return 409 conflict error if username taken'
do
@user_id
=
User
.
all
.
last
.
id
put
api
(
"/users/
#{
@user
.
id
}
"
,
admin
),
username:
'test'
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
response
).
to
have_http_status
(
409
)
expect
(
@user
.
reload
.
username
).
to
eq
(
@user
.
username
)
end
end
...
...
@@ -382,13 +382,13 @@ describe API::API, api: true do
it
"should not create invalid ssh key"
do
post
api
(
"/users/
#{
user
.
id
}
/keys"
,
admin
),
{
title:
"invalid key"
}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "key" not given'
)
end
it
'should not create key without title'
do
post
api
(
"/users/
#{
user
.
id
}
/keys"
,
admin
),
key:
'some key'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "title" not given'
)
end
...
...
@@ -401,7 +401,7 @@ describe API::API, api: true do
it
"should return 405 for invalid ID"
do
post
api
(
"/users/ASDF/keys"
,
admin
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
end
end
...
...
@@ -411,14 +411,14 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
"/users/
#{
user
.
id
}
/keys"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when authenticated'
do
it
'should return 404 for non-existing user'
do
get
api
(
'/users/999999/keys'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
...
...
@@ -426,14 +426,14 @@ describe API::API, api: true do
user
.
keys
<<
key
user
.
save
get
api
(
"/users/
#{
user
.
id
}
/keys"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'title'
]).
to
eq
(
key
.
title
)
end
it
"should return 405 for invalid ID"
do
get
api
(
"/users/ASDF/keys"
,
admin
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
end
end
end
...
...
@@ -444,7 +444,7 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
delete
api
(
"/users/
#{
user
.
id
}
/keys/42"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -455,20 +455,20 @@ describe API::API, api: true do
expect
do
delete
api
(
"/users/
#{
user
.
id
}
/keys/
#{
key
.
id
}
"
,
admin
)
end
.
to
change
{
user
.
keys
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should return 404 error if user not found'
do
user
.
keys
<<
key
user
.
save
delete
api
(
"/users/999999/keys/
#{
key
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
it
'should return 404 error if key not foud'
do
delete
api
(
"/users/
#{
user
.
id
}
/keys/42"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Key Not Found'
)
end
end
...
...
@@ -479,7 +479,7 @@ describe API::API, api: true do
it
"should not create invalid email"
do
post
api
(
"/users/
#{
user
.
id
}
/emails"
,
admin
),
{}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "email" not given'
)
end
...
...
@@ -492,7 +492,7 @@ describe API::API, api: true do
it
"should raise error for invalid ID"
do
post
api
(
"/users/ASDF/emails"
,
admin
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
end
end
...
...
@@ -502,14 +502,14 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
get
api
(
"/users/
#{
user
.
id
}
/emails"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
context
'when authenticated'
do
it
'should return 404 for non-existing user'
do
get
api
(
'/users/999999/emails'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
...
...
@@ -517,14 +517,14 @@ describe API::API, api: true do
user
.
emails
<<
email
user
.
save
get
api
(
"/users/
#{
user
.
id
}
/emails"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'email'
]).
to
eq
(
email
.
email
)
end
it
"should raise error for invalid ID"
do
put
api
(
"/users/ASDF/emails"
,
admin
)
expect
(
response
.
status
).
to
eq
(
405
)
expect
(
response
).
to
have_http_status
(
405
)
end
end
end
...
...
@@ -535,7 +535,7 @@ describe API::API, api: true do
context
'when unauthenticated'
do
it
'should return authentication error'
do
delete
api
(
"/users/
#{
user
.
id
}
/emails/42"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -546,20 +546,20 @@ describe API::API, api: true do
expect
do
delete
api
(
"/users/
#{
user
.
id
}
/emails/
#{
email
.
id
}
"
,
admin
)
end
.
to
change
{
user
.
emails
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should return 404 error if user not found'
do
user
.
emails
<<
email
user
.
save
delete
api
(
"/users/999999/emails/
#{
email
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
it
'should return 404 error if email not foud'
do
delete
api
(
"/users/
#{
user
.
id
}
/emails/42"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Email Not Found'
)
end
...
...
@@ -574,24 +574,24 @@ describe API::API, api: true do
it
"should delete user"
do
delete
api
(
"/users/
#{
user
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
{
User
.
find
(
user
.
id
)
}.
to
raise_error
ActiveRecord
::
RecordNotFound
expect
(
json_response
[
'email'
]).
to
eq
(
user
.
email
)
end
it
"should not delete for unauthenticated user"
do
delete
api
(
"/users/
#{
user
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"shouldn't available for non admin users"
do
delete
api
(
"/users/
#{
user
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
it
"should return 404 for non-existing user"
do
delete
api
(
"/users/999999"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
...
...
@@ -603,7 +603,7 @@ describe API::API, api: true do
describe
"GET /user"
do
it
"should return current user"
do
get
api
(
"/user"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'email'
]).
to
eq
(
user
.
email
)
expect
(
json_response
[
'is_admin'
]).
to
eq
(
user
.
is_admin?
)
expect
(
json_response
[
'can_create_project'
]).
to
eq
(
user
.
can_create_project?
)
...
...
@@ -613,7 +613,7 @@ describe API::API, api: true do
it
"should return 401 error if user is unauthenticated"
do
get
api
(
"/user"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -621,7 +621,7 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/user/keys"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -630,7 +630,7 @@ describe API::API, api: true do
user
.
keys
<<
key
user
.
save
get
api
(
"/user/keys"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
"title"
]).
to
eq
(
key
.
title
)
end
...
...
@@ -642,13 +642,13 @@ describe API::API, api: true do
user
.
keys
<<
key
user
.
save
get
api
(
"/user/keys/
#{
key
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"title"
]).
to
eq
(
key
.
title
)
end
it
"should return 404 Not Found within invalid ID"
do
get
api
(
"/user/keys/42"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
...
...
@@ -657,13 +657,13 @@ describe API::API, api: true do
user
.
save
admin
get
api
(
"/user/keys/
#{
key
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
it
"should return 404 for invalid ID"
do
get
api
(
"/users/keys/ASDF"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -673,29 +673,29 @@ describe API::API, api: true do
expect
do
post
api
(
"/user/keys"
,
user
),
key_attrs
end
.
to
change
{
user
.
keys
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
"should return a 401 error if unauthorized"
do
post
api
(
"/user/keys"
),
title:
'some title'
,
key:
'some key'
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"should not create ssh key without key"
do
post
api
(
"/user/keys"
,
user
),
title:
'title'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "key" not given'
)
end
it
'should not create ssh key without title'
do
post
api
(
'/user/keys'
,
user
),
key:
'some key'
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "title" not given'
)
end
it
"should not create ssh key without title"
do
post
api
(
"/user/keys"
,
user
),
key:
"somekey"
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -706,19 +706,19 @@ describe API::API, api: true do
expect
do
delete
api
(
"/user/keys/
#{
key
.
id
}
"
,
user
)
end
.
to
change
{
user
.
keys
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return success if key ID not found"
do
delete
api
(
"/user/keys/42"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return 401 error if unauthorized"
do
user
.
keys
<<
key
user
.
save
delete
api
(
"/user/keys/
#{
key
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"should raise error for invalid ID"
do
...
...
@@ -730,7 +730,7 @@ describe API::API, api: true do
context
"when unauthenticated"
do
it
"should return authentication error"
do
get
api
(
"/user/emails"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -739,7 +739,7 @@ describe API::API, api: true do
user
.
emails
<<
email
user
.
save
get
api
(
"/user/emails"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
"email"
]).
to
eq
(
email
.
email
)
end
...
...
@@ -751,13 +751,13 @@ describe API::API, api: true do
user
.
emails
<<
email
user
.
save
get
api
(
"/user/emails/
#{
email
.
id
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"email"
]).
to
eq
(
email
.
email
)
end
it
"should return 404 Not Found within invalid ID"
do
get
api
(
"/user/emails/42"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
...
...
@@ -766,13 +766,13 @@ describe API::API, api: true do
user
.
save
admin
get
api
(
"/user/emails/
#{
email
.
id
}
"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 Not found'
)
end
it
"should return 404 for invalid ID"
do
get
api
(
"/users/emails/ASDF"
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -782,17 +782,17 @@ describe API::API, api: true do
expect
do
post
api
(
"/user/emails"
,
user
),
email_attrs
end
.
to
change
{
user
.
emails
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
"should return a 401 error if unauthorized"
do
post
api
(
"/user/emails"
),
email:
'some email'
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"should not create email with invalid email"
do
post
api
(
"/user/emails"
,
user
),
{}
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'400 (Bad request) "email" not given'
)
end
end
...
...
@@ -804,19 +804,19 @@ describe API::API, api: true do
expect
do
delete
api
(
"/user/emails/
#{
email
.
id
}
"
,
user
)
end
.
to
change
{
user
.
emails
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return success if email ID not found"
do
delete
api
(
"/user/emails/42"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"should return 401 error if unauthorized"
do
user
.
emails
<<
email
user
.
save
delete
api
(
"/user/emails/
#{
email
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
it
"should raise error for invalid ID"
do
...
...
@@ -828,25 +828,25 @@ describe API::API, api: true do
before
{
admin
}
it
'should block existing user'
do
put
api
(
"/users/
#{
user
.
id
}
/block"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
user
.
reload
.
state
).
to
eq
(
'blocked'
)
end
it
'should not re-block ldap blocked users'
do
put
api
(
"/users/
#{
ldap_blocked_user
.
id
}
/block"
,
admin
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
ldap_blocked_user
.
reload
.
state
).
to
eq
(
'ldap_blocked'
)
end
it
'should not be available for non admin users'
do
put
api
(
"/users/
#{
user
.
id
}
/block"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should return a 404 error if user id not found'
do
put
api
(
'/users/9999/block'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
end
...
...
@@ -857,31 +857,31 @@ describe API::API, api: true do
it
'should unblock existing user'
do
put
api
(
"/users/
#{
user
.
id
}
/unblock"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should unblock a blocked user'
do
put
api
(
"/users/
#{
blocked_user
.
id
}
/unblock"
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
blocked_user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should not unblock ldap blocked users'
do
put
api
(
"/users/
#{
ldap_blocked_user
.
id
}
/unblock"
,
admin
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
ldap_blocked_user
.
reload
.
state
).
to
eq
(
'ldap_blocked'
)
end
it
'should not be available for non admin users'
do
put
api
(
"/users/
#{
user
.
id
}
/unblock"
,
user
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
it
'should return a 404 error if user id not found'
do
put
api
(
'/users/9999/block'
,
admin
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'404 User Not Found'
)
end
...
...
spec/requests/api/variables_spec.rb
View file @
abca19da
...
...
@@ -15,7 +15,7 @@ describe API::API, api: true do
it
'should return project variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_a
(
Array
)
end
end
...
...
@@ -24,7 +24,7 @@ describe API::API, api: true do
it
'should not return project variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -32,7 +32,7 @@ describe API::API, api: true do
it
'should not return project variables'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -42,14 +42,14 @@ describe API::API, api: true do
it
'should return project variable details'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'value'
]).
to
eq
(
variable
.
value
)
end
it
'should respond with 404 Not Found if requesting non-existing variable'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/non_existing_variable"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -57,7 +57,7 @@ describe API::API, api: true do
it
'should not return project variable details'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -65,7 +65,7 @@ describe API::API, api: true do
it
'should not return project variable details'
do
get
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -77,7 +77,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user
),
key:
'TEST_VARIABLE_2'
,
value:
'VALUE_2'
end
.
to
change
{
project
.
variables
.
count
}.
by
(
1
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'key'
]).
to
eq
(
'TEST_VARIABLE_2'
)
expect
(
json_response
[
'value'
]).
to
eq
(
'VALUE_2'
)
end
...
...
@@ -87,7 +87,7 @@ describe API::API, api: true do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user
),
key:
variable
.
key
,
value:
'VALUE_2'
end
.
to
change
{
project
.
variables
.
count
}.
by
(
0
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -95,7 +95,7 @@ describe API::API, api: true do
it
'should not create variable'
do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -103,7 +103,7 @@ describe API::API, api: true do
it
'should not create variable'
do
post
api
(
"/projects/
#{
project
.
id
}
/variables"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -118,7 +118,7 @@ describe API::API, api: true do
updated_variable
=
project
.
variables
.
first
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
value_before
).
to
eq
(
variable
.
value
)
expect
(
updated_variable
.
value
).
to
eq
(
'VALUE_1_UP'
)
end
...
...
@@ -126,7 +126,7 @@ describe API::API, api: true do
it
'should responde with 404 Not Found if requesting non-existing variable'
do
put
api
(
"/projects/
#{
project
.
id
}
/variables/non_existing_variable"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -134,7 +134,7 @@ describe API::API, api: true do
it
'should not update variable'
do
put
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -142,7 +142,7 @@ describe API::API, api: true do
it
'should not update variable'
do
put
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -153,13 +153,13 @@ describe API::API, api: true do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
,
user
)
end
.
to
change
{
project
.
variables
.
count
}.
by
(
-
1
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should responde with 404 Not Found if requesting non-existing variable'
do
delete
api
(
"/projects/
#{
project
.
id
}
/variables/non_existing_variable"
,
user
)
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
...
...
@@ -167,7 +167,7 @@ describe API::API, api: true do
it
'should not delete variable'
do
delete
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
,
user2
)
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
...
...
@@ -175,7 +175,7 @@ describe API::API, api: true do
it
'should not delete variable'
do
delete
api
(
"/projects/
#{
project
.
id
}
/variables/
#{
variable
.
key
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
spec/requests/ci/api/builds_spec.rb
View file @
abca19da
...
...
@@ -26,7 +26,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
,
info:
{
platform: :darwin
}
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'sha'
]).
to
eq
(
build
.
sha
)
expect
(
runner
.
reload
.
platform
).
to
eq
(
"darwin"
)
end
...
...
@@ -34,7 +34,7 @@ describe Ci::API::API do
it
"should return 404 error if no pending build found"
do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return 404 error if no builds for specific runner"
do
...
...
@@ -43,7 +43,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"should return 404 error if no builds for shared runner"
do
...
...
@@ -52,7 +52,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
shared_runner
.
token
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
"returns options"
do
...
...
@@ -61,7 +61,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
,
info:
{
platform: :darwin
}
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"options"
]).
to
eq
({
"image"
=>
"ruby:2.1"
,
"services"
=>
[
"postgres"
]
})
end
...
...
@@ -72,7 +72,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
,
info:
{
platform: :darwin
}
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"variables"
]).
to
eq
([
{
"key"
=>
"CI_BUILD_NAME"
,
"value"
=>
"spinach"
,
"public"
=>
true
},
{
"key"
=>
"CI_BUILD_STAGE"
,
"value"
=>
"test"
,
"public"
=>
true
},
...
...
@@ -91,7 +91,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
,
info:
{
platform: :darwin
}
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"variables"
]).
to
eq
([
{
"key"
=>
"CI_BUILD_NAME"
,
"value"
=>
"spinach"
,
"public"
=>
true
},
{
"key"
=>
"CI_BUILD_STAGE"
,
"value"
=>
"test"
,
"public"
=>
true
},
...
...
@@ -109,7 +109,7 @@ describe Ci::API::API do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
,
info:
{
platform: :darwin
}
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"depends_on_builds"
].
count
).
to
eq
(
2
)
expect
(
json_response
[
"depends_on_builds"
][
0
][
"name"
]).
to
eq
(
"rspec"
)
end
...
...
@@ -122,7 +122,7 @@ describe Ci::API::API do
it
do
post
ci_api
(
"/builds/register"
),
token:
runner
.
token
,
info:
{
param
=>
value
}
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
runner
.
reload
is_expected
.
to
eq
(
value
)
end
...
...
@@ -172,7 +172,7 @@ describe Ci::API::API do
end
it
"should update a running build"
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
'should not override trace information when no trace is given'
do
...
...
@@ -252,13 +252,13 @@ describe Ci::API::API do
context
"should authorize posting artifact to running build"
do
it
"using token as parameter"
do
post
authorize_url
,
{
token:
build
.
token
},
headers
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"TempPath"
]).
not_to
be_nil
end
it
"using token as header"
do
post
authorize_url
,
{},
headers_with_token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
"TempPath"
]).
not_to
be_nil
end
end
...
...
@@ -267,13 +267,13 @@ describe Ci::API::API do
it
"using token as parameter"
do
stub_application_setting
(
max_artifacts_size:
0
)
post
authorize_url
,
{
token:
build
.
token
,
filesize:
100
},
headers
expect
(
response
.
status
).
to
eq
(
413
)
expect
(
response
).
to
have_http_status
(
413
)
end
it
"using token as header"
do
stub_application_setting
(
max_artifacts_size:
0
)
post
authorize_url
,
{
filesize:
100
},
headers_with_token
expect
(
response
.
status
).
to
eq
(
413
)
expect
(
response
).
to
have_http_status
(
413
)
end
end
...
...
@@ -281,7 +281,7 @@ describe Ci::API::API do
before
{
post
authorize_url
,
{
token:
'invalid'
,
filesize:
100
}
}
it
'should respond with forbidden'
do
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -305,20 +305,20 @@ describe Ci::API::API do
context
"should post artifact to running build"
do
it
"uses regual file post"
do
upload_artifacts
(
file_upload
,
headers_with_token
,
false
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"artifacts_file"
][
"filename"
]).
to
eq
(
file_upload
.
original_filename
)
end
it
"uses accelerated file post"
do
upload_artifacts
(
file_upload
,
headers_with_token
,
true
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"artifacts_file"
][
"filename"
]).
to
eq
(
file_upload
.
original_filename
)
end
it
"updates artifact"
do
upload_artifacts
(
file_upload
,
headers_with_token
)
upload_artifacts
(
file_upload2
,
headers_with_token
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
"artifacts_file"
][
"filename"
]).
to
eq
(
file_upload2
.
original_filename
)
end
end
...
...
@@ -343,7 +343,7 @@ describe Ci::API::API do
end
it
'stores artifacts and artifacts metadata'
do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
stored_artifacts_file
.
original_filename
).
to
eq
(
artifacts
.
original_filename
)
expect
(
stored_metadata_file
.
original_filename
).
to
eq
(
metadata
.
original_filename
)
end
...
...
@@ -355,7 +355,7 @@ describe Ci::API::API do
end
it
'is expected to respond with bad request'
do
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'does not store metadata'
do
...
...
@@ -382,7 +382,7 @@ describe Ci::API::API do
it
'updates when specified'
do
build
.
reload
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'artifacts_expire_at'
]).
not_to
be_empty
expect
(
build
.
artifacts_expire_at
).
to
be_within
(
5
.
minutes
).
of
(
Time
.
now
+
7
.
days
)
end
...
...
@@ -393,7 +393,7 @@ describe Ci::API::API do
it
'ignores if not specified'
do
build
.
reload
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'artifacts_expire_at'
]).
to
be_nil
expect
(
build
.
artifacts_expire_at
).
to
be_nil
end
...
...
@@ -404,21 +404,21 @@ describe Ci::API::API do
it
"should fail to post too large artifact"
do
stub_application_setting
(
max_artifacts_size:
0
)
upload_artifacts
(
file_upload
,
headers_with_token
)
expect
(
response
.
status
).
to
eq
(
413
)
expect
(
response
).
to
have_http_status
(
413
)
end
end
context
"artifacts post request does not contain file"
do
it
"should fail to post artifacts without file"
do
post
post_url
,
{},
headers_with_token
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
context
'GitLab Workhorse is not configured'
do
it
"should fail to post artifacts without GitLab-Workhorse"
do
post
post_url
,
{
token:
build
.
token
},
{}
expect
(
response
.
status
).
to
eq
(
403
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
...
...
@@ -437,7 +437,7 @@ describe Ci::API::API do
it
"should fail to post artifacts for outside of tmp path"
do
upload_artifacts
(
file_upload
,
headers_with_token
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
end
...
...
@@ -458,7 +458,7 @@ describe Ci::API::API do
before
{
delete
delete_url
,
token:
build
.
token
}
it
'should remove build artifacts'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
build
.
artifacts_file
.
exists?
).
to
be_falsy
expect
(
build
.
artifacts_metadata
.
exists?
).
to
be_falsy
end
...
...
@@ -475,14 +475,14 @@ describe Ci::API::API do
end
it
'should download artifact'
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
.
headers
).
to
include
download_headers
end
end
context
'build does not has artifacts'
do
it
'should respond with not found'
do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/requests/ci/api/triggers_spec.rb
View file @
abca19da
...
...
@@ -21,17 +21,17 @@ describe Ci::API::API do
context
'Handles errors'
do
it
'should return bad request if token is missing'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/master/trigger"
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
end
it
'should return not found if project is not found'
do
post
ci_api
(
'/projects/0/refs/master/trigger'
),
options
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
it
'should return unauthorized if token is for different project'
do
post
ci_api
(
"/projects/
#{
project2
.
ci_id
}
/refs/master/trigger"
),
options
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -40,14 +40,14 @@ describe Ci::API::API do
it
'should create builds'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/master/trigger"
),
options
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
pipeline
.
builds
.
reload
expect
(
pipeline
.
builds
.
size
).
to
eq
(
2
)
end
it
'should return bad request with no builds created if there\'s no commit for that ref'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/other-branch/trigger"
),
options
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'No builds created'
)
end
...
...
@@ -58,19 +58,19 @@ describe Ci::API::API do
it
'should validate variables to be a hash'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/master/trigger"
),
options
.
merge
(
variables:
'value'
)
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'variables needs to be a hash'
)
end
it
'should validate variables needs to be a map of key-valued strings'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/master/trigger"
),
options
.
merge
(
variables:
{
key:
%w(1 2)
})
expect
(
response
.
status
).
to
eq
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'variables needs to be a map of key-valued strings'
)
end
it
'create trigger request with variables'
do
post
ci_api
(
"/projects/
#{
project
.
ci_id
}
/refs/master/trigger"
),
options
.
merge
(
variables:
variables
)
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
pipeline
.
builds
.
reload
expect
(
pipeline
.
builds
.
first
.
trigger_request
.
variables
).
to
eq
(
variables
)
end
...
...
spec/requests/git_http_spec.rb
View file @
abca19da
...
...
@@ -14,7 +14,7 @@ describe 'Git HTTP requests', lib: true do
context
"when no authentication is provided"
do
it
"responds with status 401 (no project existence information leak)"
do
download
(
'doesnt/exist.git'
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -23,7 +23,7 @@ describe 'Git HTTP requests', lib: true do
context
"when authentication fails"
do
it
"responds with status 401"
do
download
(
'doesnt/exist.git'
,
user:
user
.
username
,
password:
"nope"
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -31,7 +31,7 @@ describe 'Git HTTP requests', lib: true do
context
"when authentication succeeds"
do
it
"responds with status 404"
do
download
(
'/doesnt/exist.git'
,
user:
user
.
username
,
password:
user
.
password
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -46,7 +46,7 @@ describe 'Git HTTP requests', lib: true do
download
(
"/
#{
wiki
.
repository
.
path_with_namespace
}
.git"
)
do
|
response
|
json_body
=
ActiveSupport
::
JSON
.
decode
(
response
.
body
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_body
[
'RepoPath'
]).
to
include
(
wiki
.
repository
.
path_with_namespace
)
end
end
...
...
@@ -62,13 +62,13 @@ describe 'Git HTTP requests', lib: true do
it
"downloads get status 200"
do
download
(
path
,
{})
do
|
response
|
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
it
"uploads get status 401"
do
upload
(
path
,
{})
do
|
response
|
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -77,7 +77,7 @@ describe 'Git HTTP requests', lib: true do
it
"uploads get status 200 (because Git hooks do the real check)"
do
upload
(
path
,
env
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -86,7 +86,7 @@ describe 'Git HTTP requests', lib: true do
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:receive_pack
).
and_return
(
false
)
upload
(
path
,
env
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -97,7 +97,7 @@ describe 'Git HTTP requests', lib: true do
allow
(
Gitlab
.
config
.
gitlab_shell
).
to
receive
(
:upload_pack
).
and_return
(
false
)
download
(
path
,
{})
do
|
response
|
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -111,13 +111,13 @@ describe 'Git HTTP requests', lib: true do
context
"when no authentication is provided"
do
it
"responds with status 401 to downloads"
do
download
(
path
,
{})
do
|
response
|
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
it
"responds with status 401 to uploads"
do
upload
(
path
,
{})
do
|
response
|
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -128,7 +128,7 @@ describe 'Git HTTP requests', lib: true do
context
"when authentication fails"
do
it
"responds with status 401"
do
download
(
path
,
env
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -139,7 +139,7 @@ describe 'Git HTTP requests', lib: true do
clone_get
(
path
,
env
)
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -158,7 +158,7 @@ describe 'Git HTTP requests', lib: true do
project
.
team
<<
[
user
,
:master
]
download
(
path
,
env
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
@@ -169,12 +169,12 @@ describe 'Git HTTP requests', lib: true do
clone_get
(
path
,
env
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"uploads get status 200"
do
upload
(
path
,
env
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -188,13 +188,13 @@ describe 'Git HTTP requests', lib: true do
it
"downloads get status 200"
do
clone_get
"
#{
project
.
path_with_namespace
}
.git"
,
user:
'oauth2'
,
password:
@token
.
token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"uploads get status 401 (no project existence information leak)"
do
push_get
"
#{
project
.
path_with_namespace
}
.git"
,
user:
'oauth2'
,
password:
@token
.
token
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
...
...
@@ -232,13 +232,13 @@ describe 'Git HTTP requests', lib: true do
context
"when the user doesn't have access to the project"
do
it
"downloads get status 404"
do
download
(
path
,
user:
user
.
username
,
password:
user
.
password
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
it
"uploads get status 200 (because Git hooks do the real check)"
do
upload
(
path
,
user:
user
.
username
,
password:
user
.
password
)
do
|
response
|
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
end
...
...
@@ -256,13 +256,13 @@ describe 'Git HTTP requests', lib: true do
it
"downloads get status 200"
do
clone_get
"
#{
project
.
path_with_namespace
}
.git"
,
user:
'gitlab-ci-token'
,
password:
token
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"uploads get status 401 (no project existence information leak)"
do
push_get
"
#{
project
.
path_with_namespace
}
.git"
,
user:
'gitlab-ci-token'
,
password:
token
expect
(
response
.
status
).
to
eq
(
401
)
expect
(
response
).
to
have_http_status
(
401
)
end
end
end
...
...
@@ -336,7 +336,7 @@ describe 'Git HTTP requests', lib: true do
end
it
"returns the file"
do
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
end
end
...
...
@@ -344,7 +344,7 @@ describe 'Git HTTP requests', lib: true do
before
{
get
"/
#{
project
.
path_with_namespace
}
/blob/master/info/refs"
}
it
"returns not found"
do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
...
...
spec/requests/jwt_controller_spec.rb
View file @
abca19da
...
...
@@ -11,12 +11,12 @@ describe JwtController do
context
'existing service'
do
subject!
{
get
'/jwt/auth'
,
parameters
}
it
{
expect
(
response
.
status
).
to
eq
(
200
)
}
it
{
expect
(
response
).
to
have_http_status
(
200
)
}
context
'returning custom http code'
do
let
(
:service
)
{
double
(
execute:
{
http_status:
505
})
}
it
{
expect
(
response
.
status
).
to
eq
(
505
)
}
it
{
expect
(
response
).
to
have_http_status
(
505
)
}
end
end
...
...
@@ -36,7 +36,7 @@ describe JwtController do
context
'project with disabled CI'
do
let
(
:builds_enabled
)
{
false
}
it
{
expect
(
response
.
status
).
to
eq
(
403
)
}
it
{
expect
(
response
).
to
have_http_status
(
403
)
}
end
end
...
...
@@ -56,14 +56,14 @@ describe JwtController do
subject!
{
get
'/jwt/auth'
,
parameters
,
headers
}
it
{
expect
(
response
.
status
).
to
eq
(
403
)
}
it
{
expect
(
response
).
to
have_http_status
(
403
)
}
end
end
context
'unknown service'
do
subject!
{
get
'/jwt/auth'
,
service:
'unknown'
}
it
{
expect
(
response
.
status
).
to
eq
(
404
)
}
it
{
expect
(
response
).
to
have_http_status
(
404
)
}
end
def
credentials
(
login
,
password
)
...
...
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