mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
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:
parent
b8d9abb58f
commit
21baf16c04
3 changed files with 11 additions and 1 deletions
|
@ -25,7 +25,9 @@ module Kaminari
|
||||||
end
|
end
|
||||||
|
|
||||||
def padding(num)
|
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)
|
offset(offset_value + @_padding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,10 @@ if defined? ActiveRecord
|
||||||
assert_equal 19, relation.current_page
|
assert_equal 19, relation.current_page
|
||||||
assert_equal 19, relation.total_pages
|
assert_equal 19, relation.total_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'Negative padding' do
|
||||||
|
assert_raise(ArgumentError) { model_class.page(1).per(5).padding(-1) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sub_test_case '#total_pages' do
|
sub_test_case '#total_pages' do
|
||||||
|
|
|
@ -88,6 +88,10 @@ class PaginatableArrayTest < ActiveSupport::TestCase
|
||||||
test 'per 25, padding 25' do
|
test 'per 25, padding 25' do
|
||||||
assert_equal 3, @array.page(1).padding(25).total_pages
|
assert_equal 3, @array.page(1).padding(25).total_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'Negative padding' do
|
||||||
|
assert_raise(ArgumentError) { @array.page(1).per(5).padding(-1) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sub_test_case '#total_pages' do
|
sub_test_case '#total_pages' do
|
||||||
|
|
Loading…
Reference in a new issue