Skip to content

Instantly share code, notes, and snippets.

@cyberfox
Created February 2, 2010 21:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberfox/293038 to your computer and use it in GitHub Desktop.
Save cyberfox/293038 to your computer and use it in GitHub Desktop.
# Include this in your RAILS_ROOT/test/test_helper.rb
class ActionController::TestCase
def better_cookies
cookies = {}
Array(@response.headers['Set-Cookie']).each do |cookie|
key = nil
details = cookie.split(';').inject({}) do |fields, cookie_field|
pair = cookie_field.split('=').map {|val| Rack::Utils.unescape(val.strip)}
key = pair.first unless key
fields.merge(pair.first => pair.last)
end
details['expires'] = Time.parse(details['expires']) if details['expires']
cookies[key] = details
end
cookies
end
end
# Use it with something like…
# assert better_cookies['token']['expires'].present? &&
# better_cookies['token']['expires'] > 13.days.from_now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment