stripping anchor tags from URIs before passing to rails integration session
This commit is contained in:
parent
7d63aa1a4d
commit
0b9fd99bc0
@ -48,15 +48,18 @@ module Webrat
|
||||
|
||||
def do_request(http_method, url, data, headers) #:nodoc:
|
||||
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
|
||||
|
||||
def remove_protocol(href) #:nodoc:
|
||||
if href =~ %r{^https?://www.example.com(/.*)}
|
||||
$LAST_MATCH_INFO.captures.first
|
||||
else
|
||||
href
|
||||
# remove protocol, host and anchor
|
||||
def normalize_url(href) #:nodoc:
|
||||
uri = URI.parse(href)
|
||||
normalized_url = uri.path
|
||||
if uri.query
|
||||
normalized_url += "?" + uri.query
|
||||
end
|
||||
normalized_url
|
||||
end
|
||||
|
||||
def update_protocol(href) #:nodoc:
|
||||
|
@ -69,6 +69,15 @@ describe Webrat::RailsSession do
|
||||
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
|
||||
Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user