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:
parent
6c0d1b66c1
commit
b5e16c0a94
2 changed files with 8 additions and 3 deletions
|
@ -11,8 +11,13 @@ module Kaminari
|
||||||
# * <tt>:total_count</tt> - total_count
|
# * <tt>:total_count</tt> - total_count
|
||||||
def initialize(original_array, options = {})
|
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 = original_array, (options[:limit] || default_per_page).to_i, options[:offset].to_i, options[:total_count]
|
||||||
|
|
||||||
|
if options[:total_count]
|
||||||
|
super original_array
|
||||||
|
else
|
||||||
super(original_array[@_offset_value, @_limit_value] || [])
|
super(original_array[@_offset_value, @_limit_value] || [])
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# items at the specified "page"
|
# items at the specified "page"
|
||||||
def page(num = 1)
|
def page(num = 1)
|
||||||
|
|
|
@ -106,9 +106,9 @@ describe Kaminari::PaginatableArray do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when setting total count explicitly' do
|
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 }
|
it { should have(10).items }
|
||||||
its(:first) { should == 41 }
|
its(:first) { should == 1 }
|
||||||
its(:total_count) { should == 9999 }
|
its(:total_count) { should == 9999 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue