Skip to content
Browse files

get page number one for invalid page_numbers

  • Loading branch information...
1 parent 71f793e commit 4c00624686a4013cb9c12c89cea462cb1c63b592 Hannes Maack committed Nov 5, 2012
Showing with 6 additions and 4 deletions.
  1. +1 −0 lib/will_paginate/page_number.rb
  2. +5 −4 spec/finders/active_record_spec.rb
View
1 lib/will_paginate/page_number.rb
@@ -13,6 +13,7 @@ class PageNumber < DelegateClass(Integer)
extend Forwardable
def initialize(value, name)
+ value = 1 if value.is_a?(String) and value.to_i == 0
value = Integer(value)
if 'offset' == name ? (value < 0 or value > BIGINT) : value < 1
raise RangeError, "invalid #{name}: #{value.inspect}"
View
9 spec/finders/active_record_spec.rb
@@ -76,10 +76,11 @@
rel.offset.should == 5
end
- it "raises on invalid page number" do
- lambda {
- Developer.page('foo')
- }.should raise_error(ArgumentError)
+ it "get page one for invalid strings" do
+ rel = Developer.page('foo')
+ rel.current_page.should == 1
+ rel.per_page.should == 10
+ rel.offset.should == 0
end
it "supports first limit() then page()" do

0 comments on commit 4c00624

Please sign in to comment.
Something went wrong with that request. Please try again.