aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/middleware/cookies.rb
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2011-03-30 00:46:27 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2011-06-04 07:09:11 +0100
commitd4658d86fe7b037f2105e798a5717e22ca55d61d (patch)
tree51902717a0b8881534a9e978db7502eff9a1e26c /actionpack/lib/action_dispatch/middleware/cookies.rb
parent64325a82427120cf7659c80e1b67ca1ffb01ebc4 (diff)
downloadrails-d4658d86fe7b037f2105e798a5717e22ca55d61d.tar.gz
rails-d4658d86fe7b037f2105e798a5717e22ca55d61d.tar.bz2
rails-d4658d86fe7b037f2105e798a5717e22ca55d61d.zip
Refactor ActionController::TestCase cookies
Assigning cookies for test cases should now use cookies[], e.g: cookies[:email] = 'user@example.com' get :index assert_equal 'user@example.com', cookies[:email] To clear the cookies, use clear, e.g: cookies.clear get :index assert_nil cookies[:email] We now no longer write out HTTP_COOKIE and the cookie jar is persistent between requests so if you need to manipulate the environment for your test you need to do it before the cookie jar is created.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/cookies.rb')
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 47c4bad489..c4a83fc8cb 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -185,6 +185,11 @@ module ActionDispatch
value
end
+ # Removes all cookies on the client machine by calling <tt>delete</tt> for each cookie
+ def clear(options = {})
+ @cookies.each_key{ |k| delete(k, options) }
+ end
+
# Returns a jar that'll automatically set the assigned cookies to have an expiration date 20 years from now. Example:
#
# cookies.permanent[:prefers_open_id] = true
@@ -222,6 +227,11 @@ module ActionDispatch
@delete_cookies.each { |k, v| ::Rack::Utils.delete_cookie_header!(headers, k, v) }
end
+ def reset! #:nodoc:
+ @set_cookies.clear
+ @delete_cookies.clear
+ end
+
private
def write_cookie?(cookie)