Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6bd7e1b8
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6bd7e1b8
编写于
1月 04, 2019
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for Release Link API
Add tests for the API and add a couple of tests Add revert revert
上级
124905e2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
477 addition
and
52 deletion
+477
-52
lib/api/release/links.rb
lib/api/release/links.rb
+44
-43
spec/fixtures/api/schemas/release.json
spec/fixtures/api/schemas/release.json
+1
-9
spec/fixtures/api/schemas/release/link.json
spec/fixtures/api/schemas/release/link.json
+11
-0
spec/fixtures/api/schemas/release/links.json
spec/fixtures/api/schemas/release/links.json
+4
-0
spec/requests/api/release/links_spec.rb
spec/requests/api/release/links_spec.rb
+417
-0
未找到文件。
lib/api/release/link.rb
→
lib/api/release/link
s
.rb
浏览文件 @
6bd7e1b8
...
...
@@ -14,6 +14,9 @@ module API
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
'projects/:id'
,
requirements:
API
::
NAMESPACE_OR_PROJECT_REQUIREMENTS
do
params
do
requires
:tag_name
,
type:
String
,
desc:
'The name of the tag'
,
as: :tag
end
resource
'releases/:tag_name'
,
requirements:
RELEASE_ENDPOINT_REQUIREMETS
do
resource
:assets
do
desc
'Get a list of links of a release'
do
...
...
@@ -26,20 +29,7 @@ module API
get
'links'
do
authorize!
:read_release
,
release
present
paginate
(
release
.
links
),
with:
Entities
::
Releases
::
Link
end
desc
'Get a link detail of a release'
do
detail
'This feature was introduced in GitLab 11.7.'
success
Entities
::
Releases
::
Link
end
params
do
requires
:link_id
,
type:
String
,
desc:
'The id of the link'
end
get
'links/:link_id'
do
authorize!
:read_release
,
release
present
link
,
with:
Entities
::
Releases
::
Link
present
paginate
(
release
.
links
.
sorted
),
with:
Entities
::
Releases
::
Link
end
desc
'Create a link of a release'
do
...
...
@@ -58,44 +48,55 @@ module API
if
new_link
.
persisted?
present
new_link
,
with:
Entities
::
Releases
::
Link
else
render_api_error!
(
result
[
:message
],
result
[
:http_status
]
)
render_api_error!
(
new_link
.
errors
.
messages
,
400
)
end
end
desc
'Update a link of a release'
do
detail
'This feature was introduced in GitLab 11.7.'
success
Entities
::
Releases
::
Link
end
params
do
requires
:link_id
,
type:
Integer
,
desc:
'The id of the link'
optional
:name
,
type:
String
,
desc:
'The name of the link'
optional
:url
,
type:
String
,
desc:
'The URL of the link'
at_least_one_of
:name
,
:url
requires
:link_id
,
type:
String
,
desc:
'The id of the link'
end
put
'links/:link_id'
do
authorize!
:update_release
,
release
resource
'links/:link_id'
do
desc
'Get a link detail of a release'
do
detail
'This feature was introduced in GitLab 11.7.'
success
Entities
::
Releases
::
Link
end
get
do
authorize!
:read_release
,
release
if
link
.
update
(
declared_params
(
include_missing:
false
))
present
link
,
with:
Entities
::
Releases
::
Link
else
render_api_error!
(
result
[
:message
],
result
[
:http_status
])
end
end
desc
'Delete a link of a release'
do
detail
'This feature was introduced in GitLab 11.7.'
success
Entities
::
Releases
::
Link
end
params
do
requires
:link_id
,
type:
Integer
,
desc:
'The id of the link'
end
put
'links/:link_id'
do
authorize!
:destroy_release
,
release
desc
'Update a link of a release'
do
detail
'This feature was introduced in GitLab 11.7.'
success
Entities
::
Releases
::
Link
end
params
do
optional
:name
,
type:
String
,
desc:
'The name of the link'
optional
:url
,
type:
String
,
desc:
'The URL of the link'
at_least_one_of
:name
,
:url
end
put
do
authorize!
:update_release
,
release
if
link
.
update
(
declared_params
(
include_missing:
false
))
present
link
,
with:
Entities
::
Releases
::
Link
else
render_api_error!
(
link
.
errors
.
messages
,
400
)
end
end
if
link
.
destroy
present
link
,
with:
Entities
::
Releases
::
Link
else
render_api_error!
(
result
[
:message
],
result
[
:http_status
])
desc
'Delete a link of a release'
do
detail
'This feature was introduced in GitLab 11.7.'
success
Entities
::
Releases
::
Link
end
delete
do
authorize!
:destroy_release
,
release
if
link
.
destroy
present
link
,
with:
Entities
::
Releases
::
Link
else
render_api_error!
(
link
.
errors
.
messages
,
400
)
end
end
end
end
...
...
@@ -104,7 +105,7 @@ module API
helpers
do
def
release
@release
||=
user_project
.
releases
.
find_by_tag
(
params
[
:tag_name
])
@release
||=
user_project
.
releases
.
find_by_tag
!
(
params
[
:tag
])
end
def
link
...
...
spec/fixtures/api/schemas/release.json
浏览文件 @
6bd7e1b8
...
...
@@ -15,15 +15,7 @@
},
"assets"
:
{
"count"
:
{
"type"
:
"integer"
},
"links"
:
{
"type"
:
"array"
,
"items"
:
{
"id"
:
"integer"
,
"name"
:
"string"
,
"url"
:
"string"
,
"external"
:
"boolean"
}
},
"links"
:
{
"$ref"
:
"release/links.json"
},
"sources"
:
{
"type"
:
"array"
,
"items"
:
{
...
...
spec/fixtures/api/schemas/release/link.json
0 → 100644
浏览文件 @
6bd7e1b8
{
"type"
:
"object"
,
"required"
:
[
"name"
,
"url"
],
"properties"
:
{
"id"
:
{
"type"
:
"integer"
},
"name"
:
{
"type"
:
"string"
},
"url"
:
{
"type"
:
"string"
},
"external"
:
{
"type"
:
"boolean"
}
},
"additionalProperties"
:
false
}
spec/fixtures/api/schemas/release/links.json
0 → 100644
浏览文件 @
6bd7e1b8
{
"type"
:
"array"
,
"items"
:
{
"$ref"
:
"link.json"
}
}
spec/requests/api/release/links_spec.rb
0 → 100644
浏览文件 @
6bd7e1b8
# frozen_string_literal: true
require
'spec_helper'
describe
API
::
Release
::
Links
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
let
(
:maintainer
)
{
create
(
:user
)
}
let
(
:reporter
)
{
create
(
:user
)
}
let
(
:non_project_member
)
{
create
(
:user
)
}
let
(
:commit
)
{
create
(
:commit
,
project:
project
)
}
let!
(
:release
)
do
create
(
:release
,
project:
project
,
tag:
'v0.1'
,
author:
maintainer
)
end
before
do
project
.
add_maintainer
(
maintainer
)
project
.
add_reporter
(
reporter
)
project
.
repository
.
add_tag
(
maintainer
,
'v0.1'
,
commit
.
id
)
end
describe
'GET /projects/:id/releases/:tag_name/assets/links'
do
context
'when there are two release links'
do
let!
(
:release_link_1
)
{
create
(
:release_link
,
release:
release
,
created_at:
2
.
days
.
ago
)
}
let!
(
:release_link_2
)
{
create
(
:release_link
,
release:
release
,
created_at:
1
.
day
.
ago
)
}
it
'returns 200 HTTP status'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'returns release links ordered by created_at'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
)
expect
(
json_response
.
count
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
release_link_2
.
name
)
expect
(
json_response
.
second
[
'name'
]).
to
eq
(
release_link_1
.
name
)
end
it
'matches response schema'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
)
expect
(
response
).
to
match_response_schema
(
'release/links'
)
end
end
context
'when release does not exist'
do
let!
(
:release
)
{
}
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
)
}
let
(
:message
)
{
'404 Not found'
}
end
end
context
'when user is not a project member'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
non_project_member
)
}
let
(
:message
)
{
'404 Project Not Found'
}
end
context
'when project is public'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
it
'allows the request'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
non_project_member
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
releases_page:
false
)
end
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
)
}
end
end
end
describe
'GET /projects/:id/releases/:tag_name/assets/links/:link_id'
do
let!
(
:release_link
)
{
create
(
:release_link
,
release:
release
)
}
it
'returns 200 HTTP status'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'returns a link entry'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
expect
(
json_response
[
'name'
]).
to
eq
(
release_link
.
name
)
expect
(
json_response
[
'url'
]).
to
eq
(
release_link
.
url
)
end
it
'matches response schema'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
expect
(
response
).
to
match_response_schema
(
'release/link'
)
end
context
'when specified tag is not found in the project'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/releases/non_existing_tag/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
}
end
end
context
'when user is not a project member'
do
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/releases/non_existing_tag/assets/links/
#{
release_link
.
id
}
"
,
non_project_member
)
}
end
context
'when project is public'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
it
'allows the request'
do
get
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
non_project_member
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
end
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
releases_page:
false
)
end
it_behaves_like
'404 response'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/releases/non_existing_tag/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
}
end
end
end
describe
'POST /projects/:id/releases/:tag_name/assets/links'
do
let
(
:params
)
do
{
name:
'awesome-app.dmg'
,
url:
'https://example.com/download/awesome-app.dmg'
}
end
it
'accepts the request'
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
end
it
'creates a new release'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
),
params:
params
end
.
to
change
{
Releases
::
Link
.
count
}.
by
(
1
)
release
.
reload
expect
(
release
.
links
.
last
.
name
).
to
eq
(
'awesome-app.dmg'
)
expect
(
release
.
links
.
last
.
url
).
to
eq
(
'https://example.com/download/awesome-app.dmg'
)
end
it
'matches response schema'
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
),
params:
params
expect
(
response
).
to
match_response_schema
(
'release/link'
)
end
context
'when name is empty'
do
let
(
:params
)
do
{
name:
''
,
url:
'https://example.com/download/awesome-app.dmg'
}
end
it_behaves_like
'400 response'
do
let
(
:request
)
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
),
params:
params
end
end
end
context
'when user is a reporter'
do
it_behaves_like
'403 response'
do
let
(
:request
)
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
reporter
),
params:
params
end
end
end
context
'when user is not a project member'
do
it
'forbids the request'
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
non_project_member
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
context
'when project is public'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
it
'forbids the request'
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
non_project_member
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
context
'when the same link already exists'
do
before
do
create
(
:release_link
,
release:
release
,
name:
'awesome-app.dmg'
,
url:
'https://example.com/download/awesome-app.dmg'
)
end
it_behaves_like
'400 response'
do
let
(
:request
)
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
),
params:
params
end
end
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
releases_page:
false
)
end
it_behaves_like
'404 response'
do
let
(
:request
)
do
post
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links"
,
maintainer
),
params:
params
end
end
end
end
describe
'PUT /projects/:id/releases/:tag_name/assets/links/:link_id'
do
let
(
:params
)
{
{
name:
'awesome-app.msi'
}
}
let!
(
:release_link
)
{
create
(
:release_link
,
release:
release
)
}
it
'accepts the request'
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'updates the name'
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
),
params:
params
expect
(
json_response
[
'name'
]).
to
eq
(
'awesome-app.msi'
)
end
it
'does not update the url'
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
),
params:
params
expect
(
json_response
[
'url'
]).
to
eq
(
release_link
.
url
)
end
it
'matches response schema'
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
),
params:
params
expect
(
response
).
to
match_response_schema
(
'release/link'
)
end
context
'when params is empty'
do
let
(
:params
)
{
{}
}
it
'does not allow the request'
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
),
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
'when there are no corresponding release link'
do
let!
(
:release_link
)
{
}
it_behaves_like
'404 response'
do
let
(
:request
)
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/1"
,
maintainer
),
params:
params
end
end
end
context
'when user is a reporter'
do
it_behaves_like
'403 response'
do
let
(
:request
)
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
reporter
),
params:
params
end
end
end
context
'when user is not a project member'
do
it_behaves_like
'404 response'
do
let
(
:request
)
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
non_project_member
),
params:
params
end
end
context
'when project is public'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
it_behaves_like
'403 response'
do
let
(
:request
)
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
non_project_member
),
params:
params
end
end
end
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
releases_page:
false
)
end
it_behaves_like
'404 response'
do
let
(
:request
)
do
put
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
),
params:
params
end
end
end
end
describe
'DELETE /projects/:id/releases/:tag_name/assets/links/:link_id'
do
let!
(
:release_link
)
do
create
(
:release_link
,
release:
release
)
end
it
'accepts the request'
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
it
'destroys the release link'
do
expect
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
end
.
to
change
{
Releases
::
Link
.
count
}.
by
(
-
1
)
end
it
'matches response schema'
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
expect
(
response
).
to
match_response_schema
(
'release/link'
)
end
context
'when there are no corresponding release link'
do
let!
(
:release_link
)
{
}
it_behaves_like
'404 response'
do
let
(
:request
)
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/1"
,
maintainer
)
end
end
end
context
'when user is a reporter'
do
it_behaves_like
'403 response'
do
let
(
:request
)
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
reporter
)
end
end
end
context
'when user is not a project member'
do
it_behaves_like
'404 response'
do
let
(
:request
)
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
non_project_member
)
end
end
context
'when project is public'
do
let
(
:project
)
{
create
(
:project
,
:repository
,
:public
)
}
it_behaves_like
'403 response'
do
let
(
:request
)
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
non_project_member
)
end
end
end
end
context
'when feature flag is disabled'
do
before
do
stub_feature_flags
(
releases_page:
false
)
end
it_behaves_like
'404 response'
do
let
(
:request
)
do
delete
api
(
"/projects/
#{
project
.
id
}
/releases/v0.1/assets/links/
#{
release_link
.
id
}
"
,
maintainer
)
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录