adding a helper method to make it easier to see where the user was redirected_to

This commit is contained in:
Adam Greene 2009-01-16 12:12:50 -08:00 committed by Josh Knowles
parent ce36e5890f
commit 4e3cf59920
2 changed files with 24 additions and 5 deletions

View File

@ -125,10 +125,6 @@ For example:
response_code / 100 == 3 response_code / 100 == 3
end end
# def internal_redirect? #:nodoc:
# redirect? && current_host == response_location_host
# end
def internal_redirect? def internal_redirect?
return false unless redirect? return false unless redirect?
#should keep internal_redirects if the subdomain changes #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 response_location_host_domain = response_location_host.split('.')[-2..-1].join('.') rescue response_location_host
current_host_domain == response_location_host_domain current_host_domain == response_location_host_domain
end end
#easy helper to pull out where we were redirected to
def redirected_to
redirect? ? response_location : nil
end
def exception_caught? #:nodoc: def exception_caught? #:nodoc:
response_body =~ /Exception caught/ response_body =~ /Exception caught/

View File

@ -184,6 +184,24 @@ describe Webrat::Session do
webrat_session.stub!(:response_location => "http://login.google.com") webrat_session.stub!(:response_location => "http://login.google.com")
webrat_session.internal_redirect?.should be_false webrat_session.internal_redirect?.should be_false
end end
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 end