2011-12-11 01:15:18 +09:00
|
|
|
require 'spec_helper'
|
2011-02-05 23:20:06 +09:00
|
|
|
include Kaminari::Helpers
|
|
|
|
|
2011-02-27 23:25:16 +09:00
|
|
|
describe 'Kaminari::Helpers::Paginator' do
|
2011-02-13 18:25:07 +09:00
|
|
|
let :template do
|
2011-02-05 23:20:06 +09:00
|
|
|
stub(r = Object.new) do
|
|
|
|
render.with_any_args
|
|
|
|
params { {} }
|
2011-02-27 23:25:16 +09:00
|
|
|
options { {} }
|
2011-02-05 23:20:06 +09:00
|
|
|
url_for {|h| "/foo?page=#{h[:page]}"}
|
|
|
|
end
|
|
|
|
r
|
|
|
|
end
|
2011-02-13 18:25:07 +09:00
|
|
|
|
|
|
|
describe '#params' do
|
2011-02-16 22:52:55 +09:00
|
|
|
before do
|
2011-02-27 23:25:16 +09:00
|
|
|
@paginator = Paginator.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
2011-02-16 22:52:55 +09:00
|
|
|
end
|
2011-02-27 23:25:16 +09:00
|
|
|
subject { @paginator.page_tag(template).instance_variable_get('@params') }
|
|
|
|
it { should == {:controller => 'foo', :action => 'bar'} }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#param_name' do
|
|
|
|
before do
|
|
|
|
@paginator = Paginator.new(template, :param_name => :pagina)
|
|
|
|
end
|
|
|
|
subject { @paginator.page_tag(template).instance_variable_get('@param_name') }
|
|
|
|
it { should == :pagina }
|
2011-02-13 18:25:07 +09:00
|
|
|
end
|
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
#TODO test somehow...
|
|
|
|
# describe '#tagify_links' do
|
|
|
|
# def tags_with(options)
|
|
|
|
# PaginationRenderer.new(template, options).tagify_links
|
|
|
|
# end
|
2011-02-05 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context '1 page in total' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 1, :current_page => 1 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# it { should have(0).tags }
|
|
|
|
# end
|
2011-02-05 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context '10 pages in total' do
|
|
|
|
# context 'first page' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 1 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context 'second page' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 2 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context 'third page' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 3 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context 'fourth page(no truncation)' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 4 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context 'seventh page(no truncation)' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 7 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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-09 01:40:09 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context 'eighth page' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 8 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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 23:20:06 +09:00
|
|
|
|
2011-02-16 22:52:55 +09:00
|
|
|
# context 'last page' do
|
2012-05-25 15:31:53 +09:00
|
|
|
# subject { tags_with :total_pages => 10, :current_page => 10 }
|
2011-02-16 22:52:55 +09:00
|
|
|
# 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 23:20:06 +09:00
|
|
|
end
|