mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +00:00
Make HTTP::Cookie#expired? optionally take a time.
This commit is contained in:
parent
d8be652a92
commit
1fcf008cf0
2 changed files with 4 additions and 2 deletions
|
|
@ -344,9 +344,9 @@ class HTTP::Cookie
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def expired?
|
def expired?(time = Time.now)
|
||||||
return false unless @expires
|
return false unless @expires
|
||||||
Time.now > @expires
|
time > @expires
|
||||||
end
|
end
|
||||||
|
|
||||||
def expire
|
def expire
|
||||||
|
|
|
||||||
|
|
@ -451,6 +451,8 @@ class TestHTTPCookie < Test::Unit::TestCase
|
||||||
cookie = HTTP::Cookie.new(cookie_values)
|
cookie = HTTP::Cookie.new(cookie_values)
|
||||||
|
|
||||||
assert_equal false, cookie.expired?
|
assert_equal false, cookie.expired?
|
||||||
|
assert_equal true, cookie.expired?(cookie.expires + 1)
|
||||||
|
assert_equal false, cookie.expired?(cookie.expires - 1)
|
||||||
cookie.expire
|
cookie.expire
|
||||||
assert_equal true, cookie.expired?
|
assert_equal true, cookie.expired?
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue