diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-10 02:34:42 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-10-10 02:34:42 +0000 |
commit | 4db4661a67529d6238ed255cd51d42d6f68306e1 (patch) | |
tree | f6cad1f3cdb80663140ab22bcae7db734e9f1e4a /actionpack/test/controller | |
parent | 4aabe46341dd6db9bf9bbbbc27c32f467a7c55b7 (diff) | |
download | rails-4db4661a67529d6238ed255cd51d42d6f68306e1.tar.gz rails-4db4661a67529d6238ed255cd51d42d6f68306e1.tar.bz2 rails-4db4661a67529d6238ed255cd51d42d6f68306e1.zip |
rescue_from accepts :with => lambda { |exception| ... } or a normal block. Closes #9827.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7822 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/rescue_test.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb index f0d0526a36..cf4dcac029 100644 --- a/actionpack/test/controller/rescue_test.rb +++ b/actionpack/test/controller/rescue_test.rb @@ -9,9 +9,32 @@ class RescueController < ActionController::Base class RecordInvalid < StandardError end + class NotAllowed < StandardError + end + + class InvalidRequest < StandardError + end + + class BadGateway < StandardError + end + + class ResourceUnavailable < StandardError + end + rescue_from NotAuthorized, :with => :deny_access rescue_from RecordInvalid, :with => :show_errors + rescue_from NotAllowed, :with => proc { head :forbidden } + rescue_from InvalidRequest, :with => proc { |exception| render :text => exception.message } + + rescue_from BadGateway do + head :status => 502 + end + + rescue_from ResourceUnavailable do |exception| + render :text => exception.message + end + def raises render :text => 'already rendered' raise "don't panic!" @@ -29,10 +52,26 @@ class RescueController < ActionController::Base raise NotAuthorized end + def not_allowed + raise NotAllowed + end + + def invalid_request + raise InvalidRequest + end + def record_invalid raise RecordInvalid end + def bad_gateway + raise BadGateway + end + + def resource_unavailable + raise ResourceUnavailable + end + def missing_template end @@ -245,6 +284,26 @@ class RescueTest < Test::Unit::TestCase get :record_invalid end + def test_proc_rescue_handler + get :not_allowed + assert_response :forbidden + end + + def test_proc_rescue_handle_with_argument + get :invalid_request + assert_equal "RescueController::InvalidRequest", @response.body + end + + def test_block_rescue_handler + get :bad_gateway + assert_response 502 + end + + def test_block_rescue_handler_with_argument + get :resource_unavailable + assert_equal "RescueController::ResourceUnavailable", @response.body + end + protected def with_all_requests_local(local = true) old_local, ActionController::Base.consider_all_requests_local = |