2011-02-05 09:20:06 -05:00
|
|
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
|
|
include Kaminari::Helpers
|
|
|
|
|
|
|
|
describe 'Kaminari::Helpers::PaginationRenderer' do
|
2011-02-13 04:25:07 -05:00
|
|
|
let :template do
|
2011-02-05 09:20:06 -05:00
|
|
|
stub(r = Object.new) do
|
|
|
|
render.with_any_args
|
|
|
|
params { {} }
|
|
|
|
url_for {|h| "/foo?page=#{h[:page]}"}
|
|
|
|
end
|
|
|
|
r
|
|
|
|
end
|
2011-02-13 04:25:07 -05:00
|
|
|
|
|
|
|
describe '#params' do
|
2011-02-16 08:52:55 -05:00
|
|
|
before do
|
|
|
|
@renderer = PaginationRenderer.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
|
|
|
end
|
|
|
|
subject { @renderer.instance_variable_get '@template' }
|
2011-02-13 04:25:07 -05:00
|
|
|
its(:params) { should == {:controller => 'foo', :action => 'bar'} }
|
|
|
|
end
|
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
#TODO test somehow...
|
|
|
|
# describe '#tagify_links' do
|
|
|
|
# def tags_with(options)
|
|
|
|
# PaginationRenderer.new(template, options).tagify_links
|
|
|
|
# end
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# context '1 page in total' do
|
|
|
|
# subject { tags_with :num_pages => 1, :current_page => 1 }
|
|
|
|
# it { should have(0).tags }
|
|
|
|
# end
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-08 11:40:09 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-05 09:20:06 -05:00
|
|
|
|
2011-02-16 08:52:55 -05:00
|
|
|
# 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
|
2011-02-05 09:20:06 -05:00
|
|
|
end
|