TWMC: Fix bug where redirect was followed on a 500 response
[catagits/Test-WWW-Mechanize-Catalyst.git] / lib / Test / WWW / Mechanize / Catalyst.pm
index 866a09f..8910c44 100644 (file)
@@ -99,6 +99,7 @@ sub _make_request {
 
     # check if that was a redirect
     if (   $response->header('Location')
+        && $response->is_redirect
         && $self->redirect_ok( $request, $response ) )
     {
 
@@ -142,8 +143,6 @@ sub _do_catalyst_request {
     return Catalyst::Test::remote_request($request)
       if $ENV{CATALYST_SERVER};
 
-
-
     # If there's no Host header, set one.
     unless ($request->header('Host')) {
       my $host = $self->has_host
@@ -452,6 +451,21 @@ Returns true value if the specified link was found and followed
 successfully.  The HTTP::Response object returned by follow_link()
 is not available.
 
+=head1 CAVEATS
+
+=head2 External Redirects and allow_external
+
+If you use non-fully qualified urls in your test scripts (i.e. anything without
+a host, such as C<< ->get_ok( "/foo") >> ) and your app redirects to an
+external URL, expect to be bitten once you come back to your application's urls
+(it will try to request them on the remote server.) This is due to a limitation
+in WWW::Mechanize.
+
+One workaround for this is that if you are expecting to redirect to an external
+site, clone the TWMC obeject and use the cloned object for the external
+redirect.
+
+
 =head1 SEE ALSO
 
 Related modules which may be of interest: L<Catalyst>,