From 23186e5c9cb42e800fa7af1e1dab458a53123a13 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 9 Feb 2011 01:40:09 +0900 Subject: [PATCH] fixes #2 show nothing when num_page == 1 --- lib/kaminari/helpers.rb | 1 + spec/helpers/helpers_spec.rb | 171 ++++++++++++++++++----------------- 2 files changed, 90 insertions(+), 82 deletions(-) diff --git a/lib/kaminari/helpers.rb b/lib/kaminari/helpers.rb index 4b20fe7..316f763 100644 --- a/lib/kaminari/helpers.rb +++ b/lib/kaminari/helpers.rb @@ -67,6 +67,7 @@ module Kaminari def tagify_links num_pages, current_page, left, window, right = @options[:num_pages], @options[:current_page], @left, @window, @right + return [] if num_pages <= 1 tags = [] tags << (current_page > 1 ? PrevLink.new(self) : PrevSpan.new(self)) diff --git a/spec/helpers/helpers_spec.rb b/spec/helpers/helpers_spec.rb index 2e7cc3f..eab56a4 100644 --- a/spec/helpers/helpers_spec.rb +++ b/spec/helpers/helpers_spec.rb @@ -15,95 +15,102 @@ describe 'Kaminari::Helpers::PaginationRenderer' do PaginationRenderer.new(renderer, options).tagify_links end - context 'first page' do - subject { tags_with :num_pages => 10, :current_page => 1 } - it { should_not contain_tag PrevLink } - it { should contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should_not contain_tag FirstPageLink } - it { should contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should contain_tag NextLink } - it { should_not contain_tag NextSpan } - it { should contain_tag TruncatedSpan } + context '1 page in total' do + subject { tags_with :num_pages => 1, :current_page => 1 } + it { should have(0).tags } end - context 'second page' do - subject { tags_with :num_pages => 10, :current_page => 2 } - it { should contain_tag PrevLink } - it { should_not contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should contain_tag FirstPageLink } - it { should contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should contain_tag NextLink } - it { should_not contain_tag NextSpan } - it { should contain_tag TruncatedSpan } - end + context '10 pages in total' do + context 'first page' do + subject { tags_with :num_pages => 10, :current_page => 1 } + it { should_not contain_tag PrevLink } + it { should contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should_not contain_tag FirstPageLink } + it { should contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should contain_tag NextLink } + it { should_not contain_tag NextSpan } + it { should contain_tag TruncatedSpan } + end - context 'third page' do - subject { tags_with :num_pages => 10, :current_page => 3 } - it { should contain_tag PrevLink } - it { should_not contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should contain_tag FirstPageLink } - it { should contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should contain_tag NextLink } - it { should_not contain_tag NextSpan } - it { should contain_tag TruncatedSpan } - end + context 'second page' do + subject { tags_with :num_pages => 10, :current_page => 2 } + it { should contain_tag PrevLink } + it { should_not contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should contain_tag FirstPageLink } + it { should contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should contain_tag NextLink } + it { should_not contain_tag NextSpan } + it { should contain_tag TruncatedSpan } + end - context 'fourth page(no truncation)' do - subject { tags_with :num_pages => 10, :current_page => 4 } - it { should contain_tag PrevLink } - it { should_not contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should contain_tag FirstPageLink } - it { should contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should contain_tag NextLink } - it { should_not contain_tag NextSpan } - it { should_not contain_tag TruncatedSpan } - end + context 'third page' do + subject { tags_with :num_pages => 10, :current_page => 3 } + it { should contain_tag PrevLink } + it { should_not contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should contain_tag FirstPageLink } + it { should contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should contain_tag NextLink } + it { should_not contain_tag NextSpan } + it { should contain_tag TruncatedSpan } + end - context 'seventh page(no truncation)' do - subject { tags_with :num_pages => 10, :current_page => 7 } - it { should contain_tag PrevLink } - it { should_not contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should contain_tag FirstPageLink } - it { should contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should contain_tag NextLink } - it { should_not contain_tag NextSpan } - it { should_not contain_tag TruncatedSpan } - end + context 'fourth page(no truncation)' do + subject { tags_with :num_pages => 10, :current_page => 4 } + it { should contain_tag PrevLink } + it { should_not contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should contain_tag FirstPageLink } + it { should contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should contain_tag NextLink } + it { should_not contain_tag NextSpan } + it { should_not contain_tag TruncatedSpan } + end - context 'eighth page' do - subject { tags_with :num_pages => 10, :current_page => 8 } - it { should contain_tag PrevLink } - it { should_not contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should contain_tag FirstPageLink } - it { should contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should contain_tag NextLink } - it { should_not contain_tag NextSpan } - it { should contain_tag TruncatedSpan } - end + context 'seventh page(no truncation)' do + subject { tags_with :num_pages => 10, :current_page => 7 } + it { should contain_tag PrevLink } + it { should_not contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should contain_tag FirstPageLink } + it { should contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should contain_tag NextLink } + it { should_not contain_tag NextSpan } + it { should_not contain_tag TruncatedSpan } + end - context 'last page' do - subject { tags_with :num_pages => 10, :current_page => 10 } - it { should contain_tag PrevLink } - it { should_not contain_tag PrevSpan } - it { should contain_tag CurrentPage } - it { should contain_tag FirstPageLink } - it { should_not contain_tag LastPageLink } - it { should contain_tag PageLink } - it { should_not contain_tag NextLink } - it { should contain_tag NextSpan } - it { should contain_tag TruncatedSpan } + context 'eighth page' do + subject { tags_with :num_pages => 10, :current_page => 8 } + it { should contain_tag PrevLink } + it { should_not contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should contain_tag FirstPageLink } + it { should contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should contain_tag NextLink } + it { should_not contain_tag NextSpan } + it { should contain_tag TruncatedSpan } + end + + context 'last page' do + subject { tags_with :num_pages => 10, :current_page => 10 } + it { should contain_tag PrevLink } + it { should_not contain_tag PrevSpan } + it { should contain_tag CurrentPage } + it { should contain_tag FirstPageLink } + it { should_not contain_tag LastPageLink } + it { should contain_tag PageLink } + it { should_not contain_tag NextLink } + it { should contain_tag NextSpan } + it { should contain_tag TruncatedSpan } + end end end end