mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
default PER_PAGE to 25
This commit is contained in:
parent
294a0405d6
commit
8036619ae6
2 changed files with 20 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
module Kaminari
|
module Kaminari
|
||||||
module ActiveRecord
|
module ActiveRecord
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
PER_PAGE = 10
|
PER_PAGE = 25
|
||||||
|
|
||||||
included do
|
included do
|
||||||
def self.inherited(kls)
|
def self.inherited(kls)
|
||||||
|
@ -17,7 +17,7 @@ module Kaminari
|
||||||
scope :page, lambda {|num|
|
scope :page, lambda {|num|
|
||||||
offset(PER_PAGE * ([num.to_i, 1].max - 1)).limit(PER_PAGE)
|
offset(PER_PAGE * ([num.to_i, 1].max - 1)).limit(PER_PAGE)
|
||||||
} do
|
} do
|
||||||
# page(3).per(20)
|
# page(3).per(10)
|
||||||
def per(num)
|
def per(num)
|
||||||
offset(offset_value / limit_value * num).limit(num)
|
offset(offset_value / limit_value * num).limit(num)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,13 +3,13 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
||||||
describe Kaminari::ActiveRecord do
|
describe Kaminari::ActiveRecord do
|
||||||
before :all do
|
before :all do
|
||||||
User.delete_all
|
User.delete_all
|
||||||
1.upto(20) {|i| User.create! :name => "user#{'%02d' % i}" }
|
1.upto(100) {|i| User.create! :name => "user#{'%03d' % i}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#page' do
|
describe '#page' do
|
||||||
shared_examples_for 'the first page' do
|
shared_examples_for 'the first page' do
|
||||||
it { should have(10).users }
|
it { should have(25).users }
|
||||||
its('first.name') { should == 'user01' }
|
its('first.name') { should == 'user001' }
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples_for 'blank page' do
|
shared_examples_for 'blank page' do
|
||||||
|
@ -23,8 +23,8 @@ describe Kaminari::ActiveRecord do
|
||||||
|
|
||||||
context 'page 2' do
|
context 'page 2' do
|
||||||
subject { User.page 2 }
|
subject { User.page 2 }
|
||||||
it { should have(10).users }
|
it { should have(25).users }
|
||||||
its('first.name') { should == 'user11' }
|
its('first.name') { should == 'user026' }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'page without an argument' do
|
context 'page without an argument' do
|
||||||
|
@ -38,7 +38,7 @@ describe Kaminari::ActiveRecord do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'page > max page' do
|
context 'page > max page' do
|
||||||
subject { User.page 3 }
|
subject { User.page 5 }
|
||||||
it_should_behave_like 'blank page'
|
it_should_behave_like 'blank page'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,36 +47,36 @@ describe Kaminari::ActiveRecord do
|
||||||
context 'page 1 per 5' do
|
context 'page 1 per 5' do
|
||||||
subject { User.page(1).per(5) }
|
subject { User.page(1).per(5) }
|
||||||
it { should have(5).users }
|
it { should have(5).users }
|
||||||
its('first.name') { should == 'user01' }
|
its('first.name') { should == 'user001' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#num_pages' do
|
describe '#num_pages' do
|
||||||
context 'per 10' do
|
context 'per 25 (default)' do
|
||||||
subject { User.page.num_pages }
|
subject { User.page }
|
||||||
it { should == 2 }
|
its(:num_pages) { should == 4 }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'per 7' do
|
context 'per 7' do
|
||||||
subject { User.page(2).per(7).num_pages }
|
subject { User.page(2).per(7) }
|
||||||
it { should == 3 }
|
its(:num_pages) { should == 15 }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'per 65536' do
|
context 'per 65536' do
|
||||||
subject { User.page(50).per(65536).num_pages }
|
subject { User.page(50).per(65536) }
|
||||||
it { should == 1 }
|
its(:num_pages) { should == 1 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#current_page' do
|
describe '#current_page' do
|
||||||
context 'page 1' do
|
context 'page 1' do
|
||||||
subject { User.page.current_page }
|
subject { User.page }
|
||||||
it { should == 1 }
|
its(:current_page) { should == 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'page 2' do
|
context 'page 2' do
|
||||||
subject { User.page(2).per(3).current_page }
|
subject { User.page(2).per 3 }
|
||||||
it { should == 2 }
|
its(:current_page) { should == 2 }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue