Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:rails/rails
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Apr 22, 2009
2 parents 70c544d + 380431e commit 6ee8329
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 deletions.
96 changes: 80 additions & 16 deletions actionpack/test/controller/rescue_test.rb
Expand Up @@ -400,22 +400,6 @@ def test_block_rescue_handler_with_argument_as_string
assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body
end end


def test_rescue_dispatcher_exceptions
env = @request.env
env["action_controller.rescue.request"] = @request
env["action_controller.rescue.response"] = @response

RescueController.call_with_exception(env, ActionController::RoutingError.new("Route not found"))
assert_equal "no way", @response.body
end

def test_rescue_dispatcher_exceptions_without_request_set
@request.env['REQUEST_URI'] = '/no_way'
response = RescueController.call_with_exception(@request.env, ActionController::RoutingError.new("Route not found"))
assert_kind_of ActionDispatch::Response, response
assert_equal "no way", response.body
end

protected protected
def with_all_requests_local(local = true) def with_all_requests_local(local = true)
old_local, ActionController::Base.consider_all_requests_local = old_local, ActionController::Base.consider_all_requests_local =
Expand Down Expand Up @@ -537,3 +521,83 @@ def test_exception_in_parent_controller
assert_response :created assert_response :created
end end
end end

class ApplicationController < ActionController::Base
rescue_from ActionController::RoutingError do
render :text => 'no way'
end
end

class RescueTest < ActionController::IntegrationTest
class TestController < ActionController::Base
class RecordInvalid < StandardError
def message
'invalid'
end
end
rescue_from RecordInvalid, :with => :show_errors

def foo
render :text => "foo"
end

def invalid
raise RecordInvalid
end

def b00m
raise 'b00m'
end

protected
def show_errors(exception)
render :text => exception.message
end
end

test 'normal request' do
with_test_routing do
get '/foo'
assert_equal 'foo', response.body
end
end

test 'rescue exceptions inside controller' do
with_test_routing do
get '/invalid'
assert_equal 'invalid', response.body
end
end

test 'rescue routing exceptions' do
assert_equal 1, ApplicationController.rescue_handlers.length

begin
with_test_routing do
get '/no_way'
assert_equal 'no way', response.body
end
ensure
ActionController::Base.rescue_handlers.clear
end
end

test 'unrescued exception' do
with_test_routing do
get '/b00m'
assert_match(/Action Controller: Exception caught/, response.body)
end
end

private
def with_test_routing
with_routing do |set|
set.draw do |map|
map.connect 'foo', :controller => "rescue_test/test", :action => 'foo'
map.connect 'invalid', :controller => "rescue_test/test", :action => 'invalid'
map.connect 'b00m', :controller => "rescue_test/test", :action => 'b00m'
end
yield
end
end
end

0 comments on commit 6ee8329

Please sign in to comment.