#168 ✓resolved
Kieran P

Redirects in Rails 2.3 not being followed by Webrat

Reported by Kieran P | February 17th, 2009 @ 05:52 PM

Have upgraded our app from Rails 2.1 to Rails 2.3 RC1 and the biggest issue so far has been nearly our entire webrat suite failing because of an issue.

The redirects in 2.3 return "You are being redirected" as the body then redirect pretty much instantly, which works in browsers, but webrat, instead of following the redirect, returns the page body that has that "You are being redirected" text.

i.e. the page body being returned by webrat via 'response.body' is not the page body of the page once redirects finish.

Hope that makes sense.

Comments and changes to this ticket

  • Mark Wilden

    Mark Wilden February 25th, 2009 @ 08:31 PM

    This seems to occur in Rails 2.2.2, too.

  • Jim Hoskins

    Jim Hoskins March 2nd, 2009 @ 11:06 PM

    I have experienced the same situation using Cucumber/webrat. My application is using subdomain based accounts, and I was using relative paths for my visits, which is what was causing the problem for me.

    When I would make visit calls with the relative path, rails would redirect with the fully qualified url, and the domain it being redirected to was not the same as the request (example.com by default). This made webrat think it was an external redirect, and it would not follow it.

    By changing the visit calls from _path to _url, webrat recognized the redirects as internal and redirected properly, and my tests passed.

    You may need to tell webrat/rails what the host is by calling host!("host.name")

    Hope this helps.

  • Nash

    Nash April 15th, 2009 @ 04:16 PM


    This is also happening when I click buttons whose forms have relative paths. When I change the path to a url + path, it seems to work.

    Have you found a fix for that?


  • Mutwin Kraus

    Mutwin Kraus April 25th, 2009 @ 03:31 AM

    I pushed a fix to my fork in this commit: http://github.com/mutle/webrat/c...

    I'm using header("Host", "host.name") to set the request hostname. This doesn't require the use of url instead of path in visit or the redirects.

  • Chris Roos

    Chris Roos April 30th, 2009 @ 11:59 AM


    I've just started using your fork of webrat to get this functionality and it works perfectly.

    Any thoughts on whether this might get rolled into the original repository?



  • gaffo

    gaffo May 10th, 2009 @ 10:27 PM

    • State changed from “new” to “open”

    Is this still an issue in the released version of rails 2.3? there were some major issues with redirects, flash, and templates in some of the 2.3 pre releases and edge versions.

  • Chris Roos

    Chris Roos May 11th, 2009 @ 05:45 PM

    I was experiencing the same problem as the original reporter (Kieran P) in a fresh rails 2.3 app. I'm currently using Mutwin's fork to work around the limitation.


  • Kieran P

    Kieran P May 13th, 2009 @ 07:09 PM

    gaffo, I've just confirmed that the latest nokogiri/webrat codebases (from github as of 1 hour ago) still have this issue.

    Mutwin Kraus's patch works nicely. Would be neat to have this fixed rather than a work around though.

  • Kieran P

    Kieran P May 13th, 2009 @ 07:18 PM

    From what I can tell, the problem here is Webrat is assuming that links/etc are pointing www.example.com (which in our case, they weren't).

    I've switched our _url generations to use www.example.com and things are working now (without Mutwin's patch).

  • gaffo

    gaffo June 15th, 2009 @ 12:49 AM

    • State changed from “open” to “awaiting-merge”

    I'm going to merge this one in with #207 (https://webrat.lighthouseapp.com/projects/10503/tickets/207-make-in...) as I think this will solve the issue. Please write here if I'm completely off base.

  • gaffo

    gaffo June 15th, 2009 @ 11:26 PM

    • Assigned user set to “Bryan Helmkamp”

    This looks like a good patch. One user confirmed this in irc recently.

  • Bryan Helmkamp

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Ruby Acceptance Testing for Web applications.

Shared Ticket Bins

Referenced by