paginator: fix showing page 5000 when page count is unknown

Fix a bug where if you did a slow search that took too long to calculate
the page count, and you had 200 posts per page, then we would show page
5000 as the last page of the search.

This was because we were artificially returning 1,000,000 as the post
count to signal that the count timed out, but at 200 posts per page this
would show 5000 as the last page of the search.
This commit is contained in:
evazion
2021-09-08 18:26:52 -05:00
parent 668dd50ea8
commit 55d00fc40c
3 changed files with 19 additions and 4 deletions

View File

@@ -76,6 +76,19 @@ class PaginatorComponentTest < ViewComponent::TestCase
assert_css("span", count: 3)
end
end
context "for a search with an unknown number of pages" do
should "show the unlimited paginator" do
@tags = Tag.all
@tags.stubs(:total_count).returns(Float::INFINITY)
html = render_paginator(:numbered, @tags, page: 1, limit: 200)
assert_css("span.paginator-current", text: "1")
assert_css("span.paginator-prev")
assert_css("a.paginator-next")
assert_css(".paginator a.paginator-page", count: 4, visible: :all)
end
end
end
end
end