aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/abstract/renderer.rb14
-rw-r--r--actionpack/lib/action_controller/base/render.rb4
-rw-r--r--actionpack/test/controller/rescue_test.rb96
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb (renamed from actionpack/test/controller/session/cookie_store_test.rb)0
-rw-r--r--actionpack/test/dispatch/session/mem_cache_store_test.rb (renamed from actionpack/test/controller/session/mem_cache_store_test.rb)0
-rw-r--r--actionpack/test/dispatch/session/test_session_test.rb (renamed from actionpack/test/controller/session/test_session_test.rb)0
6 files changed, 96 insertions, 18 deletions
diff --git a/actionpack/lib/action_controller/abstract/renderer.rb b/actionpack/lib/action_controller/abstract/renderer.rb
index 2a68f048bd..a86eef889e 100644
--- a/actionpack/lib/action_controller/abstract/renderer.rb
+++ b/actionpack/lib/action_controller/abstract/renderer.rb
@@ -40,7 +40,7 @@ module AbstractController
#
# :api: plugin
def render_to_string(options = {})
- Rack::Utils.body_to_s(render_to_body(options)).to_ary.join
+ AbstractController::Renderer.body_to_s(render_to_body(options))
end
def _render_template(template, options)
@@ -49,6 +49,18 @@ module AbstractController
def view_paths() _view_paths end
+ # Return a string representation of a Rack-compatible response body.
+ def self.body_to_s(body)
+ if body.respond_to?(:to_str)
+ body
+ else
+ strings = []
+ body.each { |part| strings << part.to_s }
+ body.close if body.respond_to?(:close)
+ strings.join
+ end
+ end
+
module ClassMethods
def append_view_path(path)
diff --git a/actionpack/lib/action_controller/base/render.rb b/actionpack/lib/action_controller/base/render.rb
index 604dd31930..606df58518 100644
--- a/actionpack/lib/action_controller/base/render.rb
+++ b/actionpack/lib/action_controller/base/render.rb
@@ -1,3 +1,5 @@
+require 'action_controller/abstract/renderer'
+
module ActionController
DEFAULT_RENDER_STATUS_CODE = "200 OK"
@@ -318,7 +320,7 @@ module ActionController
end
def render_to_string(options = {})
- Rack::Utils.body_to_s(render_to_body(options)).to_ary.join
+ AbstractController::Renderer.body_to_s(render_to_body(options))
end
# Clears the rendered results, allowing for another render to be performed.
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 741b01caa8..894420a910 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -400,22 +400,6 @@ class RescueControllerTest < ActionController::TestCase
assert_equal "RescueController::ResourceUnavailableToRescueAsString", @response.body
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
def with_all_requests_local(local = true)
old_local, ActionController::Base.consider_all_requests_local =
@@ -537,3 +521,83 @@ class ControllerInheritanceRescueControllerTest < ActionController::TestCase
assert_response :created
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
diff --git a/actionpack/test/controller/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index b9bf8cf411..b9bf8cf411 100644
--- a/actionpack/test/controller/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
diff --git a/actionpack/test/controller/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb
index 7561c93e4a..7561c93e4a 100644
--- a/actionpack/test/controller/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
diff --git a/actionpack/test/controller/session/test_session_test.rb b/actionpack/test/dispatch/session/test_session_test.rb
index de6539e1cc..de6539e1cc 100644
--- a/actionpack/test/controller/session/test_session_test.rb
+++ b/actionpack/test/dispatch/session/test_session_test.rb