Skip to content

Commit d2f8348

Browse files
committed
/site/events: don't show link to the next page when total records less than one page.
Correction for c6f7520 commit.
1 parent 77e9320 commit d2f8348

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/main/java/ru/mystamps/web/util/Pager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ public Pager(long totalRecords, int recordsPerPage, int currentPage) {
8888
}
8989

9090
private static int countTotalPages(int totalRecords, int recordsPerPage) {
91-
return (int)Math.ceil(totalRecords / recordsPerPage);
91+
int totalPages = totalRecords / recordsPerPage;
92+
if (totalRecords % recordsPerPage > 0) {
93+
totalPages++;
94+
}
95+
return totalPages;
9296
}
9397

9498
private static Integer findPrev(int currentPage) {

src/test/groovy/ru/mystamps/web/util/PagerTest.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,11 @@ class PagerTest extends Specification {
216216
3 || null
217217
}
218218

219+
def "getNext() should return null when total records less than records per page"() {
220+
when:
221+
Pager pager = new Pager(2, 25, 1)
222+
then:
223+
pager.next == null
224+
}
225+
219226
}

0 commit comments

Comments
 (0)