Skip to content

Commit

Permalink
removing the normalization of url's for the rails session. stipping t…
Browse files Browse the repository at this point in the history
…hem of host, port, and anchors is not really needed, especially since josh's redirect change to stop when going to a different host. See comments here: http://webrat.lighthouseapp.com/projects/10503-webrat/tickets/132
  • Loading branch information
Adam Greene authored and joshknowles committed Jan 21, 2009
1 parent 4e3cf59 commit 4fc2b7e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
14 changes: 3 additions & 11 deletions lib/webrat/rails.rb
Expand Up @@ -65,19 +65,11 @@ def integration_session
@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, 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
integration_session.send(http_method, url, data, headers)
end

def update_protocol(href) #:nodoc:
Expand Down
13 changes: 7 additions & 6 deletions spec/private/rails/rails_session_spec.rb
Expand Up @@ -6,6 +6,7 @@
before :each do
Webrat.configuration.mode = :rails
@integration_session = mock("integration_session")
@integration_session.stub!(:response => mock("response", :body => "<html>", :code => '200'))
end

it "should delegate response_body to the session response body" do
Expand Down Expand Up @@ -43,18 +44,18 @@
end

context "the URL is a full path" do
it "should just pass on the path" do
it "should pass the full url" do
@integration_session.stub!(:https!)
@integration_session.should_receive(:get).with("/url", "data", "headers")
@integration_session.should_receive(:get).with("http://www.example.com/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 and just pass on the path" do
it "should call #https! with true before the request before passing along the full url" do
@integration_session.should_receive(:https!).with(true)
@integration_session.should_receive(:get).with("/url", "data", "headers")
@integration_session.should_receive(:get).with("https://www.example.com/url", "data", "headers")
rails_session = Webrat::RailsSession.new(@integration_session)
rails_session.get("https://www.example.com/url", "data", "headers")
end
Expand All @@ -70,9 +71,9 @@
end

context "the URL include an anchor" do
it "should strip out the anchor" do
it "should keep the anchor" do
@integration_session.should_receive(:https!).with(false)
@integration_session.should_receive(:get).with("/url", "data", "headers")
@integration_session.should_receive(:get).with("http://www.example.com/url#foo", "data", "headers")
rails_session = Webrat::RailsSession.new(@integration_session)
rails_session.get("http://www.example.com/url#foo", "data", "headers")
end
Expand Down

0 comments on commit 4fc2b7e

Please sign in to comment.