Commit acf49c6d authored by Sean McGivern's avatar Sean McGivern

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.
parent 760b2c75
...@@ -76,7 +76,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController ...@@ -76,7 +76,7 @@ class Dashboard::TodosController < Dashboard::ApplicationController
def redirect_out_of_range(todos) def redirect_out_of_range(todos)
total_pages = total_pages =
if todo_params.except(:sort, :page).empty? 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 else
todos.total_pages todos.total_pages
end end
......
---
title: Fix access to the final page of todos
merge_request:
author:
type: fixed
...@@ -44,11 +44,11 @@ describe Dashboard::TodosController do ...@@ -44,11 +44,11 @@ describe Dashboard::TodosController do
context 'when using pagination' do context 'when using pagination' do
let(:last_page) { user.todos.page.total_pages } 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 before do
issues.each { |issue| todo_service.new_issue(issue, user) } 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 end
it 'redirects to last_page if page number is larger than number of pages' do it 'redirects to last_page if page number is larger than number of pages' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment