From a776f00706d6802301c84454bba18a79b08c436e Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Sat, 13 Sep 2014 19:27:37 -0700 Subject: [PATCH] Add #out_of_range? method to PageProxy enhancement for #599. --- lib/kaminari/helpers/paginator.rb | 4 ++++ spec/helpers/tags_spec.rb | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/kaminari/helpers/paginator.rb b/lib/kaminari/helpers/paginator.rb index fb011dd..03d6e42 100644 --- a/lib/kaminari/helpers/paginator.rb +++ b/lib/kaminari/helpers/paginator.rb @@ -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 diff --git a/spec/helpers/tags_spec.rb b/spec/helpers/tags_spec.rb index cbb280e..79b3f3a 100644 --- a/spec/helpers/tags_spec.rb +++ b/spec/helpers/tags_spec.rb @@ -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