From 949f345a5097ecee52796a5b8b0e8162ab9b9865 Mon Sep 17 00:00:00 2001 From: Bryan Ricker Date: Wed, 31 Oct 2012 18:02:52 -0700 Subject: [PATCH] Allow nil for #per, to return records without limit --- lib/kaminari/models/page_scope_methods.rb | 4 +++- spec/models/active_record/scopes_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/kaminari/models/page_scope_methods.rb b/lib/kaminari/models/page_scope_methods.rb index 7008bc0..23e6aa6 100644 --- a/lib/kaminari/models/page_scope_methods.rb +++ b/lib/kaminari/models/page_scope_methods.rb @@ -3,7 +3,9 @@ module Kaminari # Specify the per_page value for the preceding page scope # Model.page(3).per(10) def per(num) - if (n = num.to_i) <= 0 + if num.nil? + limit(nil) + elsif (n = num.to_i) <= 0 self elsif max_per_page && max_per_page < n limit(max_per_page).offset(offset_value / limit_value * max_per_page) diff --git a/spec/models/active_record/scopes_spec.rb b/spec/models/active_record/scopes_spec.rb index 2911e2f..a3d5624 100644 --- a/spec/models/active_record/scopes_spec.rb +++ b/spec/models/active_record/scopes_spec.rb @@ -58,6 +58,11 @@ if defined? ActiveRecord it { should have(5).users } its('first.name') { should == 'user001' } end + + context "page 1 per nil" do + subject { model_class.page(1).per(nil) } + it { should have(model_class.count).users } + end end describe '#padding' do