mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add ActionController::Metal#set_request!
Add `ActionController::Metal#set_request!` to set a request on controller instance without calling dispatch.
This commit is contained in:
parent
3f96b6973b
commit
ee6e13f3da
3 changed files with 17 additions and 4 deletions
|
@ -190,11 +190,15 @@ module ActionController
|
||||||
end
|
end
|
||||||
|
|
||||||
def dispatch(name, request) #:nodoc:
|
def dispatch(name, request) #:nodoc:
|
||||||
|
set_request!(request)
|
||||||
|
process(name)
|
||||||
|
to_a
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_request!(request) #:nodoc:
|
||||||
@_request = request
|
@_request = request
|
||||||
@_env = request.env
|
@_env = request.env
|
||||||
@_env['action_controller.instance'] = self
|
@_env['action_controller.instance'] = self
|
||||||
process(name)
|
|
||||||
to_a
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_a #:nodoc:
|
def to_a #:nodoc:
|
||||||
|
|
|
@ -8,9 +8,9 @@ module ActionController
|
||||||
delegate :headers, :status=, :location=, :content_type=,
|
delegate :headers, :status=, :location=, :content_type=,
|
||||||
:status, :location, :content_type, :response_code, :to => "@_response"
|
:status, :location, :content_type, :response_code, :to => "@_response"
|
||||||
|
|
||||||
def dispatch(action, request)
|
def set_request!(request) #:nodoc:
|
||||||
|
super
|
||||||
set_response!(request)
|
set_response!(request)
|
||||||
super(action, request)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def response_body=(body)
|
def response_body=(body)
|
||||||
|
|
|
@ -31,6 +31,15 @@ module BareMetalTest
|
||||||
controller.index
|
controller.index
|
||||||
assert_equal ["Hello world"], controller.response_body
|
assert_equal ["Hello world"], controller.response_body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "connect a request to controller instance without dispatch" do
|
||||||
|
env = {}
|
||||||
|
controller = BareController.new
|
||||||
|
controller.set_request! ActionDispatch::Request.new(env)
|
||||||
|
assert controller.request
|
||||||
|
assert controller.response
|
||||||
|
assert env['action_controller.instance']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class HeadController < ActionController::Metal
|
class HeadController < ActionController::Metal
|
||||||
|
|
Loading…
Reference in a new issue