Skip to content

Commit

Permalink
Move TestRequest#query_parameters into AD TestRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed May 1, 2009
1 parent dc9f53b commit 1fcc7db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
14 changes: 2 additions & 12 deletions actionpack/lib/action_controller/testing/process.rb
Expand Up @@ -2,20 +2,13 @@

module ActionController #:nodoc:
class TestRequest < ActionDispatch::TestRequest #:nodoc:
attr_accessor :query_parameters

def initialize(env = {})
super

@query_parameters = {}
self.session = TestSession.new
self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => ActiveSupport::SecureRandom.hex(16))
end

def action=(action_name)
query_parameters.update({ "action" => action_name })
end

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)
Expand Down Expand Up @@ -47,9 +40,8 @@ def assign_parameters(controller_path, action, parameters)
end

def recycle!
@env.delete_if { |k, v| k =~ /^action_dispatch\.request/ }
self.query_parameters = {}
@headers = nil
@env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
@env['action_dispatch.request.query_parameters'] = {}
end
end

Expand Down Expand Up @@ -132,8 +124,6 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@html_document = nil
@request.request_method = http_method

@request.action = action.to_s

parameters ||= {}
@request.assign_parameters(@controller.class.controller_path, action.to_s, parameters)

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/http/request.rb
Expand Up @@ -351,7 +351,7 @@ def subdomains(tld_length = 1)

# Returns the query string, accounting for server idiosyncrasies.
def query_string
@env['QUERY_STRING'].present? ? @env['QUERY_STRING'] : (@env['REQUEST_URI'].split('?', 2)[1] || '')
@env['QUERY_STRING'].present? ? @env['QUERY_STRING'] : (@env['REQUEST_URI'].to_s.split('?', 2)[1] || '')
end

# Returns the request URI, accounting for server idiosyncrasies.
Expand Down
4 changes: 4 additions & 0 deletions actionpack/lib/action_dispatch/testing/test_request.rb
Expand Up @@ -39,6 +39,10 @@ def path=(path)
@env['PATH_INFO'] = path
end

def action=(action_name)
path_parameters["action"] = action_name.to_s
end

def if_modified_since=(last_modified)
@env['HTTP_IF_MODIFIED_SINCE'] = last_modified
end
Expand Down

0 comments on commit 1fcc7db

Please sign in to comment.