diff options
author | eileencodes <eileencodes@gmail.com> | 2015-08-15 13:23:41 -0400 |
---|---|---|
committer | eileencodes <eileencodes@gmail.com> | 2015-08-15 13:23:41 -0400 |
commit | f6232a518bb7377948f339d2b0b25dc607e1e42a (patch) | |
tree | 9abb862a9964a5daae743525cc83f6ee8563b08e | |
parent | 8f1bbf6e82a8e4c33d5558277a14b8d979eccf02 (diff) | |
download | rails-f6232a518bb7377948f339d2b0b25dc607e1e42a.tar.gz rails-f6232a518bb7377948f339d2b0b25dc607e1e42a.tar.bz2 rails-f6232a518bb7377948f339d2b0b25dc607e1e42a.zip |
Refactor how assign_parameters sets generated_path & query_string_keys
This is part of a larger refactoring on controller tests. We needed to
move these methods here so that we could get rid of the `|| key ==
:action || key == :controller` in `assign_parameters`. We know this is
ugly and intend to fix it but for now `generate_extras` needs to be used
in the two methods to access the path and the query_string_keys.
We're adding `:controller` and `:action` to the `query_string_keys`
because we always need a controller and action. If someone passed
`action` or `controller` in in there test they are unambigious - we
know they have to go into the query params.
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 39069f7378..94f18cefc3 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -42,14 +42,12 @@ module ActionController @env["action_dispatch.request.request_parameters"] = params end - def assign_parameters(routes, controller_path, action, parameters = {}) - parameters = parameters.symbolize_keys - generated_path, query_string_keys = routes.generate_extras(parameters.merge(:controller => controller_path, :action => action)) + def assign_parameters(routes, controller_path, action, parameters, generated_path, query_string_keys) non_path_parameters = {} path_parameters = {} parameters.each do |key, value| - if query_string_keys.include?(key) || key == :action || key == :controller + if query_string_keys.include?(key) non_path_parameters[key] = value else if value.is_a?(Array) @@ -483,11 +481,13 @@ module ActionController @request.env['REQUEST_METHOD'] = http_method - controller_class_name = @controller.class.anonymous? ? - "anonymous" : - @controller.class.controller_path + parameters = parameters.symbolize_keys - @request.assign_parameters(@routes, controller_class_name, action.to_s, parameters) + generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s)) + generated_path = generated_path(generated_extras) + query_string_keys = query_parameter_names(generated_extras) + + @request.assign_parameters(@routes, controller_class_name, action.to_s, parameters, generated_path, query_string_keys) @request.session.update(session) if session @request.flash.update(flash || {}) @@ -530,6 +530,18 @@ module ActionController @response end + def controller_class_name + @controller.class.anonymous? ? "anonymous" : @controller.class.controller_path + end + + def generated_path(generated_extras) + generated_extras[0] + end + + def query_parameter_names(generated_extras) + generated_extras[1] + [:controller, :action] + end + def setup_controller_request_and_response @controller = nil unless defined? @controller |