stripping anchor tags from URIs before passing to rails integration session

This commit is contained in:
Noah Davis 2008-12-19 14:32:02 -05:00
parent 7d63aa1a4d
commit 0b9fd99bc0
2 changed files with 18 additions and 6 deletions

View File

@ -48,15 +48,18 @@ module Webrat
def do_request(http_method, url, data, headers) #:nodoc: def do_request(http_method, url, data, headers) #:nodoc:
update_protocol(url) update_protocol(url)
integration_session.request_via_redirect(http_method, remove_protocol(url), data, headers) url = normalize_url(url)
integration_session.request_via_redirect(http_method, url, data, headers)
end end
def remove_protocol(href) #:nodoc: # remove protocol, host and anchor
if href =~ %r{^https?://www.example.com(/.*)} def normalize_url(href) #:nodoc:
$LAST_MATCH_INFO.captures.first uri = URI.parse(href)
else normalized_url = uri.path
href if uri.query
normalized_url += "?" + uri.query
end end
normalized_url
end end
def update_protocol(href) #:nodoc: def update_protocol(href) #:nodoc:

View File

@ -69,6 +69,15 @@ describe Webrat::RailsSession do
end end
end end
context "the URL include an anchor" do
it "should strip out the anchor" do
integration_session = mock("integration session", :https! => false)
rails_session = Webrat::RailsSession.new(integration_session)
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
rails_session.get("http://www.example.com/url#foo", "data", "headers")
end
end
it "should provide a saved_page_dir" do it "should provide a saved_page_dir" do
Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir) Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
end end