Skip to content

Commit

Permalink
Fixed following of internal redirects when using a custom Host header
Browse files Browse the repository at this point in the history
  Webrat didn't properly follow internal redirects when using the Host
  header, this lets Webrat check the Host header before falling back
  to www.example.com as the current_host.
  • Loading branch information
Mutwin Kraus committed Apr 25, 2009
1 parent 481bfe0 commit eddd979
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webrat/core/session.rb
Expand Up @@ -264,7 +264,7 @@ def response_location
end

def current_host
URI.parse(current_url).host || "www.example.com"
URI.parse(current_url).host || @custom_headers["Host"] || "www.example.com"
end

def response_location_host
Expand Down
4 changes: 4 additions & 0 deletions spec/integration/rails/app/controllers/webrat_controller.rb
Expand Up @@ -25,6 +25,10 @@ def external_redirect
redirect_to "http://google.com"
end

def host_redirect
redirect_to submit_url
end

def before_redirect_form
end

Expand Down
1 change: 1 addition & 0 deletions spec/integration/rails/config/routes.rb
Expand Up @@ -4,6 +4,7 @@
webrat.internal_redirect "/internal_redirect", :action => "internal_redirect"
webrat.external_redirect "/external_redirect", :action => "external_redirect"
webrat.infinite_redirect "/infinite_redirect", :action => "infinite_redirect"
webrat.host_redirect "/host_redirect", :action => "host_redirect"

webrat.before_redirect_form "/before_redirect_form", :action => "before_redirect_form"
webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
Expand Down
7 changes: 7 additions & 0 deletions spec/integration/rails/test/integration/webrat_test.rb
Expand Up @@ -45,6 +45,13 @@ class WebratTest < ActionController::IntegrationTest
assert response.redirect?
end

test "should recognize the host header to follow redirects properly" do
header "Host", "foo.bar"
visit host_redirect_path
assert !response.redirect?
assert response.body.include?("OK")
end

test "should click link by text" do
visit internal_redirect_path
click_link "Test Link Text"
Expand Down

1 comment on commit eddd979

@kamk
Copy link

@kamk kamk commented on eddd979 May 28, 2009

Choose a reason for hiding this comment

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

This fix helped me getting rid of "visit response.location" in stories tests.

Please sign in to comment.