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

Fix a bug that paginatable arrays with total_count option always returns whole array

Fixes #516
This commit is contained in:
Yuki Nishijima 2014-05-06 20:04:16 -07:00
parent 324e933dc7
commit 3f752a9f4d
2 changed files with 27 additions and 8 deletions

View file

@ -17,11 +17,11 @@ module Kaminari
extend Kaminari::PageScopeMethods
end
if options[:total_count]
super original_array
else
super(original_array[@_offset_value, @_limit_value] || [])
if @_total_count
original_array = original_array.first(@_total_count)
end
super(original_array[@_offset_value, @_limit_value] || [])
end
def entry_name

View file

@ -142,9 +142,28 @@ describe Kaminari::PaginatableArray do
end
context 'when setting total count explicitly' do
subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
it { should have(10).items }
its(:first) { should == 1 }
its(:total_count) { should == 9999 }
context "total_count > size of the given array" do
subject { Kaminari::PaginatableArray.new((1..10).to_a, :total_count => 9999).page(5).per(10) }
it { should have(0).items }
its(:first) { should be_nil }
its(:total_count) { should == 9999 }
end
context "total_count == size of the given array" do
subject { Kaminari.paginate_array((1..15).to_a, total_count: 15).page(1).per(10) }
it { should have(10).items }
its(:first) { should == 1 }
its(:total_count) { should == 15 }
end
context "total_count < size of the given array" do
subject { Kaminari.paginate_array((1..25).to_a, total_count: 15).page(2).per(10) }
it { should have(5).items }
its(:first) { should == 11 }
its(:total_count) { should == 15 }
end
end
end