allocate request objects with the env hash, set routes on the request

This commit is to abstract the code away from the env hash.  It no
longer needs to have the routes key hard coded.
This commit is contained in:
Aaron Patterson 2015-09-15 07:38:39 -07:00
parent a50376424f
commit ec6638a237
2 changed files with 6 additions and 9 deletions

@ -140,13 +140,6 @@ def self.make_response!(request)
end
end
def self.build_with_env(env = {}) #:nodoc:
new.tap { |c|
c.set_request! ActionDispatch::Request.new(env)
c.set_response! make_response!(c.request)
}
end
# Delegates to the class' <tt>controller_name</tt>
def controller_name
self.class.controller_name

@ -65,14 +65,18 @@ def initialize(controller, env, defaults)
@controller = controller
@defaults = defaults
@env = normalize_keys defaults.merge(env)
@env['action_dispatch.routes'] = controller._routes
end
# Render templates with any options from ActionController::Base#render_to_string.
def render(*args)
raise 'missing controller' unless controller
instance = controller.build_with_env(@env)
request = ActionDispatch::Request.new @env
request.routes = controller._routes
instance = controller.new
instance.set_request! request
instance.set_response! controller.make_response!(request)
instance.render_to_string(*args)
end