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
...
@@ -11,10 +11,6 @@ module API
'issues'
=>
->
(
iid
)
{
find_project_issue
(
iid
)
}
'issues'
=>
->
(
iid
)
{
find_project_issue
(
iid
)
}
}.
freeze
}.
freeze
rescue_from
ArgumentError
do
|
e
|
render_api_error!
(
e
.
message
,
400
)
end
params
do
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
end
...
@@ -43,8 +39,19 @@ module API
...
@@ -43,8 +39,19 @@ module API
resource
:todos
do
resource
:todos
do
helpers
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
def
find_todos
TodosFinder
.
new
(
current_user
,
params
).
execute
TodosFinder
.
new
(
current_user
,
declared_params
(
include_missing:
false
)
).
execute
end
end
def
issuable_and_awardable?
(
type
)
def
issuable_and_awardable?
(
type
)
...
@@ -76,7 +83,7 @@ module API
...
@@ -76,7 +83,7 @@ module API
success
Entities
::
Todo
success
Entities
::
Todo
end
end
params
do
params
do
use
:pagination
use
:pagination
,
:todo_filters
end
end
get
do
get
do
todos
=
paginate
(
find_todos
.
with_entity_associations
)
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
...
@@ -35,9 +35,25 @@ RSpec.describe API::Todos do
context
'when authenticated'
do
context
'when authenticated'
do
context
'when invalid params'
do
context
'when invalid params'
do
it
"returns argument error"
do
context
"invalid action"
do
get
api
(
'/todos'
,
john_doe
),
params:
{
type:
'InvalidType'
}
it
'returns argument error'
do
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
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
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