Permalink
Browse files

Modified the cookie_jar save_as method to optionally allow the saving…

… of session cookie hash.
  • Loading branch information...
Jim Jones authored and knu committed May 16, 2012
1 parent 6ebe772 commit aae4c9e5477c14ef421b67983cf3fdad9758fea0
Showing with 29 additions and 2 deletions.
  1. +2 −2 lib/mechanize/cookie_jar.rb
  2. +27 −0 test/test_mechanize_cookie_jar.rb
@@ -75,9 +75,9 @@ def each
# Available formats:
# :yaml <- YAML structure
# :cookiestxt <- Mozilla's cookies.txt format
def save_as(file, format = :yaml)
def save_as(file, format = :yaml, cookie_cleanup = true)
jar = dup
jar.cleanup true
jar.cleanup cookie_cleanup
open(file, 'w') { |f|
case format
@@ -289,6 +289,33 @@ def test_save_cookies_yaml
assert_equal(3, @jar.cookies(url).length)
end
def test_save_session_cookies_yaml
url = URI 'http://rubyforge.org/'
# Add one cookie with an expiration date in the future
cookie = Mechanize::Cookie.new(cookie_values)
s_cookie = Mechanize::Cookie.new(cookie_values(:name => 'Bar',
:expires => nil,
:session => true))
@jar.add(url, cookie)
@jar.add(url, s_cookie)
@jar.add(url, Mechanize::Cookie.new(cookie_values(:name => 'Baz')))
assert_equal(3, @jar.cookies(url).length)
in_tmpdir do
@jar.save_as("cookies.yml", :yaml, false)
jar = Mechanize::CookieJar.new
jar.load("cookies.yml")
assert_equal(3, jar.cookies(url).length)
end
assert_equal(3, @jar.cookies(url).length)
end
def test_save_cookies_cookiestxt
url = URI 'http://rubyforge.org/'

0 comments on commit aae4c9e

Please sign in to comment.