mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Do not display link to previous page if scope is out of range
This commit is contained in:
parent
fce39505df
commit
5c5d158278
5 changed files with 26 additions and 2 deletions
|
@ -41,7 +41,7 @@ module Kaminari
|
|||
def link_to_previous_page(scope, name, options = {}, &block)
|
||||
prev_page = Kaminari::Helpers::PrevPage.new self, options.reverse_merge(:current_page => scope.current_page)
|
||||
|
||||
link_to_unless scope.first_page?, name, prev_page.url, options.except(:params, :param_name).reverse_merge(:rel => 'prev') do
|
||||
link_to_if scope.prev_page.present?, name, prev_page.url, options.except(:params, :param_name).reverse_merge(:rel => 'prev') do
|
||||
block.call if block
|
||||
end
|
||||
end
|
||||
|
|
|
@ -55,7 +55,7 @@ module Kaminari
|
|||
|
||||
# Previous page number in the collection
|
||||
def prev_page
|
||||
current_page - 1 unless first_page?
|
||||
current_page - 1 unless first_page? || current_page > (total_pages + 1)
|
||||
end
|
||||
|
||||
# First page of the collection?
|
||||
|
|
|
@ -69,6 +69,13 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do
|
|||
subject { helper.link_to_previous_page @users, 'Previous', :params => {:controller => 'users', :action => 'index'} }
|
||||
it { should_not be }
|
||||
end
|
||||
|
||||
context 'out of range' do
|
||||
before { @users = User.page(5) }
|
||||
|
||||
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
||||
it { should_not be }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#link_to_next_page' do
|
||||
|
@ -110,6 +117,13 @@ describe 'Kaminari::ActionViewExtension', :if => defined?(Rails) do
|
|||
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
||||
it { should_not be }
|
||||
end
|
||||
|
||||
context 'out of range' do
|
||||
before { @users = User.page(5) }
|
||||
|
||||
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
||||
it { should_not be }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#page_entries_info' do
|
||||
|
|
|
@ -204,6 +204,11 @@ if defined? ActiveRecord
|
|||
subject { model_class.page(5) }
|
||||
its(:prev_page) { should == 4 }
|
||||
end
|
||||
|
||||
context 'page 6' do
|
||||
subject { model_class.page(6) }
|
||||
its(:prev_page) { should be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#first_page?' do
|
||||
|
|
|
@ -141,6 +141,11 @@ describe Kaminari::PaginatableArray do
|
|||
subject { array.page 5 }
|
||||
its(:prev_page) { should == 4 }
|
||||
end
|
||||
|
||||
context 'page 6' do
|
||||
subject { array.page 6 }
|
||||
its(:prev_page) { should be_nil }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#count' do
|
||||
|
|
Loading…
Reference in a new issue