2011-12-10 11:15:18 -05:00
|
|
|
require 'spec_helper'
|
2011-04-26 22:26:14 -04:00
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
if defined? MongoMapper
|
|
|
|
describe Kaminari::MongoMapperExtension do
|
|
|
|
before(:each) do
|
2012-05-20 10:30:19 -04:00
|
|
|
User.destroy_all
|
|
|
|
41.times { User.create!({:salary => 1}) }
|
2011-04-26 22:26:14 -04:00
|
|
|
end
|
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
describe '#page' do
|
|
|
|
context 'page 1' do
|
2012-05-20 10:30:19 -04:00
|
|
|
subject { User.page(1) }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should be_a Plucky::Query }
|
|
|
|
its(:current_page) { should == 1 }
|
|
|
|
its(:limit_value) { should == 25 }
|
2012-05-25 02:31:53 -04:00
|
|
|
its(:total_pages) { should == 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should skip(0) }
|
|
|
|
end
|
2011-05-03 11:19:51 -04:00
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
context 'page 2' do
|
2012-05-20 10:30:19 -04:00
|
|
|
subject { User.page 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should be_a Plucky::Query }
|
|
|
|
its(:current_page) { should == 2 }
|
|
|
|
its(:limit_value) { should == 25 }
|
2012-05-25 02:31:53 -04:00
|
|
|
its(:total_pages) { should == 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should skip 25 }
|
|
|
|
end
|
2011-05-03 11:19:51 -04:00
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
context 'page "foobar"' do
|
2012-05-20 10:30:19 -04:00
|
|
|
subject { User.page 'foobar' }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should be_a Plucky::Query }
|
|
|
|
its(:current_page) { should == 1 }
|
|
|
|
its(:limit_value) { should == 25 }
|
2012-05-25 02:31:53 -04:00
|
|
|
its(:total_pages) { should == 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should skip 0 }
|
2011-04-26 22:26:14 -04:00
|
|
|
end
|
2011-05-03 11:19:51 -04:00
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
context 'with criteria before' do
|
|
|
|
it "should have the proper criteria source" do
|
2012-05-20 10:30:19 -04:00
|
|
|
User.where(:salary => 1).page(2).criteria.source.should == {:salary => 1}
|
2012-05-17 08:08:02 -04:00
|
|
|
end
|
2011-05-03 11:19:51 -04:00
|
|
|
|
2012-05-20 10:30:19 -04:00
|
|
|
subject { User.where(:salary => 1).page 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
its(:current_page) { should == 2 }
|
|
|
|
its(:limit_value) { should == 25 }
|
2012-05-25 02:31:53 -04:00
|
|
|
its(:total_pages) { should == 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should skip 25 }
|
2011-04-26 22:26:14 -04:00
|
|
|
end
|
2011-05-03 11:19:51 -04:00
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
context 'with criteria after' do
|
|
|
|
it "should have the proper criteria source" do
|
2012-05-20 10:30:19 -04:00
|
|
|
User.where(:salary => 1).page(2).criteria.source.should == {:salary => 1}
|
2012-05-17 08:08:02 -04:00
|
|
|
end
|
|
|
|
|
2012-05-20 10:30:19 -04:00
|
|
|
subject { User.page(2).where(:salary => 1) }
|
2012-05-17 08:08:02 -04:00
|
|
|
its(:current_page) { should == 2 }
|
|
|
|
its(:limit_value) { should == 25 }
|
2012-05-25 02:31:53 -04:00
|
|
|
its(:total_pages) { should == 2 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should skip 25 }
|
|
|
|
end
|
2011-04-26 22:26:14 -04:00
|
|
|
end
|
|
|
|
|
2012-05-17 08:08:02 -04:00
|
|
|
describe '#per' do
|
2012-05-20 10:30:19 -04:00
|
|
|
subject { User.page(2).per(10) }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should be_a Plucky::Query }
|
|
|
|
its(:current_page) { should == 2 }
|
|
|
|
its(:limit_value) { should == 10 }
|
2012-05-25 02:31:53 -04:00
|
|
|
its(:total_pages) { should == 5 }
|
2012-05-17 08:08:02 -04:00
|
|
|
it { should skip 10 }
|
|
|
|
end
|
2011-04-26 22:26:14 -04:00
|
|
|
end
|
2011-05-03 11:19:51 -04:00
|
|
|
end
|