TWMC: Fix bug where redirect was followed on a 500 response
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / lib / Catty.pm
index cdd1405..83e6745 100644 (file)
@@ -1,11 +1,13 @@
 package Catty;
 
 use strict;
+use warnings;
 
 #use Catalyst;
-use Catalyst qw/-Debug/;
+use Catalyst;
 use Cwd;
 use MIME::Base64;
+use Encode qw//;
 
 our $VERSION = '0.01';
 
@@ -13,8 +15,8 @@ Catty->config(
     name => 'Catty',
     root => cwd . '/t/root',
 );
-
 Catty->setup();
+Catty->log->levels("fatal");
 
 sub default : Private {
     my ( $self, $context ) = @_;
@@ -25,7 +27,8 @@ sub default : Private {
 
 sub hello : Global {
     my ( $self, $context ) = @_;
-    my $html = html( "Hello", "Hi there! ☺" );
+    my $str = Encode::encode('utf-8', "\x{263A}"); # ☺
+    my $html = html( "Hello", "Hi there! $str" );
     $context->response->content_type("text/html; charset=utf-8");
     $context->response->output($html);
 }
@@ -74,6 +77,13 @@ sub check_auth_basic : Global {
     }
 }
 
+sub redirect_with_500 : Global {
+    my ( $self, $c ) = @_;
+    $DB::single = 1;
+    $c->res->redirect( $c->uri_for("/bonjour"));
+    die "erk!";
+}
+
 sub die : Global {
     my ( $self, $context ) = @_;
     my $html = html( "Die", "This is the die page" );
@@ -82,6 +92,23 @@ sub die : Global {
     die "erk!";
 }
 
+sub name : Global {
+    my ($self, $c) = @_;
+
+    my $html = html( $c->config->{name}, "This is the die page" );
+    $c->response->content_type("text/html");
+    $c->response->output($html);
+}
+
+sub host : Global {
+    my ($self, $c) = @_;
+
+    my $host = $c->req->header('Host') || "<undef>";
+    my $html = html( $c->config->{name}, "Host: $host" );
+    $c->response->content_type("text/html");
+    $c->response->output($html);
+}
+
 sub html {
     my ( $title, $body ) = @_;
     return qq{
@@ -108,5 +135,14 @@ sub gzipped : Global {
     $c->response->headers->push_header( 'Vary', 'Accept-Encoding' );
 }
 
+sub user_agent : Global {
+    my ( $self, $c ) = @_;
+    
+    my $html = html($c->req->user_agent, $c->req->user_agent);
+    $c->response->content_type("text/html; charset=utf-8");
+    $c->response->output( $html );
+    
+}
+
 1;