From 4e3cf59920472cd0164fdfcd883bfcba0ff56b44 Mon Sep 17 00:00:00 2001 From: Adam Greene Date: Fri, 16 Jan 2009 12:12:50 -0800 Subject: [PATCH] adding a helper method to make it easier to see where the user was redirected_to --- lib/webrat/core/session.rb | 9 +++++---- spec/private/core/session_spec.rb | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index b3c8688..fd47598 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -125,10 +125,6 @@ For example: response_code / 100 == 3 end - # 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 @@ -136,6 +132,11 @@ For example: response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host current_host_domain == response_location_host_domain end + + #easy helper to pull out where we were redirected to + def redirected_to + redirect? ? response_location : nil + end def exception_caught? #:nodoc: response_body =~ /Exception caught/ diff --git a/spec/private/core/session_spec.rb b/spec/private/core/session_spec.rb index 33f2e8b..917a951 100644 --- a/spec/private/core/session_spec.rb +++ b/spec/private/core/session_spec.rb @@ -184,6 +184,24 @@ describe Webrat::Session do webrat_session.stub!(:response_location => "http://login.google.com") webrat_session.internal_redirect?.should be_false end - end + + describe "#redirected_to" do + before(:each) do + webrat_session = Webrat::Session.new + end + + it "should return nil if not redirected" do + webrat_session.stub!(:redirect? => false) + webrat_session.redirected_to.should be_nil + end + + it "should return the response_location if redirected" do + webrat_session.stub!(:redirect? => true) + webrat_session.stub!(:response_location => "http://www.example.com") + webrat_session.redirected_to.should == "http://www.example.com" + end + + end + end \ No newline at end of file