mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
ActionDispatch::Cookies::CookieJar#deleted? predicate method.
Necessary in controller tests to determine if the CookieJar will delete the given cookie.
This commit is contained in:
parent
ec65f14463
commit
5169543a6d
2 changed files with 20 additions and 0 deletions
|
@ -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) }
|
||||
|
|
|
@ -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/
|
||||
|
|
Loading…
Reference in a new issue