Skip to content

Commit

Permalink
Fixed issue where webrat was only using relative paths when making re…
Browse files Browse the repository at this point in the history
…quests for Rails apps. This borked Rails apps that use subdomains [John Hwang/Zach Dennis]
  • Loading branch information
zdennis authored and joshknowles committed Jan 21, 2009
1 parent 7a59353 commit 0272e81
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 7 additions & 5 deletions lib/webrat/rails.rb
Expand Up @@ -73,11 +73,13 @@ def do_request(http_method, url, data, headers) #:nodoc:
# 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
normalized_url = []
normalized_url << "#{uri.scheme}://" if uri.scheme
normalized_url << uri.host if uri.host
normalized_url << ":#{uri.port}" if uri.port && ![80,443].include?(uri.port)
normalized_url << uri.path if uri.path
normalized_url << "?#{uri.query}" if uri.query
normalized_url.join
end

def update_protocol(href) #:nodoc:
Expand Down
7 changes: 6 additions & 1 deletion spec/integration/rails/test/integration/webrat_test.rb
@@ -1,7 +1,12 @@
require 'test_helper'

class WebratTest < ActionController::IntegrationTest


test "should visit fully qualified urls" do
visit root_url(:host => "chunkybacon.example.com")
assert_equal "chunkybacon", request.subdomains.first
end

test "should visit pages" do
visit root_path
assert_tag "Webrat Form"
Expand Down
10 changes: 5 additions & 5 deletions spec/private/rails/rails_session_spec.rb
Expand Up @@ -43,18 +43,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 @@ -72,7 +72,7 @@
context "the URL include an anchor" do
it "should strip out 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", "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 0272e81

Please sign in to comment.