Fix bug in support for HTTPS with Rails LM/BH

This commit is contained in:
Bryan Helmkamp 2008-08-22 10:57:00 -04:00
parent 206e65b92f
commit dd8243108a
3 changed files with 15 additions and 9 deletions

View File

@ -44,11 +44,9 @@ module Webrat
end end
def absolute_href def absolute_href
if href =~ %r{^https?://www.example.com(/.*)} if href =~ /^\?/
$LAST_MATCH_INFO.captures.first
elsif href =~ /^\?/
"#{@session.current_url}#{href}" "#{@session.current_url}#{href}"
elsif href !~ /^\// elsif href !~ %r{^https?://www.example.com(/.*)} && (href !~ /^\//)
"#{@session.current_url}/#{href}" "#{@session.current_url}/#{href}"
else else
href href

View File

@ -16,22 +16,22 @@ module Webrat
def get(url, data) def get(url, data)
update_protocol(url) update_protocol(url)
@integration_session.get_via_redirect(url, data) @integration_session.get_via_redirect(remove_protocol(url), data)
end end
def post(url, data) def post(url, data)
update_protocol(url) update_protocol(url)
@integration_session.post_via_redirect(url, data) @integration_session.post_via_redirect(remove_protocol(url), data)
end end
def put(url, data) def put(url, data)
update_protocol(url) update_protocol(url)
@integration_session.put_via_redirect(url, data) @integration_session.put_via_redirect(remove_protocol(url), data)
end end
def delete(url, data) def delete(url, data)
update_protocol(url) update_protocol(url)
@integration_session.delete_via_redirect(url, data) @integration_session.delete_via_redirect(remove_protocol(url), data)
end end
def response_body def response_body
@ -44,6 +44,14 @@ module Webrat
protected protected
def remove_protocol(href)
if href =~ %r{^https?://www.example.com(/.*)}
$LAST_MATCH_INFO.captures.first
else
href
end
end
def update_protocol(href) def update_protocol(href)
if href =~ /^https:/ if href =~ /^https:/
@integration_session.https!(true) @integration_session.https!(true)

View File

@ -255,7 +255,7 @@ describe "clicks_link" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<a href="http://www.example.com/page/sub">Jump to sub page</a> <a href="http://www.example.com/page/sub">Jump to sub page</a>
EOS EOS
@session.should_receive(:get).with("/page/sub", {}) @session.should_receive(:get).with("http://www.example.com/page/sub", {})
@session.clicks_link "Jump to sub page" @session.clicks_link "Jump to sub page"
end end