refs #30 specs for new pagination helper

This commit is contained in:
Akira Matsuda 2011-02-27 20:28:00 +09:00
parent afc7dc1b44
commit 468fccfa39
2 changed files with 37 additions and 6 deletions

View File

@ -13,7 +13,7 @@ feature 'Users' do
page.should have_content '1' page.should have_content '1'
end end
within 'span.next' do within 'span.next' do
click_link 'Next »' click_link 'Next '
end end
end end
@ -21,8 +21,8 @@ feature 'Users' do
within 'span.page.current' do within 'span.page.current' do
page.should have_content '2' page.should have_content '2'
end end
within 'span.page.last' do within 'span.last' do
click_link '4' click_link 'Last »'
end end
end end
@ -31,7 +31,7 @@ feature 'Users' do
page.should have_content '4' page.should have_content '4'
end end
within 'span.prev' do within 'span.prev' do
click_link '« Prev' click_link ' Prev'
end end
end end
@ -39,6 +39,15 @@ feature 'Users' do
within 'span.page.current' do within 'span.page.current' do
page.should have_content '3' page.should have_content '3'
end end
within 'span.first' do
click_link '« First'
end
end
within 'nav.pagination' do
within 'span.page.current' do
page.should have_content '1'
end
end end
end end
end end

View File

@ -60,6 +60,28 @@ describe 'Kaminari::Helpers' do
end end
end end
describe '#next?' do
context 'page == current_page + 1' do
subject { Paginator::PageProxy.new({:current_page => 52}, 53, nil) }
its(:next?) { should be_true }
end
context 'page != current_page + 1' do
subject { Paginator::PageProxy.new({:current_page => 52}, 77, nil) }
its(:next?) { should_not be_true }
end
end
describe '#prev?' do
context 'page == current_page - 1' do
subject { Paginator::PageProxy.new({:current_page => 77}, 76, nil) }
its(:prev?) { should be_true }
end
context 'page != current_page + 1' do
subject { Paginator::PageProxy.new({:current_page => 77}, 80, nil) }
its(:prev?) { should_not be_true }
end
end
describe '#left_outer?' do describe '#left_outer?' do
context 'current_page == left' do context 'current_page == left' do
subject { Paginator::PageProxy.new({:left => 3}, 3, nil) } subject { Paginator::PageProxy.new({:left => 3}, 3, nil) }
@ -67,7 +89,7 @@ describe 'Kaminari::Helpers' do
end end
context 'current_page == left + 1' do context 'current_page == left + 1' do
subject { Paginator::PageProxy.new({:left => 3}, 4, nil) } subject { Paginator::PageProxy.new({:left => 3}, 4, nil) }
its(:left_outer?) { should be_true } its(:left_outer?) { should_not be_true }
end end
context 'current_page == left + 2' do context 'current_page == left + 2' do
subject { Paginator::PageProxy.new({:left => 3}, 5, nil) } subject { Paginator::PageProxy.new({:left => 3}, 5, nil) }
@ -82,7 +104,7 @@ describe 'Kaminari::Helpers' do
end end
context 'num_pages - page == right' do context 'num_pages - page == right' do
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 7, nil) } subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 7, nil) }
its(:right_outer?) { should be_true } its(:right_outer?) { should_not be_true }
end end
context 'num_pages - page < right' do context 'num_pages - page < right' do
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 8, nil) } subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 8, nil) }