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 button elements (Patch from Nick Sieger)
* Support matching select options by regexp (Patch from Kyle Hargraves) * Support matching select options by regexp (Patch from Kyle Hargraves)
* Support relative links, including href="?foo=bar" (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 * Bug fixes
@ -27,7 +28,7 @@
* Added reloads method to reload the page (Patch from Kamal Fariz Mahyuddi) * 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) * 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 * 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) * 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) * 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) * 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 method ||= http_method
return if href =~ /^#/ && method == :get return if href =~ /^#/ && method == :get
update_protocol(href)
Page.new(@page.session, absolute_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
@ -27,8 +28,18 @@ module Webrat
@element["href"] @element["href"]
end end
def update_protocol(href)
if href =~ /^https:/
@page.session.https!(true)
elsif href =~ /^http:/
@page.session.https!(false)
end
end
def absolute_href def absolute_href
if href =~ /^\?/ if href =~ %r{^https?://www.example.com(/.*)}
$LAST_MATCH_INFO.captures.first
elsif href =~ /^\?/
"#{@page.url}#{href}" "#{@page.url}#{href}"
elsif href !~ /^\// elsif href !~ /^\//
"#{@page.url}/#{href}" "#{@page.url}/#{href}"

View File

@ -200,6 +200,23 @@ describe "clicks_link" do
@session.clicks_link "Jump to sub page" @session.clicks_link "Jump to sub page"
end 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 it "should follow query parameters" do
@session.current_page.stubs(:url).returns("/page") @session.current_page.stubs(:url).returns("/page")
@response.stubs(:body).returns(<<-EOS) @response.stubs(:body).returns(<<-EOS)