Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug fixes and improvements for Mechanize::Download reported by Floria…

…n Gross. Issue #62
  • Loading branch information...
commit 7a5866fed3be762fa785fa4528f1290a3d36baae 1 parent 9eee397
@drbrain drbrain authored
View
4 lib/mechanize.rb
@@ -308,7 +308,7 @@ def get(uri, parameters = [], referer = nil, headers = {})
# FIXME: Huge hack so that using a URI as a referer works. I need to
# refactor everything to pass around URIs but still support
# Mechanize::Page#base
- unless referer.is_a?(Mechanize::File)
+ unless Mechanize::Parser === referer then
referer = referer.is_a?(String) ?
Page.new(URI.parse(referer), {'content-type' => 'text/html'}) :
Page.new(referer, {'content-type' => 'text/html'})
@@ -975,7 +975,7 @@ def parse uri, response, body
# Find our pluggable parser
parser_klass = @pluggable_parser.parser content_type
- unless Mechanize::Download === parser_klass then
+ unless parser_klass <= Mechanize::Download then
body = case body
when IO, Tempfile, StringIO then
body.read
View
2  lib/mechanize/download.rb
@@ -51,7 +51,7 @@ def save filename = nil
end
end
else
- FileUtils.cp @body_io.path, filename
+ FileUtils.mv @body_io.path, filename
end
end
View
14 test/test_mechanize.rb
@@ -452,6 +452,19 @@ def test_get_follow_meta_refresh_referer_not_sent
assert_nil requests.last['referer']
end
+ def test_get_referer_download
+ download = Mechanize::Download.new URI 'http://example/prev'
+
+ uri = URI 'http://example'
+
+ page = @mech.get uri, { :q => 'h' }, download, { 'X-H' => 'v' }
+
+ assert_equal URI('http://example/?q=h'), page.uri
+ assert_equal URI('http://example'), uri
+
+ assert_equal 'http://example/prev', requests.first['referer']
+ end
+
def test_get_robots
@mech.robots = true
@@ -791,6 +804,7 @@ def test_parse_download
download = @mech.parse @uri, response, StringIO.new('raw')
assert_kind_of Mechanize::Download, download
+ assert_kind_of StringIO, download.content
end
def test_parse_html
Please sign in to comment.
Something went wrong with that request. Please try again.