mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-27 14:57:46 +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
|
}.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty?(url)
|
# Tests if the jar is empty. If url is given, tests if there is no
|
||||||
cookies(url).empty?
|
# cookie for the URL.
|
||||||
|
def empty?(url = nil)
|
||||||
|
if url
|
||||||
|
each(url) { return false }
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
@jar.empty?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Iterate over cookies. If +uri+ is given, cookies not for the
|
# Iterate over cookies. If +uri+ is given, cookies not for the
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,15 @@ class TestHTTPCookieJar < Test::Unit::TestCase
|
||||||
}.merge(options)
|
}.merge(options)
|
||||||
end
|
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
|
def test_two_cookies_same_domain_and_name_different_paths
|
||||||
url = URI 'http://rubyforge.org/'
|
url = URI 'http://rubyforge.org/'
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue