From 31e48939b13b5960eec0167ef0b71cd65ed36ed4 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 29 Jun 2005 02:41:00 +0000 Subject: r1475@iwill: jeremy | 2005-06-28 23:19:51 -0700 Ticket 1543 - Fix test_process r1476@iwill: jeremy | 2005-06-29 00:20:53 -0700 Correct expected, actual order for assert_equal. Use new render method in TestController. r1477@iwill: jeremy | 2005-06-29 00:23:45 -0700 Generate route and assign parameters without modifying the user's params. r1480@iwill: jeremy | 2005-06-29 00:28:52 -0700 Update changelog. r1481@iwill: jeremy | 2005-06-29 00:34:02 -0700 Directly generate paths with a leading slash instead of tacking it on later. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1557 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/assertions.rb | 1 + .../lib/action_controller/code_generation.rb | 2 +- actionpack/lib/action_controller/test_process.rb | 25 +++++++++++----------- actionpack/lib/action_controller/url_rewriter.rb | 1 - 4 files changed, 15 insertions(+), 14 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index b19ccc3b2b..c8245c7a3a 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -123,6 +123,7 @@ module Test #:nodoc: # Asserts that the provided options can be used to generate the provided path. def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) + expected_path = "/#{expected_path}" unless expected_path[0] == ?/ # Load routes.rb if it hasn't been loaded. ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? diff --git a/actionpack/lib/action_controller/code_generation.rb b/actionpack/lib/action_controller/code_generation.rb index de11d4a496..a480003720 100644 --- a/actionpack/lib/action_controller/code_generation.rb +++ b/actionpack/lib/action_controller/code_generation.rb @@ -217,7 +217,7 @@ module ActionController end def finish - line %("#{segments.join('/')}") + line %("/#{segments.join('/')}") end def check_conditions(conditions) diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 5248cd1e90..60c8e1a02c 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -66,10 +66,11 @@ module ActionController #:nodoc: def path @path || super() end - - def assign_parameters(parameters) - path, extras = ActionController::Routing::Routes.generate(parameters.symbolize_keys) - non_path_parameters = (get? ? query_parameters : request_parameters) + + def generate_route_and_assign_parameters(controller_path, action, parameters) + parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action) + path, extras = ActionController::Routing::Routes.generate(parameters) + non_path_parameters = get? ? query_parameters : request_parameters parameters.each do |key, value| (extras.key?(key.to_sym) ? non_path_parameters : path_parameters)[key] = value end @@ -248,9 +249,7 @@ module Test @request.action = action.to_s parameters ||= {} - parameters[:controller] = @controller.class.controller_path - parameters[:action] = action.to_s - @request.assign_parameters(parameters) + @request.generate_route_and_assign_parameters(@controller.class.controller_path, action.to_s, parameters) @request.session = ActionController::TestSession.new(session) unless session.nil? @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash @@ -307,11 +306,13 @@ module Test end def build_request_uri(action, parameters) - return if @request.env['REQUEST_URI'] - url = ActionController::UrlRewriter.new(@request, parameters) - @request.set_REQUEST_URI( - url.rewrite(@controller.send(:rewrite_options, - (parameters||{}).update(:only_path => true, :action=>action)))) + unless @request.env['REQUEST_URI'] + options = @controller.send(:rewrite_options, parameters) + options.update(:only_path => true, :action => action) + + url = ActionController::UrlRewriter.new(@request, parameters) + @request.set_REQUEST_URI(url.rewrite(options)) + end end def html_document diff --git a/actionpack/lib/action_controller/url_rewriter.rb b/actionpack/lib/action_controller/url_rewriter.rb index c9fd60880c..8ae6f3e57b 100644 --- a/actionpack/lib/action_controller/url_rewriter.rb +++ b/actionpack/lib/action_controller/url_rewriter.rb @@ -44,7 +44,6 @@ module ActionController extras.update(params_copy) end - path = "/#{path}" path << build_query_string(extras) unless extras.empty? path -- cgit v1.2.3