mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-03-25 08:55:53 +00:00
Implement HTTP::CookieJar#empty? without an argument.
This commit is contained in:
parent
3b38cd2ffd
commit
fd7450717a
2 changed files with 18 additions and 2 deletions
|
|
@ -46,8 +46,15 @@ class HTTP::CookieJar
|
|||
}.sort
|
||||
end
|
||||
|
||||
def empty?(url)
|
||||
cookies(url).empty?
|
||||
# Tests if the jar is empty. If url is given, tests if there is no
|
||||
# cookie for the URL.
|
||||
def empty?(url = nil)
|
||||
if url
|
||||
each(url) { return false }
|
||||
return true
|
||||
else
|
||||
@jar.empty?
|
||||
end
|
||||
end
|
||||
|
||||
# Iterate over cookies. If +uri+ is given, cookies not for the
|
||||
|
|
|
|||
|
|
@ -25,6 +25,15 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
|||
}.merge(options)
|
||||
end
|
||||
|
||||
def test_empty?
|
||||
assert_equal true, @jar.empty?
|
||||
cookie = HTTP::Cookie.new(cookie_values)
|
||||
@jar.add(cookie)
|
||||
assert_equal false, @jar.empty?
|
||||
assert_equal false, @jar.empty?('http://rubyforge.org/')
|
||||
assert_equal true, @jar.empty?('http://example.local/')
|
||||
end
|
||||
|
||||
def test_two_cookies_same_domain_and_name_different_paths
|
||||
url = URI 'http://rubyforge.org/'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue