Merge branch 'relative-links' of git://github.com/pd/webrat into pd/relative-links
This commit is contained in:
commit
e5630a5f43
|
@ -1,5 +1,9 @@
|
||||||
== Trunk
|
== Trunk
|
||||||
|
|
||||||
|
* Enhancements
|
||||||
|
|
||||||
|
* Support relative links, including href="?foo=bar" (Patch from Kyle Hargraves)
|
||||||
|
|
||||||
* Bug fixes
|
* Bug fixes
|
||||||
|
|
||||||
* Fix regression of not sending default values in password fields
|
* Fix regression of not sending default values in password fields
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Webrat
|
||||||
method ||= http_method
|
method ||= http_method
|
||||||
return if href =~ /^#/ && method == :get
|
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
|
end
|
||||||
|
|
||||||
def matches_text?(link_text)
|
def matches_text?(link_text)
|
||||||
|
@ -27,6 +27,16 @@ module Webrat
|
||||||
@element["href"]
|
@element["href"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def absolute_href
|
||||||
|
if href =~ /^\?/
|
||||||
|
"#{@page.url}#{href}"
|
||||||
|
elsif href !~ /^\//
|
||||||
|
"#{@page.url}/#{href}"
|
||||||
|
else
|
||||||
|
href
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def authenticity_token
|
def authenticity_token
|
||||||
return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") &&
|
return unless onclick && onclick.include?("s.setAttribute('name', 'authenticity_token');") &&
|
||||||
onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/
|
onclick =~ /s\.setAttribute\('value', '([a-f0-9]{40})'\);/
|
||||||
|
|
|
@ -190,4 +190,22 @@ class ClicksLinkTest < Test::Unit::TestCase
|
||||||
@session.expects(:send).with('get_via_redirect', '#section-1', {}).never
|
@session.expects(:send).with('get_via_redirect', '#section-1', {}).never
|
||||||
@session.clicks_link "Jump to Section 1"
|
@session.clicks_link "Jump to Section 1"
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue