Merge branch 'relative-links' of git://github.com/pd/webrat into pd/relative-links

This commit is contained in:
Bryan Helmkamp 2008-04-13 17:36:38 -04:00
commit e5630a5f43
3 changed files with 33 additions and 1 deletions

View File

@ -1,5 +1,9 @@
== Trunk
* Enhancements
* Support relative links, including href="?foo=bar" (Patch from Kyle Hargraves)
* Bug fixes
* Fix regression of not sending default values in password fields

View File

@ -10,7 +10,7 @@ module Webrat
method ||= http_method
return if href =~ /^#/ && method == :get
Page.new(@page.session, href, method, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token})
Page.new(@page.session, absolute_href, method, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token})
end
def matches_text?(link_text)
@ -27,6 +27,16 @@ module Webrat
@element["href"]
end
def absolute_href
if href =~ /^\?/
"#{@page.url}#{href}"
elsif href !~ /^\//
"#{@page.url}/#{href}"
else
href
end
end
def authenticity_token
return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") &&
onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/

View File

@ -190,4 +190,22 @@ class ClicksLinkTest < Test::Unit::TestCase
@session.expects(:send).with('get_via_redirect', '#section-1', {}).never
@session.clicks_link "Jump to Section 1"
end
def test_should_follow_relative_links
@session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS)
<a href="sub">Jump to sub page</a>
EOS
@session.expects(:get_via_redirect).with("/page/sub", {})
@session.clicks_link "Jump to sub page"
end
def test_should_follow_query_parameters
@session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS)
<a href="?foo=bar">Jump to foo bar</a>
EOS
@session.expects(:get_via_redirect).with("/page?foo=bar", {})
@session.clicks_link "Jump to foo bar"
end
end