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
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
@ -137,6 +133,11 @@ For example:
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/
end

View File

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