Change default value of max_per_page from 0 to nil

This commit is contained in:
Keiko Oda 2012-08-28 00:54:45 -07:00
parent c77867681e
commit 7af1e87db4
4 changed files with 6 additions and 6 deletions

View File

@ -73,7 +73,7 @@ Then bundle:
You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method. You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> method.
default_per_page # 25 by default default_per_page # 25 by default
max_per_page # 0 by default max_per_page # nil by default
window # 4 by default window # 4 by default
outer_window # 0 by default outer_window # 0 by default
left # 0 by default left # 0 by default
@ -104,7 +104,7 @@ Run the following generator command, then edit the generated file.
* +max_paginates_per+ * +max_paginates_per+
You can specify max +per_page+ value per each model using the following declarative DSL. You can specify max +per_page+ value per each model using the following declarative DSL.
If the variable that specified via +per+ scope is more than this variable, max +paginates_per+ is used instead of it. Default value is 0, which means you are not specifying max +per_page+ value. If the variable that specified via +per+ scope is more than this variable, max +paginates_per+ is used instead of it. Default value is nil, which means you are not imposing any max +per_page+ value.
class User < ActiveRecord::Base class User < ActiveRecord::Base
max_paginates_per 100 max_paginates_per 100
end end

View File

@ -38,7 +38,7 @@ module Kaminari
# this is ugly. why can't we pass the default value to config_accessor...? # this is ugly. why can't we pass the default value to config_accessor...?
configure do |config| configure do |config|
config.default_per_page = 25 config.default_per_page = 25
config.max_per_page = 0 config.max_per_page = nil
config.window = 4 config.window = 4
config.outer_window = 0 config.outer_window = 0
config.left = 0 config.left = 0

View File

@ -5,7 +5,7 @@ module Kaminari
def per(num) def per(num)
if (n = num.to_i) <= 0 if (n = num.to_i) <= 0
self self
elsif max_per_page != 0 && max_per_page < n elsif max_per_page && max_per_page < n
limit(max_per_page).offset(offset_value / limit_value * max_per_page) limit(max_per_page).offset(offset_value / limit_value * max_per_page)
else else
limit(n).offset(offset_value / limit_value * n) limit(n).offset(offset_value / limit_value * n)

View File

@ -19,7 +19,7 @@ describe Kaminari::Configuration do
describe 'max_per_page' do describe 'max_per_page' do
context 'by default' do context 'by default' do
its(:max_per_page) { should == 0 } its(:max_per_page) { should == nil }
end end
context 'configure via config block' do context 'configure via config block' do
before do before do
@ -27,7 +27,7 @@ describe Kaminari::Configuration do
end end
its(:max_per_page) { should == 100 } its(:max_per_page) { should == 100 }
after do after do
Kaminari.configure {|c| c.max_per_page = 0} Kaminari.configure {|c| c.max_per_page = nil}
end end
end end
end end