Skip to content

Commit

Permalink
Fix bug in support for HTTPS with Rails LM/BH
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Aug 22, 2008
1 parent 206e65b commit dd82431
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib/webrat/core/link.rb
Expand Up @@ -44,11 +44,9 @@ def href
end

def absolute_href
if href =~ %r{^https?://www.example.com(/.*)}
$LAST_MATCH_INFO.captures.first
elsif href =~ /^\?/
if href =~ /^\?/
"#{@session.current_url}#{href}"
elsif href !~ /^\//
elsif href !~ %r{^https?://www.example.com(/.*)} && (href !~ /^\//)
"#{@session.current_url}/#{href}"
else
href
Expand Down
16 changes: 12 additions & 4 deletions lib/webrat/rails/rails_session.rb
Expand Up @@ -16,22 +16,22 @@ def saved_page_dir

def get(url, data)
update_protocol(url)
@integration_session.get_via_redirect(url, data)
@integration_session.get_via_redirect(remove_protocol(url), data)
end

def post(url, data)
update_protocol(url)
@integration_session.post_via_redirect(url, data)
@integration_session.post_via_redirect(remove_protocol(url), data)
end

def put(url, data)
update_protocol(url)
@integration_session.put_via_redirect(url, data)
@integration_session.put_via_redirect(remove_protocol(url), data)
end

def delete(url, data)
update_protocol(url)
@integration_session.delete_via_redirect(url, data)
@integration_session.delete_via_redirect(remove_protocol(url), data)
end

def response_body
Expand All @@ -44,6 +44,14 @@ def response_code

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)
if href =~ /^https:/
@integration_session.https!(true)
Expand Down
2 changes: 1 addition & 1 deletion spec/api/clicks_link_spec.rb
Expand Up @@ -255,7 +255,7 @@
@session.response_body = <<-EOS
<a href="http://www.example.com/page/sub">Jump to sub page</a>
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"
end

Expand Down

0 comments on commit dd82431

Please sign in to comment.