Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
32691ffd
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,发现更多精彩内容 >>
提交
32691ffd
编写于
2月 21, 2017
作者:
R
Robert Schilling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Backport Todos API to V3
上级
1ef911f0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
102 addition
and
0 deletion
+102
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/v3/todos.rb
lib/api/v3/todos.rb
+28
-0
spec/requests/api/v3/todos_spec.rb
spec/requests/api/v3/todos_spec.rb
+73
-0
未找到文件。
lib/api/api.rb
浏览文件 @
32691ffd
...
...
@@ -19,6 +19,7 @@ module API
mount
::
API
::
V3
::
Repositories
mount
::
API
::
V3
::
SystemHooks
mount
::
API
::
V3
::
Tags
mount
::
API
::
V3
::
Todos
mount
::
API
::
V3
::
Templates
mount
::
API
::
V3
::
Users
end
...
...
lib/api/v3/todos.rb
0 → 100644
浏览文件 @
32691ffd
module
API
module
V3
class
Todos
<
Grape
::
API
before
{
authenticate!
}
resource
:todos
do
desc
'Mark a todo as done'
do
success
::
API
::
Entities
::
Todo
end
params
do
requires
:id
,
type:
Integer
,
desc:
'The ID of the todo being marked as done'
end
delete
':id'
do
todo
=
current_user
.
todos
.
find
(
params
[
:id
])
TodoService
.
new
.
mark_todos_as_done
([
todo
],
current_user
)
present
todo
.
reload
,
with:
::
API
::
Entities
::
Todo
,
current_user:
current_user
end
desc
'Mark all todos as done'
delete
do
todos
=
TodosFinder
.
new
(
current_user
,
params
).
execute
TodoService
.
new
.
mark_todos_as_done
(
todos
,
current_user
)
end
end
end
end
end
spec/requests/api/v3/todos_spec.rb
0 → 100644
浏览文件 @
32691ffd
require
'spec_helper'
describe
API
::
V3
::
Todos
,
api:
true
do
include
ApiHelpers
let
(
:project_1
)
{
create
(
:empty_project
)
}
let
(
:project_2
)
{
create
(
:empty_project
)
}
let
(
:author_1
)
{
create
(
:user
)
}
let
(
:author_2
)
{
create
(
:user
)
}
let
(
:john_doe
)
{
create
(
:user
,
username:
'john_doe'
)
}
let!
(
:pending_1
)
{
create
(
:todo
,
:mentioned
,
project:
project_1
,
author:
author_1
,
user:
john_doe
)
}
let!
(
:pending_2
)
{
create
(
:todo
,
project:
project_2
,
author:
author_2
,
user:
john_doe
)
}
let!
(
:pending_3
)
{
create
(
:todo
,
project:
project_1
,
author:
author_2
,
user:
john_doe
)
}
let!
(
:done
)
{
create
(
:todo
,
:done
,
project:
project_1
,
author:
author_1
,
user:
john_doe
)
}
before
do
project_1
.
team
<<
[
john_doe
,
:developer
]
project_2
.
team
<<
[
john_doe
,
:developer
]
end
describe
'DELETE /todos/:id'
do
context
'when unauthenticated'
do
it
'returns authentication error'
do
delete
v3_api
(
"/todos/
#{
pending_1
.
id
}
"
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
context
'when authenticated'
do
it
'marks a todo as done'
do
delete
v3_api
(
"/todos/
#{
pending_1
.
id
}
"
,
john_doe
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
pending_1
.
reload
).
to
be_done
end
it
'updates todos cache'
do
expect_any_instance_of
(
User
).
to
receive
(
:update_todos_count_cache
).
and_call_original
delete
v3_api
(
"/todos/
#{
pending_1
.
id
}
"
,
john_doe
)
end
end
end
describe
'DELETE /todos'
do
context
'when unauthenticated'
do
it
'returns authentication error'
do
delete
v3_api
(
'/todos'
)
expect
(
response
.
status
).
to
eq
(
401
)
end
end
context
'when authenticated'
do
it
'marks all todos as done'
do
delete
v3_api
(
'/todos'
,
john_doe
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
response
.
body
).
to
eq
(
'3'
)
expect
(
pending_1
.
reload
).
to
be_done
expect
(
pending_2
.
reload
).
to
be_done
expect
(
pending_3
.
reload
).
to
be_done
end
it
'updates todos cache'
do
expect_any_instance_of
(
User
).
to
receive
(
:update_todos_count_cache
).
and_call_original
delete
v3_api
(
"/todos"
,
john_doe
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录