Don't accept negative value for padding

Because negative offset behavior is so unpredictable: https://github.com/amatsuda/kaminari/issues/839#issuecomment-268211318

closes #839
This commit is contained in:
Akira Matsuda 2017-01-05 15:43:50 +09:00
parent b8d9abb58f
commit 21baf16c04
3 changed files with 11 additions and 1 deletions

View File

@ -25,7 +25,9 @@ module Kaminari
end
def padding(num)
@_padding = num.to_i
num = num.to_i
raise ArgumentError, "padding must not be negative" if num < 0
@_padding = num
offset(offset_value + @_padding)
end

View File

@ -203,6 +203,10 @@ if defined? ActiveRecord
assert_equal 19, relation.current_page
assert_equal 19, relation.total_pages
end
test 'Negative padding' do
assert_raise(ArgumentError) { model_class.page(1).per(5).padding(-1) }
end
end
sub_test_case '#total_pages' do

View File

@ -88,6 +88,10 @@ class PaginatableArrayTest < ActiveSupport::TestCase
test 'per 25, padding 25' do
assert_equal 3, @array.page(1).padding(25).total_pages
end
test 'Negative padding' do
assert_raise(ArgumentError) { @array.page(1).per(5).padding(-1) }
end
end
sub_test_case '#total_pages' do