Skip to content

Commit

Permalink
Rescue from WillPaginate::InvalidPage error with 404 Not Found.
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Mar 3, 2008
1 parent 6ef9e37 commit 4598470
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/will_paginate.rb
Expand Up @@ -20,6 +20,10 @@ def enable_actionpack
return if ActionView::Base.instance_methods.include? 'will_paginate'
require 'will_paginate/view_helpers'
ActionView::Base.class_eval { include ViewHelpers }

if ActionController::Base.respond_to? :rescue_responses
ActionController::Base.rescue_responses['WillPaginate::InvalidPage'] = :not_found
end
end

# mixes in WillPaginate::Finder in ActiveRecord::Base and classes that deal
Expand Down
7 changes: 7 additions & 0 deletions test/pagination_test.rb
Expand Up @@ -212,6 +212,13 @@ def test_setting_id_for_container
assert_equal 'custom_id', div.first['id']
end
end

if ActionController::Base.respond_to? :rescue_responses
def test_rescue_response_hook_presence
assert_equal :not_found,
DevelopersController.rescue_responses['WillPaginate::InvalidPage']
end
end

protected

Expand Down

0 comments on commit 4598470

Please sign in to comment.