forked from kaminari/kaminari
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require File.expand_path('../spec_helper', File.dirname(__FILE__)) | ||
require 'mongoid' | ||
require File.expand_path('../../lib/kaminari/mongoid_extension', File.dirname(__FILE__)) | ||
|
||
describe Kaminari::MongoidExtension do | ||
before :all do | ||
class Developer | ||
include ::Mongoid::Document | ||
end | ||
end | ||
before do | ||
stub(subject).count { 300 } # in order to avoid DB access... | ||
end | ||
|
||
describe '#page' do | ||
context 'page 1' do | ||
subject { Developer.page 1 } | ||
it { should be_a Mongoid::Criteria } | ||
its(:current_page) { should == 1 } | ||
its(:limit_value) { should == 25 } | ||
its(:num_pages) { should == 12 } | ||
it { should skip(0) } | ||
end | ||
|
||
context 'page 2' do | ||
subject { Developer.page 2 } | ||
it { should be_a Mongoid::Criteria } | ||
its(:current_page) { should == 2 } | ||
its(:limit_value) { should == 25 } | ||
its(:num_pages) { should == 12 } | ||
it { should skip 25 } | ||
end | ||
|
||
context 'page "foobar"' do | ||
subject { Developer.page 'foobar' } | ||
it { should be_a Mongoid::Criteria } | ||
its(:current_page) { should == 1 } | ||
its(:limit_value) { should == 25 } | ||
its(:num_pages) { should == 12 } | ||
it { should skip 0 } | ||
end | ||
end | ||
|
||
describe '#per' do | ||
subject { Developer.page(2).per(10) } | ||
it { should be_a Mongoid::Criteria } | ||
its(:current_page) { should == 2 } | ||
its(:limit_value) { should == 10 } | ||
its(:num_pages) { should == 30 } | ||
it { should skip 10 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters