1
0
Fork 0
mirror of https://github.com/kaminari/kaminari.git synced 2022-11-09 13:44:37 -05:00
kaminari--kaminari/spec/models/scopes_spec.rb
2011-02-06 20:11:45 +09:00

82 lines
1.8 KiB
Ruby

require File.expand_path('../spec_helper', File.dirname(__FILE__))
describe Kaminari::ActiveRecord do
before :all do
User.delete_all
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
end
describe '#page' do
shared_examples_for 'the first page' do
it { should have(25).users }
its('first.name') { should == 'user001' }
end
shared_examples_for 'blank page' do
it { should have(0).users }
end
context 'page 1' do
subject { User.page 1 }
it_should_behave_like 'the first page'
end
context 'page 2' do
subject { User.page 2 }
it { should have(25).users }
its('first.name') { should == 'user026' }
end
context 'page without an argument' do
subject { User.page }
it_should_behave_like 'the first page'
end
context 'page < 1' do
subject { User.page 0 }
it_should_behave_like 'the first page'
end
context 'page > max page' do
subject { User.page 5 }
it_should_behave_like 'blank page'
end
end
describe '#per' do
context 'page 1 per 5' do
subject { User.page(1).per(5) }
it { should have(5).users }
its('first.name') { should == 'user001' }
end
end
describe '#num_pages' do
context 'per 25 (default)' do
subject { User.page }
its(:num_pages) { should == 4 }
end
context 'per 7' do
subject { User.page(2).per(7) }
its(:num_pages) { should == 15 }
end
context 'per 65536' do
subject { User.page(50).per(65536) }
its(:num_pages) { should == 1 }
end
end
describe '#current_page' do
context 'page 1' do
subject { User.page }
its(:current_page) { should == 1 }
end
context 'page 2' do
subject { User.page(2).per 3 }
its(:current_page) { should == 2 }
end
end
end