mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Fix a bug that PaginatableArray#total_pages returns the wrong value
closes #416
This commit is contained in:
parent
9be421d916
commit
ed4e6f042b
2 changed files with 8 additions and 3 deletions
|
@ -11,7 +11,7 @@ module Kaminari
|
|||
# * <tt>:offset</tt> - offset
|
||||
# * <tt>:total_count</tt> - total_count
|
||||
def initialize(original_array = [], options = {})
|
||||
@_original_array, @_limit_value, @_offset_value, @_total_count = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count]
|
||||
@_original_array, @_limit_value, @_offset_value, @_total_count, @_padding = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count], options[:padding].to_i
|
||||
|
||||
if options[:limit] && options[:offset]
|
||||
extend Kaminari::PageScopeMethods
|
||||
|
@ -33,7 +33,7 @@ module Kaminari
|
|||
|
||||
# returns another chunk of the original array
|
||||
def limit(num)
|
||||
self.class.new @_original_array, :limit => num, :offset => @_offset_value, :total_count => @_total_count
|
||||
self.class.new @_original_array, :limit => num, :offset => @_offset_value, :total_count => @_total_count, :padding => @_padding
|
||||
end
|
||||
|
||||
# total item numbers of the original array
|
||||
|
@ -43,7 +43,7 @@ module Kaminari
|
|||
|
||||
# returns another chunk of the original array
|
||||
def offset(num)
|
||||
self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count
|
||||
self.class.new @_original_array, :limit => @_limit_value, :offset => num, :total_count => @_total_count, :padding => @_padding
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -86,6 +86,11 @@ describe Kaminari::PaginatableArray do
|
|||
subject { array.page(5).per('aho') }
|
||||
its(:total_pages) { should == 4 }
|
||||
end
|
||||
|
||||
context 'per 25, padding 25' do
|
||||
subject { array.page(1).padding(25) }
|
||||
its(:total_pages) { should == 3 }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#current_page' do
|
||||
|
|
Loading…
Reference in a new issue