lib/action_controller/test_process.rb in actionpack-2.3.2 vs lib/action_controller/test_process.rb in actionpack-2.3.3
- old
+ new
@@ -1,5 +1,6 @@
+require 'rack/session/abstract/id'
module ActionController #:nodoc:
class TestRequest < Request #:nodoc:
attr_accessor :cookies, :session_options
attr_accessor :query_parameters, :path, :session
attr_accessor :host
@@ -11,10 +12,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
@@ -108,20 +111,25 @@
raw_post # populate env['RAW_POST_DATA']
@parameters = nil # reset TestRequest#parameters to use the new path_parameters
end
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
def user_agent=(user_agent)
@env['HTTP_USER_AGENT'] = user_agent
end
private
+ def generate_sid(sidbits)
+ "%0#{sidbits / 4}x" % rand(2**sidbits - 1)
+ end
+
def initialize_containers
@cookies = {}
end
def initialize_default_values
@@ -248,10 +256,10 @@
#
# assert_equal 'AuthorOfNewPage', r.cookies['author']
def cookies
cookies = {}
Array(headers['Set-Cookie']).each do |cookie|
- key, value = cookie.split(";").first.split("=")
+ key, value = cookie.split(";").first.split("=").map {|val| Rack::Utils.unescape(val)}
cookies[key] = value
end
cookies
end