Fixed issue where webrat was only using relative paths when making requests for Rails apps. This borked Rails apps that use subdomains [John Hwang/Zach Dennis]

This commit is contained in:
Zach Dennis 2009-01-20 20:54:59 -05:00 committed by Josh Knowles
parent 7a59353c78
commit 0272e81847
3 changed files with 18 additions and 11 deletions

View File

@ -73,11 +73,13 @@ module Webrat
# 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:

View File

@ -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"

View File

@ -43,18 +43,18 @@ describe Webrat::RailsSession do
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
@ -72,7 +72,7 @@ describe Webrat::RailsSession do
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