diff --git a/lib/webrat/rails.rb b/lib/webrat/rails.rb index 5a30faa..e5af9ac 100644 --- a/lib/webrat/rails.rb +++ b/lib/webrat/rails.rb @@ -65,11 +65,19 @@ module Webrat @context end - #now that we are not following external links, do NOT normalize the url and strip it of its host - #once we get here we don't care about stripping out the host because we know def do_request(http_method, url, data, headers) #:nodoc: update_protocol(url) - integration_session.send(http_method, url, data, headers) + integration_session.send(http_method, normalize_url(url), data, headers) + end + + # 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: diff --git a/spec/private/rails/rails_session_spec.rb b/spec/private/rails/rails_session_spec.rb index a791f12..4f53e4b 100644 --- a/spec/private/rails/rails_session_spec.rb +++ b/spec/private/rails/rails_session_spec.rb @@ -6,7 +6,6 @@ describe Webrat::RailsSession do before :each do Webrat.configuration.mode = :rails @integration_session = mock("integration_session") - @integration_session.stub!(:response => mock("response", :body => "", :code => '200')) end it "should delegate response_body to the session response body" do @@ -44,18 +43,18 @@ describe Webrat::RailsSession do end context "the URL is a full path" do - it "should pass the full url" do + it "should just pass on the path" do @integration_session.stub!(:https!) - @integration_session.should_receive(:get).with("http://www.example.com/url", "data", "headers") + @integration_session.should_receive(:get).with("/url", "data", "headers") rails_session = Webrat::RailsSession.new(@integration_session) rails_session.get("http://www.example.com/url", "data", "headers") end end context "the URL is https://" do - it "should call #https! with true before the request before passing along the full url" do + it "should call #https! with true before the request and just pass on the path" do @integration_session.should_receive(:https!).with(true) - @integration_session.should_receive(:get).with("https://www.example.com/url", "data", "headers") + @integration_session.should_receive(:get).with("/url", "data", "headers") rails_session = Webrat::RailsSession.new(@integration_session) rails_session.get("https://www.example.com/url", "data", "headers") end @@ -71,9 +70,9 @@ describe Webrat::RailsSession do end context "the URL include an anchor" do - it "should keep the anchor" do + it "should strip out the anchor" do @integration_session.should_receive(:https!).with(false) - @integration_session.should_receive(:get).with("http://www.example.com/url#foo", "data", "headers") + @integration_session.should_receive(:get).with("/url", "data", "headers") rails_session = Webrat::RailsSession.new(@integration_session) rails_session.get("http://www.example.com/url#foo", "data", "headers") end