Fix wrong pagination when used with padding #359

Merged
merged 1 commit into from Apr 23, 2013

Projects

None yet

4 participants

@vladimir-vg
Contributor

Pagination just breaks when used with padding, because total_pages and current_page doesn't checks is padding used.

For example:

source = [
  # padding
  1, 2, 3, 4,

  # first page
  5, 6, 7,

  # second
  8, 9,
]
arr = Kaminari.paginate_array(source).page(2).per(3).padding(4)

puts arr.inspect
# => [8, 9] which is correct

puts arr.total_pages # => 3
# whoops, that's wrong, 2 was expected

puts arr.current_page # => 3
# also wrong, 2 was expected

Array used just for example, I encounter same problem when work with active record.

I fixed it, but probably it can be written in more sound style to the rest of code.

Owner
yuki24 commented Apr 1, 2013

@vladimir-vg Thank you for the PR! Could you provide some failng tests for the PR?

Owner

@vladimir-vg Confirmed the bug. Going to merge your PR. Thanks!

@amatsuda amatsuda merged commit ee5954f into kaminari:master Apr 23, 2013
borski commented May 3, 2013

I think this is still not working, actually.

[26] pry(main)> a = [1,2,3,4,5,6,7,8,9]
=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
[27] pry(main)> b = Kaminari.paginate_array(a).page(2).per(3).padding(4)
=> [8, 9]
[28] pry(main)> b
=> [8, 9]
[29] pry(main)> b.total_pages
=> 3
[30] pry(main)> b.current_page
=> 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment