From 7af1e87db47f21d05eef3a0cc9e2e58c36f0b704 Mon Sep 17 00:00:00 2001 From: Keiko Oda Date: Tue, 28 Aug 2012 00:54:45 -0700 Subject: [PATCH] Change default value of max_per_page from 0 to nil --- README.rdoc | 4 ++-- lib/kaminari/config.rb | 2 +- lib/kaminari/models/page_scope_methods.rb | 2 +- spec/config/config_spec.rb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rdoc b/README.rdoc index d77c8d009..5cd4cb1dc 100644 --- a/README.rdoc +++ b/README.rdoc @@ -73,7 +73,7 @@ Then bundle: You can configure the following default values by overriding these values using Kaminari.configure method. default_per_page # 25 by default - max_per_page # 0 by default + max_per_page # nil by default window # 4 by default outer_window # 0 by default left # 0 by default @@ -104,7 +104,7 @@ Run the following generator command, then edit the generated file. * +max_paginates_per+ 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 max_paginates_per 100 end diff --git a/lib/kaminari/config.rb b/lib/kaminari/config.rb index cc22d0198..0c5025c70 100644 --- a/lib/kaminari/config.rb +++ b/lib/kaminari/config.rb @@ -38,7 +38,7 @@ def param_name # this is ugly. why can't we pass the default value to config_accessor...? configure do |config| config.default_per_page = 25 - config.max_per_page = 0 + config.max_per_page = nil config.window = 4 config.outer_window = 0 config.left = 0 diff --git a/lib/kaminari/models/page_scope_methods.rb b/lib/kaminari/models/page_scope_methods.rb index 5fefce111..7008bc0c3 100644 --- a/lib/kaminari/models/page_scope_methods.rb +++ b/lib/kaminari/models/page_scope_methods.rb @@ -5,7 +5,7 @@ module PageScopeMethods def per(num) if (n = num.to_i) <= 0 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) else limit(n).offset(offset_value / limit_value * n) diff --git a/spec/config/config_spec.rb b/spec/config/config_spec.rb index 7512b5c1b..3215a4daa 100644 --- a/spec/config/config_spec.rb +++ b/spec/config/config_spec.rb @@ -19,7 +19,7 @@ describe 'max_per_page' do context 'by default' do - its(:max_per_page) { should == 0 } + its(:max_per_page) { should == nil } end context 'configure via config block' do before do @@ -27,7 +27,7 @@ end its(:max_per_page) { should == 100 } after do - Kaminari.configure {|c| c.max_per_page = 0} + Kaminari.configure {|c| c.max_per_page = nil} end end end