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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
d40f9294
Commit
d40f9294
authored
Sep 06, 2020
by
gaga5lala
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REFACTOR: valid params leverage on Grape DSL
parent
9412b5ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
9 deletions
+32
-9
lib/api/todos.rb
lib/api/todos.rb
+13
-6
spec/requests/api/todos_spec.rb
spec/requests/api/todos_spec.rb
+19
-3
No files found.
lib/api/todos.rb
View file @
d40f9294
...
...
@@ -11,10 +11,6 @@ module API
'issues'
=>
->
(
iid
)
{
find_project_issue
(
iid
)
}
}.
freeze
rescue_from
ArgumentError
do
|
e
|
render_api_error!
(
e
.
message
,
400
)
end
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
...
...
@@ -43,8 +39,19 @@ module API
resource
:todos
do
helpers
do
params
:todo_filters
do
optional
:action_id
,
Integer
optional
:action
,
Array
[
String
],
values:
Todo
::
ACTION_NAMES
.
values
.
map
(
&
:to_s
)
optional
:author_id
,
Integer
optional
:state
,
String
,
values:
Todo
.
state_machine
.
states
.
map
(
&
:name
).
map
(
&
:to_s
)
optional
:target_id
,
Integer
optional
:type
,
Array
[
String
],
values:
TodosFinder
.
todo_types
optional
:project_id
,
Integer
optional
:group_id
,
Integer
end
def
find_todos
TodosFinder
.
new
(
current_user
,
params
).
execute
TodosFinder
.
new
(
current_user
,
declared_params
(
include_missing:
false
)
).
execute
end
def
issuable_and_awardable?
(
type
)
...
...
@@ -76,7 +83,7 @@ module API
success
Entities
::
Todo
end
params
do
use
:pagination
use
:pagination
,
:todo_filters
end
get
do
todos
=
paginate
(
find_todos
.
with_entity_associations
)
...
...
spec/requests/api/todos_spec.rb
View file @
d40f9294
...
...
@@ -35,9 +35,25 @@ RSpec.describe API::Todos do
context
'when authenticated'
do
context
'when invalid params'
do
it
"returns argument error"
do
get
api
(
'/todos'
,
john_doe
),
params:
{
type:
'InvalidType'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
context
"invalid action"
do
it
'returns argument error'
do
get
api
(
'/todos'
,
john_doe
),
params:
{
action:
'InvalidAction'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
"invalid state"
do
it
'returns argument error'
do
get
api
(
'/todos'
,
john_doe
),
params:
{
state:
'InvalidState'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
end
end
context
"invalid type"
do
it
'returns argument error'
do
get
api
(
'/todos'
,
john_doe
),
params:
{
type:
'InvalidType'
}
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
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