summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-11-09 13:13:48 +0000
committerSean McGivern <sean@gitlab.com>2017-11-09 13:13:48 +0000
commitacf49c6d89a38806fd722c2b9052f99c68822e43 (patch)
treeed001d07ed570d362007dc88c44dce38856599ec
parent760b2c75ef9d2c6acb655860dceae4c04cd8e5a7 (diff)
downloadgitlab-ce-acf49c6d89a38806fd722c2b9052f99c68822e43.tar.gz
Fix access to the final page of todos
The todos page limit is 20, and both that and a user's pending todo count are integers. Using integer division means that the result's floor will be taken, defeating the point of the later call to `#ceil`. So we need to convert one side of the division to a float first, otherwise the last page won't be treated as available.
-rw-r--r--app/controllers/dashboard/todos_controller.rb2
-rw-r--r--changelogs/unreleased/fix-todos-last-page.yml5
-rw-r--r--spec/controllers/dashboard/todos_controller_spec.rb4
3 files changed, 8 insertions, 3 deletions
diff --git a/app/controllers/dashboard/todos_controller.rb b/app/controllers/dashboard/todos_controller.rb
index 02c5857eea7..e89eaf7edda 100644
--- a/app/controllers/dashboard/todos_controller.rb
+++ b/app/controllers/dashboard/todos_controller.rb
@@ -76,7 +76,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
def redirect_out_of_range(todos)
total_pages =
if todo_params.except(:sort, :page).empty?
- (current_user.todos_pending_count / todos.limit_value).ceil
+ (current_user.todos_pending_count.to_f / todos.limit_value).ceil
else
todos.total_pages
end
diff --git a/changelogs/unreleased/fix-todos-last-page.yml b/changelogs/unreleased/fix-todos-last-page.yml
new file mode 100644
index 00000000000..efcdbb75e6e
--- /dev/null
+++ b/changelogs/unreleased/fix-todos-last-page.yml
@@ -0,0 +1,5 @@
+---
+title: Fix access to the final page of todos
+merge_request:
+author:
+type: fixed
diff --git a/spec/controllers/dashboard/todos_controller_spec.rb b/spec/controllers/dashboard/todos_controller_spec.rb
index d862e1447e3..f9faa4fa59a 100644
--- a/spec/controllers/dashboard/todos_controller_spec.rb
+++ b/spec/controllers/dashboard/todos_controller_spec.rb
@@ -44,11 +44,11 @@ describe Dashboard::TodosController do
context 'when using pagination' do
let(:last_page) { user.todos.page.total_pages }
- let!(:issues) { create_list(:issue, 2, project: project, assignees: [user]) }
+ let!(:issues) { create_list(:issue, 3, project: project, assignees: [user]) }
before do
issues.each { |issue| todo_service.new_issue(issue, user) }
- allow(Kaminari.config).to receive(:default_per_page).and_return(1)
+ allow(Kaminari.config).to receive(:default_per_page).and_return(2)
end
it 'redirects to last_page if page number is larger than number of pages' do