Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

CookieJar#deleted? predicate method #4613

merged 1 commit into from Jan 23, 2012


None yet
2 participants

pda commented Jan 23, 2012

ActionDispatch::Cookies::CookieJar needs a way to query for deleted cookies.

Here's an example use case from a controller test:

get :destroy
assert cookies.deleted? "auth_token"


@pda pda ActionDispatch::Cookies::CookieJar#deleted? predicate method.
Necessary in controller tests to determine if the CookieJar will delete
the given cookie.

@josevalim josevalim and 1 other commented on an outdated diff Jan 23, 2012

@@ -180,8 +180,7 @@ def recycle!
@env['action_dispatch.request.query_parameters'] = {}
@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) }
+ @set_cookies.reject!{ |k,v| cookie_jar.deleted?(k) }

josevalim Jan 23, 2012


These are not exactly equivalent. The first one would delete any cookie regardless of the path or the domain, while the second one won't.


pda Jan 23, 2012


Good point. I'll eliminate that commit, leaving just the addition of the #deleted? method.


pda commented Jan 23, 2012

Removed change to actionpack/lib/action_controller/test_case.rb as @josevalim rightly points out using #deleted? wasn't exactly equivalent to the method using instance_variable_get.


josevalim commented Jan 23, 2012

Another option is to have deleted?(key) check if they key was deleted regardless of the options or add another method for that. Better than the instance variable get check.


pda commented Jan 23, 2012

I was initially reluctant to have #deleted? disregard the cookie scope options, but I can't really see a problem with def deleted?(key) not taking an options hash.

@josevalim josevalim added a commit that referenced this pull request Jan 23, 2012

@josevalim josevalim Merge pull request #4613 from pda/cookie_jar_deleted_predicate
CookieJar#deleted? predicate method

@josevalim josevalim merged commit adb7568 into rails:master Jan 23, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment