Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
822dac87
Commit
822dac87
authored
Dec 04, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract tests for project hooks API
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
882029d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
116 deletions
+132
-116
spec/requests/api/project_hooks_spec.rb
spec/requests/api/project_hooks_spec.rb
+132
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+0
-116
No files found.
spec/requests/api/project_hooks_spec.rb
0 → 100644
View file @
822dac87
require
'spec_helper'
describe
API
::
API
,
'ProjectHooks'
do
include
ApiHelpers
before
(
:each
)
{
enable_observers
}
after
(
:each
)
{
disable_observers
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user3
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project_with_code
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let!
(
:hook
)
{
create
(
:project_hook
,
project:
project
,
url:
"http://example.com"
)
}
before
do
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user3
,
:developer
]
end
describe
"GET /projects/:id/hooks"
do
context
"authorized user"
do
it
"should return project hooks"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
1
json_response
.
first
[
'url'
].
should
==
"http://example.com"
end
end
context
"unauthorized user"
do
it
"should not access project hooks"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user3
)
response
.
status
.
should
==
403
end
end
end
describe
"GET /projects/:id/hooks/:hook_id"
do
context
"authorized user"
do
it
"should return a project hook"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
[
'url'
].
should
==
hook
.
url
end
it
"should return a 404 error if hook id is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
)
response
.
status
.
should
==
404
end
end
context
"unauthorized user"
do
it
"should not access an existing hook"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user3
)
response
.
status
.
should
==
403
end
end
it
"should return a 404 error if hook id is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
)
response
.
status
.
should
==
404
end
end
describe
"POST /projects/:id/hooks"
do
it
"should add hook to project"
do
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
url:
"http://example.com"
}.
to
change
{
project
.
hooks
.
count
}.
by
(
1
)
response
.
status
.
should
==
201
end
it
"should return a 400 error if url not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
400
end
it
"should return a 422 error if url not valid"
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
"url"
=>
"ftp://example.com"
response
.
status
.
should
==
422
end
end
describe
"PUT /projects/:id/hooks/:hook_id"
do
it
"should update an existing project hook"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
),
url:
'http://example.org'
response
.
status
.
should
==
200
json_response
[
'url'
].
should
==
'http://example.org'
end
it
"should return 404 error if hook id not found"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
),
url:
'http://example.org'
response
.
status
.
should
==
404
end
it
"should return 400 error if url is not given"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
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'
response
.
status
.
should
==
422
end
end
describe
"DELETE /projects/:id/hooks/:hook_id"
do
it
"should delete hook from project"
do
expect
{
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
}.
to
change
{
project
.
hooks
.
count
}.
by
(
-
1
)
response
.
status
.
should
==
200
end
it
"should return success when deleting hook"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
200
end
it
"should return success when deleting non existent hook"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/42"
,
user
)
response
.
status
.
should
==
200
end
it
"should return a 405 error if hook id not given"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
405
end
end
end
spec/requests/api/projects_spec.rb
View file @
822dac87
...
@@ -10,7 +10,6 @@ describe API::API do
...
@@ -10,7 +10,6 @@ describe API::API do
let
(
:user3
)
{
create
(
:user
)
}
let
(
:user3
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let!
(
:project
)
{
create
(
:project_with_code
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let!
(
:project
)
{
create
(
:project_with_code
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let!
(
:hook
)
{
create
(
:project_hook
,
project:
project
,
url:
"http://example.com"
)
}
let!
(
:snippet
)
{
create
(
:project_snippet
,
author:
user
,
project:
project
,
title:
'example'
)
}
let!
(
:snippet
)
{
create
(
:project_snippet
,
author:
user
,
project:
project
,
title:
'example'
)
}
let!
(
:users_project
)
{
create
(
:users_project
,
user:
user
,
project:
project
,
project_access:
UsersProject
::
MASTER
)
}
let!
(
:users_project
)
{
create
(
:users_project
,
user:
user
,
project:
project
,
project_access:
UsersProject
::
MASTER
)
}
let!
(
:users_project2
)
{
create
(
:users_project
,
user:
user3
,
project:
project
,
project_access:
UsersProject
::
DEVELOPER
)
}
let!
(
:users_project2
)
{
create
(
:users_project
,
user:
user3
,
project:
project
,
project_access:
UsersProject
::
DEVELOPER
)
}
...
@@ -439,121 +438,6 @@ describe API::API do
...
@@ -439,121 +438,6 @@ describe API::API do
end
end
end
end
describe
"GET /projects/:id/hooks"
do
context
"authorized user"
do
it
"should return project hooks"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
1
json_response
.
first
[
'url'
].
should
==
"http://example.com"
end
end
context
"unauthorized user"
do
it
"should not access project hooks"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user3
)
response
.
status
.
should
==
403
end
end
end
describe
"GET /projects/:id/hooks/:hook_id"
do
context
"authorized user"
do
it
"should return a project hook"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
[
'url'
].
should
==
hook
.
url
end
it
"should return a 404 error if hook id is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
)
response
.
status
.
should
==
404
end
end
context
"unauthorized user"
do
it
"should not access an existing hook"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user3
)
response
.
status
.
should
==
403
end
end
it
"should return a 404 error if hook id is not available"
do
get
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
)
response
.
status
.
should
==
404
end
end
describe
"POST /projects/:id/hooks"
do
it
"should add hook to project"
do
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
url:
"http://example.com"
}.
to
change
{
project
.
hooks
.
count
}.
by
(
1
)
response
.
status
.
should
==
201
end
it
"should return a 400 error if url not given"
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
400
end
it
"should return a 422 error if url not valid"
do
post
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
),
"url"
=>
"ftp://example.com"
response
.
status
.
should
==
422
end
end
describe
"PUT /projects/:id/hooks/:hook_id"
do
it
"should update an existing project hook"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
),
url:
'http://example.org'
response
.
status
.
should
==
200
json_response
[
'url'
].
should
==
'http://example.org'
end
it
"should return 404 error if hook id not found"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/1234"
,
user
),
url:
'http://example.org'
response
.
status
.
should
==
404
end
it
"should return 400 error if url is not given"
do
put
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
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'
response
.
status
.
should
==
422
end
end
describe
"DELETE /projects/:id/hooks/:hook_id"
do
it
"should delete hook from project"
do
expect
{
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
}.
to
change
{
project
.
hooks
.
count
}.
by
(
-
1
)
response
.
status
.
should
==
200
end
it
"should return success when deleting hook"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/
#{
hook
.
id
}
"
,
user
)
response
.
status
.
should
==
200
end
it
"should return success when deleting non existent hook"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks/42"
,
user
)
response
.
status
.
should
==
200
end
it
"should return a 405 error if hook id not given"
do
delete
api
(
"/projects/
#{
project
.
id
}
/hooks"
,
user
)
response
.
status
.
should
==
405
end
end
describe
"GET /projects/:id/snippets"
do
describe
"GET /projects/:id/snippets"
do
it
"should return an array of project snippets"
do
it
"should return an array of project snippets"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/snippets"
,
user
)
...
...
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