Add #out_of_range? method to PageProxy

enhancement for #599.
This commit is contained in:
Yuki Nishijima 2014-09-13 19:27:37 -07:00
parent f5030681d7
commit a776f00706
2 changed files with 21 additions and 0 deletions

View File

@ -171,6 +171,10 @@ module Kaminari
(@page.to_i == @options[:current_page] + @options[:window] + 1) && (@page.to_i == @options[:total_pages] - @options[:right])
end
def out_of_range?
@page > @options[:total_pages]
end
# The last rendered tag was "truncated" or not
def was_truncated?
@last.is_a? Gap

View File

@ -233,6 +233,23 @@ describe 'Kaminari::Helpers' do
its("gap for 8") { gap_for(8).should be_a_single_gap }
end
end
describe "#out_of_range?" do
context 'within range' do
subject { Paginator::PageProxy.new({:total_pages => 5}, 4, nil).out_of_range? }
it { should == false }
end
context 'on last page' do
subject { Paginator::PageProxy.new({:total_pages => 5}, 5, nil).out_of_range? }
it { should == false }
end
context 'out of range' do
subject { Paginator::PageProxy.new({:total_pages => 5}, 6, nil).out_of_range? }
it { should == true }
end
end
end
end
end