BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
32691ffd
Commit
32691ffd
authored
Feb 21, 2017
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport Todos API to V3
parent
1ef911f0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
0 deletions
+102
-0
api.rb
lib/api/api.rb
+1
-0
todos.rb
lib/api/v3/todos.rb
+28
-0
todos_spec.rb
spec/requests/api/v3/todos_spec.rb
+73
-0
No files found.
lib/api/api.rb
View file @
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
View file @
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
View file @
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
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