Class: ActionController::TestRequest

Inherits:
Request show all
Defined in:
lib/action_controller/test_process.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Request

Request::HTTP_METHODS, Request::HTTP_METHOD_LOOKUP, Request::TRUSTED_PROXIES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Request

#GET, #POST, #accepts, #body, #cache_format, #content_length, #content_type, #delete?, #domain, #etag_matches?, #form_data?, #format, #format=, #fresh?, #get?, #head?, #headers, #host_with_port, #if_modified_since, #if_none_match, #key?, #media_type, #method, #not_modified?, #parameters, #path_parameters, #path_parameters=, #port, #port_string, #post?, #protocol, #put?, #query_string, #raw_host_with_port, #remote_ip, #request_method, #server_port, #server_software, #ssl?, #standard_port, #subdomains, #symbolized_path_parameters, #template_format, #url, #xml_http_request?

Constructor Details

#initialize(env = {}) ⇒ TestRequest

Returns a new instance of TestRequest.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/action_controller/test_process.rb', line 12

def initialize(env = {})
  super(Rack::MockRequest.env_for("/").merge(env))

  @query_parameters   = {}
  @session            = TestSession.new
  default_rack_options = Rack::Session::Abstract::ID::DEFAULT_OPTIONS
  @session_options    ||= {:id => generate_sid(default_rack_options[:sidbits])}.merge(default_rack_options)

  initialize_default_values
  initialize_containers
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



4
5
6
# File 'lib/action_controller/test_process.rb', line 4

def cookies
  @cookies
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/action_controller/test_process.rb', line 6

def host
  @host
end

#path(*args) ⇒ Object

Returns the value of attribute path.



5
6
7
# File 'lib/action_controller/test_process.rb', line 5

def path
  @path
end

#query_parametersObject

Returns the value of attribute query_parameters.



5
6
7
# File 'lib/action_controller/test_process.rb', line 5

def query_parameters
  @query_parameters
end

#sessionObject

Returns the value of attribute session.



5
6
7
# File 'lib/action_controller/test_process.rb', line 5

def session
  @session
end

#session_optionsObject

Returns the value of attribute session_options.



4
5
6
# File 'lib/action_controller/test_process.rb', line 4

def session_options
  @session_options
end

Class Method Details

.new(env = {}) ⇒ Object



8
9
10
# File 'lib/action_controller/test_process.rb', line 8

def self.new(env = {})
  super
end

Instance Method Details

#accept=(mime_types) ⇒ Object



69
70
71
72
# File 'lib/action_controller/test_process.rb', line 69

def accept=(mime_types)
  @env["HTTP_ACCEPT"] = Array(mime_types).collect { |mime_types| mime_types.to_s }.join(",")
  @accepts = nil
end

#action=(action_name) ⇒ Object



47
48
49
50
# File 'lib/action_controller/test_process.rb', line 47

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

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/action_controller/test_process.rb', line 94

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)
  non_path_parameters = get? ? query_parameters : request_parameters
  parameters.each do |key, value|
    if value.is_a? Fixnum
      value = value.to_s
    elsif value.is_a? Array
      value = ActionController::Routing::PathSegment::Result.new(value)
    end

    if extra_keys.include?(key.to_sym)
      non_path_parameters[key] = value
    else
      path_parameters[key.to_s] = value
    end
  end
  raw_post # populate env['RAW_POST_DATA']
  @parameters = nil # reset TestRequest#parameters to use the new path_parameters
end

#body_streamObject

Wraps raw_post in a StringIO.



29
30
31
# File 'lib/action_controller/test_process.rb', line 29

def body_stream #:nodoc:
  StringIO.new(raw_post)
end

#if_modified_since=(last_modified) ⇒ Object



74
75
76
# File 'lib/action_controller/test_process.rb', line 74

def if_modified_since=(last_modified)
  @env["HTTP_IF_MODIFIED_SINCE"] = last_modified
end

#if_none_match=(etag) ⇒ Object



78
79
80
# File 'lib/action_controller/test_process.rb', line 78

def if_none_match=(etag)
  @env["HTTP_IF_NONE_MATCH"] = etag
end

#port=(number) ⇒ Object



43
44
45
# File 'lib/action_controller/test_process.rb', line 43

def port=(number)
  @env["SERVER_PORT"] = number.to_i
end

#raw_postObject

Either the RAW_POST_DATA environment variable or the URL-encoded request parameters.



35
36
37
38
39
40
41
# File 'lib/action_controller/test_process.rb', line 35

def raw_post
  @env['RAW_POST_DATA'] ||= begin
    data = url_encoded_request_parameters
    data.force_encoding(Encoding::BINARY) if data.respond_to?(:force_encoding)
    data
  end
end

#recycle!Object



115
116
117
118
119
120
# File 'lib/action_controller/test_process.rb', line 115

def recycle!
  @env["action_controller.request.request_parameters"] = {}
  self.query_parameters   = {}
  self.path_parameters    = {}
  @headers, @request_method, @accepts, @content_type = nil, nil, nil, nil
end

#remote_addr=(addr) ⇒ Object



82
83
84
# File 'lib/action_controller/test_process.rb', line 82

def remote_addr=(addr)
  @env['REMOTE_ADDR'] = addr
end

#request_method=(method) ⇒ Object



65
66
67
# File 'lib/action_controller/test_process.rb', line 65

def request_method=(method)
  @request_method = method
end

#request_uri(*args) ⇒ Object



86
87
88
# File 'lib/action_controller/test_process.rb', line 86

def request_uri(*args)
  @request_uri || super()
end

#request_uri=(uri) ⇒ Object



60
61
62
63
# File 'lib/action_controller/test_process.rb', line 60

def request_uri=(uri)
  @request_uri = uri
  @path = uri.split("?").first
end

#reset_sessionObject



24
25
26
# File 'lib/action_controller/test_process.rb', line 24

def reset_session
  @session.reset
end

#set_REQUEST_URI(value) ⇒ Object

Used to check AbstractRequest’s request_uri functionality. Disables the use of @path and @request_uri so superclass can handle those.



54
55
56
57
58
# File 'lib/action_controller/test_process.rb', line 54

def set_REQUEST_URI(value)
  @env["REQUEST_URI"] = value
  @request_uri = nil
  @path = nil
end

#user_agent=(user_agent) ⇒ Object



122
123
124
# File 'lib/action_controller/test_process.rb', line 122

def user_agent=(user_agent)
  @env['HTTP_USER_AGENT'] = user_agent
end