aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2011-06-05 12:34:27 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2011-06-05 12:34:27 +0100
commite864ff7259ed9e4c61a146c635aedc3c60779931 (patch)
tree91d3d05ece03c08ee4c6b7944b505e9e6b06f0ed /actionpack/lib/action_controller
parent0a9270417c8eb03891ec161622bcf81e5cb8af02 (diff)
downloadrails-e864ff7259ed9e4c61a146c635aedc3c60779931.tar.gz
rails-e864ff7259ed9e4c61a146c635aedc3c60779931.tar.bz2
rails-e864ff7259ed9e4c61a146c635aedc3c60779931.zip
Add backward compatibility for testing cookies
This commit restores the ability to assign cookies for testing via @request.env['HTTP_COOKIE'] and @request.cookies, e.g: @request.env['HTTP_COOKIE'] = 'user_name=david' get :index assert_equal 'david', cookies[:user_name] and @request.cookies[:user_name] = 'david' get :index assert_equal 'david', cookies[:user_name] Assigning via cookies[] is the preferred method and will take precedence over the other two methods. This is so that cookies set in controller actions have precedence and are carried over between calls to get, post, etc.
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r--actionpack/lib/action_controller/test_case.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb
index 6d85846eb3..d14bb666cc 100644
--- a/actionpack/lib/action_controller/test_case.rb
+++ b/actionpack/lib/action_controller/test_case.rb
@@ -182,7 +182,14 @@ module ActionController
@method = @request_method = nil
@fullpath = @ip = @remote_ip = nil
@env['action_dispatch.request.query_parameters'] = {}
- cookie_jar.reset!
+ @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
end