Merge branch 'master' of git@github.com:brynary/webrat

This commit is contained in:
Bryan Helmkamp 2008-05-04 14:07:04 -04:00
commit c7765a1e6c
3 changed files with 31 additions and 2 deletions

View File

@ -6,6 +6,7 @@
* Support button elements (Patch from Nick Sieger)
* Support matching select options by regexp (Patch from Kyle Hargraves)
* Support relative links, including href="?foo=bar" (Patch from Kyle Hargraves)
* Support links to fully qualified URLs starting with http:// or https:// (Luke Melia)
* Bug fixes
@ -27,7 +28,7 @@
* Added reloads method to reload the page (Patch from Kamal Fariz Mahyuddi)
* Prevent making a request if clicking on local anchor link (Patch from Kamal Fariz Mahyuddi)
* Added clicks_link_within(selector, link_text), allowing restricting link search
to within a given css selector (Path from Luke Melia)
to within a given css selector (Patch from Luke Melia)
* Allow specifying the input name/label when doing a select (Patch from David Chelimsky)
* Raise a specific exception if the developer tries to manipulate form elements before loading a page (Patch from James Deville)
* Add support for alternate POST, PUT and DELETE link clicking (Patch from Kyle Hargraves)

View File

@ -10,6 +10,7 @@ module Webrat
method ||= http_method
return if href =~ /^#/ && method == :get
update_protocol(href)
Page.new(@page.session, absolute_href, method, authenticity_token.blank? ? {} : {"authenticity_token" => authenticity_token})
end
@ -27,8 +28,18 @@ module Webrat
@element["href"]
end
def update_protocol(href)
if href =~ /^https:/
@page.session.https!(true)
elsif href =~ /^http:/
@page.session.https!(false)
end
end
def absolute_href
if href =~ /^\?/
if href =~ %r{^https?://www.example.com(/.*)}
$LAST_MATCH_INFO.captures.first
elsif href =~ /^\?/
"#{@page.url}#{href}"
elsif href !~ /^\//
"#{@page.url}/#{href}"

View File

@ -200,6 +200,23 @@ describe "clicks_link" do
@session.clicks_link "Jump to sub page"
end
it "should follow fully qualified local links" do
@response.stubs(:body).returns(<<-EOS)
<a href="http://www.example.com/page/sub">Jump to sub page</a>
EOS
@session.expects(:get_via_redirect).with("/page/sub", {})
@session.clicks_link "Jump to sub page"
end
it "should follow fully qualified secure local links" do
@response.stubs(:body).returns(<<-EOS)
<a href="https://www.example.com/page/sub">Jump to sub page</a>
EOS
@session.expects(:https!).with(true)
@session.expects(:get_via_redirect).with("/page/sub", {})
@session.clicks_link "Jump to sub page"
end
it "should follow query parameters" do
@session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS)