Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the PageNumber class to raise no ArgumentError #275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/will_paginate/page_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
9 changes: 5 additions & 4 deletions spec/finders/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down