2011-04-26 08:56:36 -04:00
|
|
|
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
|
|
|
|
|
|
|
describe 'Kaminari::ActionViewExtension' do
|
2011-05-05 10:41:17 -04:00
|
|
|
before do
|
|
|
|
50.times {|i| User.create! :name => "user#{i}"}
|
|
|
|
end
|
2011-04-26 08:56:36 -04:00
|
|
|
describe '#paginate' do
|
|
|
|
before do
|
2011-05-05 10:28:41 -04:00
|
|
|
@users = User.page(1)
|
2011-04-26 08:56:36 -04:00
|
|
|
end
|
2011-05-05 10:28:41 -04:00
|
|
|
subject { helper.paginate @users, :params => {:controller => 'users', :action => 'index'} }
|
|
|
|
it { should be_a String }
|
2011-04-26 08:56:36 -04:00
|
|
|
|
2011-05-05 10:28:41 -04:00
|
|
|
context 'escaping the pagination for javascript' do
|
|
|
|
it 'should escape for javascript' do
|
|
|
|
lambda { escape_javascript(helper.paginate @users, :params => {:controller => 'users', :action => 'index'}) }.should_not raise_error
|
2011-04-26 08:56:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-05-05 10:41:17 -04:00
|
|
|
|
|
|
|
describe '#link_to_next_page' do
|
|
|
|
context 'having more page' do
|
|
|
|
before do
|
|
|
|
@users = User.page(1)
|
|
|
|
end
|
2011-11-04 15:09:02 -04:00
|
|
|
context 'the default behaviour' do
|
|
|
|
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
|
|
|
it { should be_a String }
|
|
|
|
it { should match /rel="next"/ }
|
|
|
|
end
|
|
|
|
context 'overriding rel=' do
|
|
|
|
subject { helper.link_to_next_page @users, 'More', :rel => 'external', :params => {:controller => 'users', :action => 'index'} }
|
|
|
|
it { should match /rel="external"/ }
|
|
|
|
end
|
2011-05-05 10:41:17 -04:00
|
|
|
end
|
|
|
|
context 'the last page' do
|
|
|
|
before do
|
|
|
|
@users = User.page(2)
|
|
|
|
end
|
|
|
|
subject { helper.link_to_next_page @users, 'More', :params => {:controller => 'users', :action => 'index'} }
|
|
|
|
it { should_not be }
|
|
|
|
end
|
|
|
|
end
|
2011-04-26 08:56:36 -04:00
|
|
|
end
|