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
bf9bd068
Commit
bf9bd068
authored
Oct 05, 2017
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'save-a-query-on-todos-with-no-filters' into 'master'
Save a query on the todos index page See merge request gitlab-org/gitlab-ce!14686
parents
5ae8e378
063b9edc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
todos_controller.rb
app/controllers/dashboard/todos_controller.rb
+26
-4
save-a-query-on-todos-with-no-filters.yml
...logs/unreleased/save-a-query-on-todos-with-no-filters.yml
+5
-0
todos_controller_spec.rb
spec/controllers/dashboard/todos_controller_spec.rb
+25
-1
No files found.
app/controllers/dashboard/todos_controller.rb
View file @
bf9bd068
...
...
@@ -7,9 +7,8 @@ class Dashboard::TodosController < Dashboard::ApplicationController
def
index
@sort
=
params
[
:sort
]
@todos
=
@todos
.
page
(
params
[
:page
])
if
@todos
.
out_of_range?
&&
@todos
.
total_pages
!=
0
redirect_to
url_for
(
params
.
merge
(
page:
@todos
.
total_pages
,
only_path:
true
))
end
return
if
redirect_out_of_range
(
@todos
)
end
def
destroy
...
...
@@ -60,7 +59,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
end
def
find_todos
@todos
||=
TodosFinder
.
new
(
current_user
,
params
).
execute
@todos
||=
TodosFinder
.
new
(
current_user
,
todo_
params
).
execute
end
def
todos_counts
...
...
@@ -69,4 +68,27 @@ class Dashboard::TodosController < Dashboard::ApplicationController
done_count:
number_with_delimiter
(
current_user
.
todos_done_count
)
}
end
def
todo_params
params
.
permit
(
:action_id
,
:author_id
,
:project_id
,
:type
,
:sort
,
:state
)
end
def
redirect_out_of_range
(
todos
)
total_pages
=
if
todo_params
.
except
(
:sort
,
:page
).
empty?
(
current_user
.
todos_pending_count
/
todos
.
limit_value
).
ceil
else
todos
.
total_pages
end
return
false
if
total_pages
.
zero?
out_of_range
=
todos
.
current_page
>
total_pages
if
out_of_range
redirect_to
url_for
(
params
.
merge
(
page:
total_pages
,
only_path:
true
))
end
out_of_range
end
end
changelogs/unreleased/save-a-query-on-todos-with-no-filters.yml
0 → 100644
View file @
bf9bd068
---
title
:
Remove a SQL query from the todos index page
merge_request
:
author
:
type
:
other
spec/controllers/dashboard/todos_controller_spec.rb
View file @
bf9bd068
...
...
@@ -57,7 +57,7 @@ describe Dashboard::TodosController do
expect
(
response
).
to
redirect_to
(
dashboard_todos_path
(
page:
last_page
))
end
it
'
redirects to corresponden
t page'
do
it
'
goes to the correc
t page'
do
get
:index
,
page:
last_page
expect
(
assigns
(
:todos
).
current_page
).
to
eq
(
last_page
)
...
...
@@ -70,6 +70,30 @@ describe Dashboard::TodosController do
expect
(
response
).
to
redirect_to
(
dashboard_todos_path
(
page:
last_page
))
end
context
'when providing no filters'
do
it
'does not perform a query to get the page count, but gets that from the user'
do
allow
(
controller
).
to
receive
(
:current_user
).
and_return
(
user
)
expect
(
user
).
to
receive
(
:todos_pending_count
).
and_call_original
get
:index
,
page:
(
last_page
+
1
).
to_param
,
sort: :created_asc
expect
(
response
).
to
redirect_to
(
dashboard_todos_path
(
page:
last_page
,
sort: :created_asc
))
end
end
context
'when providing filters'
do
it
'performs a query to get the correct page count'
do
allow
(
controller
).
to
receive
(
:current_user
).
and_return
(
user
)
expect
(
user
).
not_to
receive
(
:todos_pending_count
)
get
:index
,
page:
(
last_page
+
1
).
to_param
,
project_id:
project
.
id
expect
(
response
).
to
redirect_to
(
dashboard_todos_path
(
page:
last_page
,
project_id:
project
.
id
))
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