diff options
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/test_process.rb | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 8dd2e443ae..8e6c81b375 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -72,10 +72,16 @@ module ActionController #:nodoc: extra_keys = ActionController::Routing::Routes.extra_keys(parameters) non_path_parameters = get? ? query_parameters : request_parameters parameters.each do |key, value| + if value.is_a? Fixnum + value = value.to_s + elsif value.is_a? Array + value = ActionController::Routing::PathComponent::Result.new(value) + end + if extra_keys.include?(key.to_sym) non_path_parameters[key] = value else - path_parameters[key] = value.is_a?(Fixnum) ? value.to_s : value + path_parameters[key.to_s] = value end end end @@ -352,6 +358,36 @@ module Test return @controller.send(selector, *args) if ActionController::Routing::NamedRoutes::Helpers.include?(selector) return super end + + # A helper to make it easier to test different route configurations. + # This method temporarily replaces ActionController::Routing::Routes + # with a new RouteSet instance. + # + # The new instance is yielded to the passed block. Typically the block + # will create some routes using map.draw { map.connect ... }: + # + # with_routing do |set| + # set.draw { set.connect ':controller/:id/:action' } + # assert_equal( + # ['/content/10/show', {}], + # set.generate(:controller => 'content', :id => 10, :action => 'show') + # ) + # end + # + def with_routing + real_routes = ActionController::Routing::Routes + ActionController::Routing.send :remove_const, :Routes + + temporary_routes = ActionController::Routing::RouteSet.new + ActionController::Routing.send :const_set, :Routes, temporary_routes + + yield temporary_routes + ensure + if ActionController::Routing.const_defined? :Routes + ActionController::Routing.send(:remove_const, :Routes) + end + ActionController::Routing.const_set(:Routes, real_routes) if real_routes + end end end end |