Skip to content

Commit

Permalink
Change default value of max_per_page from 0 to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
keiko713 committed Aug 28, 2012
1 parent c778676 commit 7af1e87
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.rdoc
Expand Up @@ -73,7 +73,7 @@ Then bundle:

You can configure the following default values by overriding these values using <tt>Kaminari.configure</tt> 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/kaminari/config.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/kaminari/models/page_scope_methods.rb
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions spec/config/config_spec.rb
Expand Up @@ -19,15 +19,15 @@

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
Kaminari.configure {|c| c.max_per_page = 100}
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
Expand Down

0 comments on commit 7af1e87

Please sign in to comment.