mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Merge pull request #583 from lime/last-page-consistency
Make last_page? behave consistently with last?
This commit is contained in:
commit
608bac0f85
4 changed files with 10 additions and 5 deletions
|
@ -66,7 +66,7 @@ module Kaminari
|
|||
def link_to_next_page(scope, name, options = {}, &block)
|
||||
next_page = Kaminari::Helpers::NextPage.new self, options.reverse_merge(:current_page => scope.current_page)
|
||||
|
||||
link_to_unless scope.last_page?, name, next_page.url, options.except(:params, :param_name).reverse_merge(:rel => 'next') do
|
||||
link_to_unless scope.last_page? || scope.out_of_range?, name, next_page.url, options.except(:params, :param_name).reverse_merge(:rel => 'next') do
|
||||
block.call if block
|
||||
end
|
||||
end
|
||||
|
|
|
@ -145,7 +145,7 @@ module Kaminari::Helpers
|
|||
param_name = options.delete(:param_name) || Kaminari.config.param_name
|
||||
placeholder = options.delete(:placeholder)
|
||||
|
||||
unless scope.last_page?
|
||||
unless scope.last_page? || scope.out_of_range?
|
||||
query = params.merge(param_name => scope.next_page)
|
||||
link_to name, env['PATH_INFO'] + (query.empty? ? '' : "?#{query.to_query}"), options.reverse_merge(:rel => 'next')
|
||||
else
|
||||
|
|
|
@ -44,7 +44,7 @@ module Kaminari
|
|||
|
||||
# Next page number in the collection
|
||||
def next_page
|
||||
current_page + 1 unless last_page?
|
||||
current_page + 1 unless last_page? || out_of_range?
|
||||
end
|
||||
|
||||
# Previous page number in the collection
|
||||
|
@ -59,7 +59,7 @@ module Kaminari
|
|||
|
||||
# Last page of the collection?
|
||||
def last_page?
|
||||
current_page >= total_pages
|
||||
current_page == total_pages
|
||||
end
|
||||
|
||||
# Out of range of the collection?
|
||||
|
|
|
@ -210,10 +210,15 @@ if defined? ActiveRecord
|
|||
its(:last_page?) { should == true }
|
||||
end
|
||||
|
||||
context 'not on last page' do
|
||||
context 'within range' do
|
||||
subject { model_class.page(1).per(10) }
|
||||
its(:last_page?) { should == false }
|
||||
end
|
||||
|
||||
context 'out of range' do
|
||||
subject { model_class.page(11).per(10) }
|
||||
its(:last_page?) { should == false }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#out_of_range?' do
|
||||
|
|
Loading…
Reference in a new issue