From ce36e5890fc35ae87f02d1dcd9b6ea37dc052c4b Mon Sep 17 00:00:00 2001 From: Adam Greene Date: Wed, 14 Jan 2009 12:53:29 -0800 Subject: [PATCH] lets follow redirects that are on the same domain but a different subdomain... --- lib/webrat/core/session.rb | 12 ++++++++++-- spec/private/core/session_spec.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 8010436..b3c8688 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -125,8 +125,16 @@ For example: response_code / 100 == 3 end - def internal_redirect? #:nodoc: - redirect? && current_host == response_location_host + # def internal_redirect? #:nodoc: + # redirect? && current_host == response_location_host + # end + + def internal_redirect? + return false unless redirect? + #should keep internal_redirects if the subdomain changes + current_host_domain = current_host.split('.')[-2..-1].join('.') rescue current_host + response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host + current_host_domain == response_location_host_domain end def exception_caught? #:nodoc: diff --git a/spec/private/core/session_spec.rb b/spec/private/core/session_spec.rb index d67b49b..33f2e8b 100644 --- a/spec/private/core/session_spec.rb +++ b/spec/private/core/session_spec.rb @@ -159,6 +159,13 @@ describe Webrat::Session do webrat_session.internal_redirect?.should be_true end + it "should return true if the last response was a redirect and the hosts are the same but the subdomains are different" do + webrat_session.stub!(:redirect? => true) + webrat_session.stub!(:current_url => "http://example.com") + webrat_session.stub!(:response_location => "http://myName.example.com") + webrat_session.internal_redirect?.should be_true + end + it "should return false if the last response was not a redirect" do webrat_session.stub!(:redirect? => false) webrat_session.internal_redirect?.should be_false @@ -170,5 +177,13 @@ describe Webrat::Session do webrat_session.stub!(:response_location => "http://google.com") webrat_session.internal_redirect?.should be_false end + + it "should return false if the last response was a redirect but the host of the current_url doesn't matches that of the response location, but they have the same subdomain" do + webrat_session.stub!(:redirect? => true) + webrat_session.stub!(:current_url => "http://login.example.com") + webrat_session.stub!(:response_location => "http://login.google.com") + webrat_session.internal_redirect?.should be_false + end + end end \ No newline at end of file