Skip to content

Commit

Permalink
adding a helper method to make it easier to see where the user was re…
Browse files Browse the repository at this point in the history
…directed_to
  • Loading branch information
Adam Greene authored and joshknowles committed Jan 21, 2009
1 parent ce36e58 commit 4e3cf59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/webrat/core/session.rb
Expand Up @@ -125,17 +125,18 @@ def redirect? #:nodoc:
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
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

#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/
Expand Down
20 changes: 19 additions & 1 deletion spec/private/core/session_spec.rb
Expand Up @@ -184,6 +184,24 @@ def session.response_body
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

1 comment on commit 4e3cf59

@adkron
Copy link
Contributor

@adkron adkron commented on 4e3cf59 Jan 21, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work in selenium mode. At least not yet. =8-)

Please sign in to comment.