From 6bc24d40d56332593bc22612d4618a2f80b1d91b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Sch=C3=BCrrer?= Date: Sun, 21 Feb 2010 17:21:25 +0100 Subject: Use ActionDispatch::Routing everywhere --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 14557ca782..99924205dd 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -19,7 +19,7 @@ module ActionController def assign_parameters(controller_path, action, parameters = {}) parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action) - extra_keys = ActionController::Routing::Routes.extra_keys(parameters) + extra_keys = ActionDispatch::Routing::Routes.extra_keys(parameters) non_path_parameters = get? ? query_parameters : request_parameters parameters.each do |key, value| if value.is_a? Fixnum -- cgit v1.2.3 From 226dfc2681c98deaf14e4ae82e973d1d5caedd68 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Wed, 24 Feb 2010 16:01:03 -0800 Subject: WIP: Remove the global router --- actionpack/lib/action_controller/test_case.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 99924205dd..5f8bc6f325 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -17,9 +17,9 @@ module ActionController end end - def assign_parameters(controller_path, action, parameters = {}) + def assign_parameters(router, controller_path, action, parameters = {}) parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action) - extra_keys = ActionDispatch::Routing::Routes.extra_keys(parameters) + extra_keys = router.extra_keys(parameters) non_path_parameters = get? ? query_parameters : request_parameters parameters.each do |key, value| if value.is_a? Fixnum @@ -220,7 +220,7 @@ module ActionController def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') # Sanity check for required instance variables so we can give an # understandable error message. - %w(@controller @request @response).each do |iv_name| + %w(@router @controller @request @response).each do |iv_name| if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil? raise "#{iv_name} is nil: make sure you set it in your test's setup method." end @@ -236,7 +236,7 @@ module ActionController @request.env['REQUEST_METHOD'] = http_method parameters ||= {} - @request.assign_parameters(@controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) + @request.assign_parameters(@router, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) @request.session = ActionController::TestSession.new(session) unless session.nil? @request.session["flash"] = @request.flash.update(flash || {}) @@ -340,7 +340,7 @@ module ActionController options.update(:only_path => true, :action => action) url = ActionController::UrlRewriter.new(@request, parameters) - @request.request_uri = url.rewrite(options) + @request.request_uri = url.rewrite(@router, options) end end end -- cgit v1.2.3 From 36fd9efb5e4bfc9ac3acd4189d4dc457dea8102a Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Thu, 25 Feb 2010 15:05:10 -0800 Subject: Continued effort to deglobalize the router --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 5f8bc6f325..0fa2a8b90c 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -336,7 +336,7 @@ module ActionController private def build_request_uri(action, parameters) unless @request.env['REQUEST_URI'] - options = @controller.__send__(:rewrite_options, parameters) + options = @controller.__send__(:merge_options, parameters) options.update(:only_path => true, :action => action) url = ActionController::UrlRewriter.new(@request, parameters) -- cgit v1.2.3 From bae691f61ab8cf4a59adaee6406855e11d009c74 Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Fri, 26 Feb 2010 15:20:41 -0800 Subject: Change the API for setting global options for #url_for to self.url_options = { ... } This attr_accessor can be set in a before filter or in the action itself. Overwriting default_url_options still works but will output a deprecation notice. --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 0fa2a8b90c..64d9bdab2a 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -336,7 +336,7 @@ module ActionController private def build_request_uri(action, parameters) unless @request.env['REQUEST_URI'] - options = @controller.__send__(:merge_options, parameters) + options = @controller.__send__(:url_options).merge(parameters) options.update(:only_path => true, :action => action) url = ActionController::UrlRewriter.new(@request, parameters) -- cgit v1.2.3 From 5e0a05b8cb236d285ebb45de006dd3600c69357d Mon Sep 17 00:00:00 2001 From: Carlhuda Date: Tue, 2 Mar 2010 18:57:02 -0800 Subject: Tweak the semantic of various URL related methods of ActionDispatch::Request --- actionpack/lib/action_controller/test_case.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 64d9bdab2a..7e0a833dfa 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -322,6 +322,8 @@ module ActionController @controller ||= klass.new rescue nil end + @request.env.delete('PATH_INFO') + if @controller @controller.request = @request @controller.params = {} @@ -333,15 +335,19 @@ module ActionController @request.remote_addr = '208.77.188.166' # example.com end - private - def build_request_uri(action, parameters) - unless @request.env['REQUEST_URI'] - options = @controller.__send__(:url_options).merge(parameters) - options.update(:only_path => true, :action => action) + private + def build_request_uri(action, parameters) + unless @request.env["PATH_INFO"] + options = @controller.__send__(:url_options).merge(parameters) + options.update(:only_path => true, :action => action, :relative_url_root => nil) + rewriter = ActionController::UrlRewriter.new(@request, parameters) - url = ActionController::UrlRewriter.new(@request, parameters) - @request.request_uri = url.rewrite(@router, options) - end + url, query_string = rewriter.rewrite(@router, options).split("?", 2) + + @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root + @request.env["PATH_INFO"] = url + @request.env["QUERY_STRING"] = query_string || "" end + end end end -- cgit v1.2.3 From de79525d045b6ea2d83f325bdeeb9380510d045c Mon Sep 17 00:00:00 2001 From: wycats Date: Mon, 8 Mar 2010 21:08:31 -0800 Subject: Get rid of the instance-level URL rewriter --- actionpack/lib/action_controller/test_case.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 7e0a833dfa..c43e560ac1 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -339,9 +339,13 @@ module ActionController def build_request_uri(action, parameters) unless @request.env["PATH_INFO"] options = @controller.__send__(:url_options).merge(parameters) - options.update(:only_path => true, :action => action, :relative_url_root => nil) - rewriter = ActionController::UrlRewriter.new(@request, parameters) + options.update( + :only_path => true, + :action => action, + :relative_url_root => nil, + :_path_segments => @request.symbolized_path_parameters) + rewriter = ActionController::UrlRewriter url, query_string = rewriter.rewrite(@router, options).split("?", 2) @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root -- cgit v1.2.3 From 7db80f87e9c194713c2016820e39af6043ddf8d0 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 9 Mar 2010 20:50:35 -0600 Subject: Move AC::UrlRewriter onto route set --- actionpack/lib/action_controller/test_case.rb | 33 +++++++++++++-------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index c43e560ac1..072d289964 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -335,23 +335,22 @@ module ActionController @request.remote_addr = '208.77.188.166' # example.com end - private - def build_request_uri(action, parameters) - unless @request.env["PATH_INFO"] - options = @controller.__send__(:url_options).merge(parameters) - options.update( - :only_path => true, - :action => action, - :relative_url_root => nil, - :_path_segments => @request.symbolized_path_parameters) - - rewriter = ActionController::UrlRewriter - url, query_string = rewriter.rewrite(@router, options).split("?", 2) - - @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root - @request.env["PATH_INFO"] = url - @request.env["QUERY_STRING"] = query_string || "" + private + def build_request_uri(action, parameters) + unless @request.env["PATH_INFO"] + options = @controller.__send__(:url_options).merge(parameters) + options.update( + :only_path => true, + :action => action, + :relative_url_root => nil, + :_path_segments => @request.symbolized_path_parameters) + + url, query_string = @router.rewrite(options).split("?", 2) + + @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root + @request.env["PATH_INFO"] = url + @request.env["QUERY_STRING"] = query_string || "" + end end end - end end -- cgit v1.2.3 From 4d2470f7daad8cebd0a69f5ea0509a41af0596b8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 9 Mar 2010 21:00:24 -0600 Subject: RouteSet#rewrite => url_for --- actionpack/lib/action_controller/test_case.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_controller/test_case.rb') diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 072d289964..cdb5db32aa 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -345,7 +345,7 @@ module ActionController :relative_url_root => nil, :_path_segments => @request.symbolized_path_parameters) - url, query_string = @router.rewrite(options).split("?", 2) + url, query_string = @router.url_for(options).split("?", 2) @request.env["SCRIPT_NAME"] = @controller.config.relative_url_root @request.env["PATH_INFO"] = url -- cgit v1.2.3