Class: ActionController::TestRequest

Inherits:
ActionDispatch::TestRequest show all
Defined in:
actionpack/lib/action_controller/test_case.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Result

Constant Summary

Constants inherited from ActionDispatch::TestRequest

ActionDispatch::TestRequest::DEFAULT_ENV

Constants inherited from ActionDispatch::Request

ActionDispatch::Request::ENV_METHODS, ActionDispatch::Request::HTTP_METHODS, ActionDispatch::Request::HTTP_METHOD_LOOKUP, ActionDispatch::Request::LOCALHOST, ActionDispatch::Request::RFC2518, ActionDispatch::Request::RFC2616, ActionDispatch::Request::RFC3253, ActionDispatch::Request::RFC3648, ActionDispatch::Request::RFC3744, ActionDispatch::Request::RFC5323, ActionDispatch::Request::RFC5789

Constants included from ActionDispatch::Http::Cache::Request

ActionDispatch::Http::Cache::Request::HTTP_IF_MODIFIED_SINCE, ActionDispatch::Http::Cache::Request::HTTP_IF_NONE_MATCH

Instance Method Summary collapse

Methods inherited from ActionDispatch::TestRequest

#accept=, #action=, #cookies, #host=, #if_modified_since=, #if_none_match=, new, #path=, #port=, #rack_cookies, #remote_addr=, #request_method=, #request_uri=, #user_agent=

Methods inherited from ActionDispatch::Request

#GET, #POST, #authorization, #body, #body_stream, #content_length, #cookie_jar, #delete?, #flash, #form_data?, #fullpath, #get?, #head?, #headers, #ip, #key?, #local?, #media_type, #method, #method_symbol, #original_fullpath, #original_url, #post?, #put?, #raw_post, #remote_ip, #request_method, #request_method_symbol, #reset_session, #server_software, #session=, #session_options=, #uuid, #xml_http_request?

Methods included from ActionDispatch::Http::URL

#domain, extract_domain, extract_subdomain, extract_subdomains, #host, #host_with_port, #optional_port, #port, #port_string, #protocol, #raw_host_with_port, #server_port, #standard_port, #standard_port?, #subdomain, #subdomains, #url, url_for

Methods included from ActionDispatch::Http::FilterParameters

#filtered_env, #filtered_parameters, #filtered_path

Methods included from ActiveSupport::Concern

#append_features, extended, #included

Methods included from ActionDispatch::Http::Parameters

#parameters, #path_parameters, #path_parameters=, #reset_parameters, #symbolized_path_parameters

Methods included from ActionDispatch::Http::MimeNegotiation

#accepts, #content_mime_type, #content_type, #format, #format=, #formats, #negotiate_mime

Methods included from ActionDispatch::Http::Cache::Request

#etag_matches?, #fresh?, #if_modified_since, #if_none_match, #not_modified?

Constructor Details

#initialize(env = {}) ⇒ TestRequest

Returns a new instance of TestRequest.



131
132
133
134
135
136
# File 'actionpack/lib/action_controller/test_case.rb', line 131

def initialize(env = {})
  super

  self.session = TestSession.new
  self.session_options = TestSession::DEFAULT_OPTIONS.merge(:id => SecureRandom.hex(16))
end

Instance Method Details

#assign_parameters(routes, controller_path, action, parameters = {}) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'actionpack/lib/action_controller/test_case.rb', line 145

def assign_parameters(routes, controller_path, action, parameters = {})
  parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action)
  extra_keys = routes.extra_keys(parameters)
  non_path_parameters = get? ? query_parameters : request_parameters
  parameters.each do |key, value|
    if value.is_a?(Array) && (value.frozen? || value.any?(&:frozen?))
      value = value.map{ |v| v.duplicable? ? v.dup : v }
    elsif value.is_a?(Hash) && (value.frozen? || value.any?{ |k,v| v.frozen? })
      value = Hash[value.map{ |k,v| [k, v.duplicable? ? v.dup : v] }]
    elsif value.frozen? && value.duplicable?
      value = value.dup
    end

    if extra_keys.include?(key.to_sym)
      non_path_parameters[key] = value
    else
      if value.is_a?(Array)
        value = Result.new(value.map(&:to_param))
      else
        value = value.to_param
      end

      path_parameters[key.to_s] = value
    end
  end

  # Clear the combined params hash in case it was already referenced.
  @env.delete("action_dispatch.request.parameters")

  params = self.request_parameters.dup
  %w(controller action only_path).each do |k|
    params.delete(k)
    params.delete(k.to_sym)
  end
  data = params.to_query

  @env['CONTENT_LENGTH'] = data.length.to_s
  @env['rack.input'] = StringIO.new(data)
end

#recycle!Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'actionpack/lib/action_controller/test_case.rb', line 185

def recycle!
  @formats = nil
  @env.delete_if { |k, v| k =~ /^(action_dispatch|rack)\.request/ }
  @env.delete_if { |k, v| k =~ /^action_dispatch\.rescue/ }
  @symbolized_path_params = nil
  @method = @request_method = nil
  @fullpath = @ip = @remote_ip = @protocol = nil
  @env['action_dispatch.request.query_parameters'] = {}
  @set_cookies ||= {}
  @set_cookies.update(Hash[cookie_jar.instance_variable_get("@set_cookies").map{ |k,o| [k,o[:value]] }])
  deleted_cookies = cookie_jar.instance_variable_get("@delete_cookies")
  @set_cookies.reject!{ |k,v| deleted_cookies.include?(k) }
  cookie_jar.update(rack_cookies)
  cookie_jar.update(cookies)
  cookie_jar.update(@set_cookies)
  cookie_jar.recycle!
end