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

Add #out_of_range? method

closes #306, and closes #366
This commit is contained in:
Yuki Nishijima 2013-06-18 22:10:43 +09:00
parent 69e44c6f15
commit 8e48e45aa5
2 changed files with 23 additions and 1 deletions

View file

@ -67,5 +67,10 @@ module Kaminari
def last_page? def last_page?
current_page >= total_pages current_page >= total_pages
end end
# Out of range of the collection?
def out_of_range?
current_page > total_pages
end
end end
end end

View file

@ -201,6 +201,23 @@ if defined? ActiveRecord
end end
end end
describe '#out_of_range?' do
context 'on last page' do
subject { model_class.page(10).per(10) }
its(:out_of_range?) { should == false }
end
context 'within range' do
subject { model_class.page(1).per(10) }
its(:out_of_range?) { should == false }
end
context 'out of range' do
subject { model_class.page(11).per(10) }
its(:out_of_range?) { should == true }
end
end
describe '#count' do describe '#count' do
context 'page 1' do context 'page 1' do
subject { model_class.page } subject { model_class.page }