aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_controller/dispatcher.rb27
-rw-r--r--actionpack/lib/action_controller/rack_process.rb3
-rw-r--r--actionpack/test/controller/dispatcher_test.rb4
-rw-r--r--actionpack/test/controller/rack_test.rb6
4 files changed, 16 insertions, 24 deletions
diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb
index 5a185eb59c..11c4f057d8 100644
--- a/actionpack/lib/action_controller/dispatcher.rb
+++ b/actionpack/lib/action_controller/dispatcher.rb
@@ -65,18 +65,23 @@ module ActionController
include ActiveSupport::Callbacks
define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
- # DEPRECATE: Remove arguments
+ # DEPRECATE: Remove arguments, since they are only used by CGI
def initialize(output = $stdout, request = nil, response = nil)
- @output, @request, @response = output, request, response
+ @output = output
@app = @@middleware.build(lambda { |env| self.dup._call(env) })
end
def dispatch
begin
run_callbacks :before_dispatch
- handle_request
+ controller = Routing::Routes.recognize(@request)
+ controller.process(@request, @response).to_a
rescue Exception => exception
- failsafe_rescue exception
+ if controller ||= (::ApplicationController rescue Base)
+ controller.process_with_exception(@request, @response, exception).to_a
+ else
+ raise exception
+ end
ensure
run_callbacks :after_dispatch, :enumerator => :reverse_each
end
@@ -123,19 +128,5 @@ module ActionController
return if @request.key?("rack.test")
ActiveRecord::Base.clear_active_connections!
end
-
- protected
- def handle_request
- @controller = Routing::Routes.recognize(@request)
- @controller.process(@request, @response).out
- end
-
- def failsafe_rescue(exception)
- if @controller ||= (::ApplicationController rescue Base)
- @controller.process_with_exception(@request, @response, exception).out
- else
- raise exception
- end
- end
end
end
diff --git a/actionpack/lib/action_controller/rack_process.rb b/actionpack/lib/action_controller/rack_process.rb
index 778c3c256f..8483f8e289 100644
--- a/actionpack/lib/action_controller/rack_process.rb
+++ b/actionpack/lib/action_controller/rack_process.rb
@@ -83,7 +83,7 @@ module ActionController #:nodoc:
@status || super
end
- def out(&block)
+ def to_a(&block)
@block = block
@status = headers.delete("Status")
if [204, 304].include?(status.to_i)
@@ -93,7 +93,6 @@ module ActionController #:nodoc:
[status, headers.to_hash, self]
end
end
- alias to_a out
def each(&callback)
if @body.respond_to?(:call)
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index a183b69c99..fd06b4ea99 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -96,7 +96,9 @@ class DispatcherTest < Test::Unit::TestCase
private
def dispatch(cache_classes = true)
- Dispatcher.any_instance.stubs(:handle_request).returns([200, {}, 'response'])
+ controller = mock()
+ controller.stubs(:process).returns([200, {}, 'response'])
+ ActionController::Routing::Routes.stubs(:recognize).returns(controller)
Dispatcher.define_dispatcher_callbacks(cache_classes)
@dispatcher.call({})
end
diff --git a/actionpack/test/controller/rack_test.rb b/actionpack/test/controller/rack_test.rb
index e2ec686c41..3a8a00b7d7 100644
--- a/actionpack/test/controller/rack_test.rb
+++ b/actionpack/test/controller/rack_test.rb
@@ -236,7 +236,7 @@ class RackResponseTest < BaseRackTest
@response.body = "Hello, World!"
@response.prepare!
- status, headers, body = @response.out
+ status, headers, body = @response.to_a
assert_equal "200 OK", status
assert_equal({
"Content-Type" => "text/html; charset=utf-8",
@@ -257,7 +257,7 @@ class RackResponseTest < BaseRackTest
end
@response.prepare!
- status, headers, body = @response.out
+ status, headers, body = @response.to_a
assert_equal "200 OK", status
assert_equal({"Content-Type" => "text/html; charset=utf-8", "Cache-Control" => "no-cache", "Set-Cookie" => []}, headers)
@@ -293,6 +293,6 @@ class RackResponseHeadersTest < BaseRackTest
private
def response_headers
@response.prepare!
- @response.out[1]
+ @response.to_a[1]
end
end