1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00

keep the whole Array if total_count is given

This commit is contained in:
Akira Matsuda 2011-08-26 08:12:10 +09:00
parent 6c0d1b66c1
commit b5e16c0a94
2 changed files with 8 additions and 3 deletions

View file

@ -11,7 +11,12 @@ module Kaminari
# * <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]
super(original_array[@_offset_value, @_limit_value] || [])
if options[:total_count]
super original_array
else
super(original_array[@_offset_value, @_limit_value] || [])
end
end
# items at the specified "page"

View file

@ -106,9 +106,9 @@ describe Kaminari::PaginatableArray do
end
context 'when setting total count explicitly' do
subject { Kaminari::PaginatableArray.new((1..100).to_a, :total_count => 9999).page(5).per(10) }
subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
it { should have(10).items }
its(:first) { should == 41 }
its(:first) { should == 1 }
its(:total_count) { should == 9999 }
end
end