1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make Railties tests green again.

This commit is contained in:
José Valim 2010-02-17 00:14:49 +01:00
parent b1edd09662
commit e8ef12e39d
2 changed files with 13 additions and 8 deletions

View file

@ -11,15 +11,21 @@ module ActionDispatch
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
class Dispatcher
def initialize(options = {})
defaults = options[:defaults]
def initialize(options={})
@defaults = options[:defaults]
@glob_param = options.delete(:glob)
end
def call(env)
params = env[PARAMETERS_KEY]
prepare_params!(params)
controller(params).action(params[:action]).call(env)
# Just raise undefined constant errors if a controller was specified as default.
unless controller = controller(params, @defaults.key?(:controller))
return [404, {'X-Cascade' => 'pass'}, []]
end
controller.action(params[:action]).call(env)
end
def prepare_params!(params)
@ -34,13 +40,13 @@ module ActionDispatch
end
end
def controller(params, swallow=false)
def controller(params, raise_error=true)
if params && params.has_key?(:controller)
controller = "#{params[:controller].camelize}Controller"
ActiveSupport::Inflector.constantize(controller)
end
rescue NameError => e
raise ActionController::RoutingError, e.message, e.backtrace unless swallow
raise ActionController::RoutingError, e.message, e.backtrace if raise_error
end
private
@ -53,7 +59,6 @@ module ActionDispatch
end
end
# A NamedRouteCollection instance is a collection of named routes, and also
# maintains an anonymous module that can be used to install helpers for the
# named routes.
@ -427,7 +432,7 @@ module ActionDispatch
req = Rack::Request.new(env)
@set.recognize(req) do |route, params|
dispatcher = route.app
if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, true)
if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
dispatcher.prepare_params!(params)
return params
end

View file

@ -823,7 +823,7 @@ class RenderTest < ActionController::TestCase
def test_render_text_with_resource
get :render_text_with_resource
assert_equal 'name: David', @response.body
assert_equal 'name: "David"', @response.body
end
# :ported: