Skip to content

Commit

Permalink
Fix a syntax error that made agent.redirect_ok = :permanent not working.
Browse files Browse the repository at this point in the history
Finally add a test for redirect_ok.
  • Loading branch information
knu committed Sep 5, 2011
1 parent eb9e8dc commit fb7a668
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mechanize/http/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ def response_redirect response, method, page, redirects
when false, nil
return page
when :permanent
return page if response_class != Net::HTTPMovedPermanently
return page unless Net::HTTPMovedPermanently === response
end

log.info("follow redirect to: #{response['Location']}") if log
Expand Down
25 changes: 25 additions & 0 deletions test/test_redirect_ok.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "helper"

class TestRedirectOk < MiniTest::Unit::TestCase
def setup
@agent = Mechanize.new
end

def test_false
@agent.redirect_ok = false
page = @agent.get('http://localhost/redirect_ok')
assert_equal(URI('http://localhost/redirect_ok'), @agent.page.uri)
end

def test_true
@agent.redirect_ok = true
page = @agent.get('http://localhost/redirect_ok')
assert_equal(URI('http://localhost/redirect_ok?q=5'), @agent.page.uri)
end

def test_permanent
@agent.redirect_ok = :permanent
page = @agent.get('http://localhost/redirect_ok')
assert_equal(URI('http://localhost/redirect_ok?q=3'), @agent.page.uri)
end
end

0 comments on commit fb7a668

Please sign in to comment.