Fix #570: make per(nil) respect max_per_page#800
Fix #570: make per(nil) respect max_per_page#800jonathanhefner wants to merge 2 commits intokaminari:masterfrom
Conversation
This makes `per` always respect `max_per_page`, fixing kaminari#570. The issue actually applies to any invalid argument, e.g. `per("bad")`. Now, when an invalid argument is given, `per` uses `default_per_page` in its place.
| limit(n) | ||
| elsif max_per_page && max_per_page < n | ||
| limit(max_per_page).offset(offset_value / limit_value * max_per_page) | ||
| if num == 0 || num == '0' |
There was a problem hiding this comment.
This is more efficient, but does not handle unlikely corner cases. For example " 0 " and "-0" will fall through to the else. (Note: "-0" was not handled in the previous version, either.)
I can change this, if we want to be extremely thorough. Thoughts?
This makes `per` handle abnormal expressions of zero, such as "000" and "-0". Negative numbers and non-numeric inputs are still treated as if they were nil.
|
As mentioned in my comment, I modified When given bad input, |
|
@yuki24 Are there any changes that should be made? Any additional tests you would like me to add? |
|
Happy to contribute! Thank you! 😄 |
This makes
peralways respectmax_per_page, fixing #570. The issue actually applies to any invalid argument, e.g.per("bad"). Now, when an invalid argument is given,perusesdefault_per_pagein its place.