diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-23 06:18:38 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-23 06:18:38 -0800 |
commit | adb75680db377bf9026dd26f87200267eb786a2d (patch) | |
tree | 83eaaf97c6b729fcdb7a849c36a562c95fc23261 /actionpack | |
parent | ec65f144633aaf6791e97173448123790e69ff21 (diff) | |
parent | 5169543a6da2390191f780214e06c578eadb9442 (diff) | |
download | rails-adb75680db377bf9026dd26f87200267eb786a2d.tar.gz rails-adb75680db377bf9026dd26f87200267eb786a2d.tar.bz2 rails-adb75680db377bf9026dd26f87200267eb786a2d.zip |
Merge pull request #4613 from pda/cookie_jar_deleted_predicate
CookieJar#deleted? predicate method
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 9 | ||||
-rw-r--r-- | actionpack/test/dispatch/cookies_test.rb | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index 39ff58a447..25f1db8228 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -191,6 +191,15 @@ module ActionDispatch value end + # Whether the given cookie is to be deleted by this CookieJar. + # Like <tt>[]=</tt>, you can pass in an options hash to test if a + # deletion applies to a specific <tt>:path</tt>, <tt>:domain</tt> etc. + def deleted?(key, options = {}) + options.symbolize_keys! + handle_options(options) + @delete_cookies[key.to_s] == options + 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) } diff --git a/actionpack/test/dispatch/cookies_test.rb b/actionpack/test/dispatch/cookies_test.rb index 6ebd02e85c..3e48d97e67 100644 --- a/actionpack/test/dispatch/cookies_test.rb +++ b/actionpack/test/dispatch/cookies_test.rb @@ -245,6 +245,17 @@ class CookiesTest < ActionController::TestCase assert_cookie_header "user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT" end + def test_deleted_cookie_predicate + cookies.delete("user_name") + assert cookies.deleted?("user_name") + assert_equal false, cookies.deleted?("another") + end + + def test_deleted_cookie_predicate_with_mismatching_options + cookies.delete("user_name", :path => "/path") + assert_equal false, cookies.deleted?("user_name", :path => "/different") + end + def test_cookies_persist_throughout_request response = get :authenticate assert response.headers["Set-Cookie"] =~ /user_name=david/ |