[Catalyst-commits] r11881 - in Catalyst-Engine-Embeddable/trunk:
lib/Catalyst/Engine t t/lib/TestApp/Controller
t0m at dev.catalyst.perl.org
t0m at dev.catalyst.perl.org
Wed Nov 18 01:27:43 GMT 2009
Author: t0m
Date: 2009-11-18 01:27:42 +0000 (Wed, 18 Nov 2009)
New Revision: 11881
Added:
Catalyst-Engine-Embeddable/trunk/t/base.t
Catalyst-Engine-Embeddable/trunk/t/error.t
Modified:
Catalyst-Engine-Embeddable/trunk/lib/Catalyst/Engine/Embeddable.pm
Catalyst-Engine-Embeddable/trunk/t/lib/TestApp/Controller/Root.pm
Log:
Update to be able to get the errors captured during the request back + tests
Modified: Catalyst-Engine-Embeddable/trunk/lib/Catalyst/Engine/Embeddable.pm
===================================================================
--- Catalyst-Engine-Embeddable/trunk/lib/Catalyst/Engine/Embeddable.pm 2009-11-18 00:51:29 UTC (rev 11880)
+++ Catalyst-Engine-Embeddable/trunk/lib/Catalyst/Engine/Embeddable.pm 2009-11-18 01:27:42 UTC (rev 11881)
@@ -10,9 +10,10 @@
our $VERSION = '0.000002';
sub prepare_request {
- my ($self, $c, $req, $res_ref) = @_;
+ my ($self, $c, $req, $res_ref, $err_ref) = @_;
$c->req->{_engine_embeddable}{req} = $req;
$c->req->{_engine_embeddable}{res} = $res_ref;
+ $c->req->{_engine_embeddable}{err} = $err_ref;
$c->req->method($req->method);
}
@@ -29,7 +30,7 @@
my ($self, $c) = @_;
my $uri = $c->req->{_engine_embeddable}{req}->uri();
- my $base = $uri->clone; $base->path('/');
+ my $base = $uri->clone; $base->path('/'); $base->path_query('');
$c->req->uri($uri);
$c->req->base($base);
@@ -55,6 +56,17 @@
$c->req->{_body} = $http_body;
}
+sub finalize_error {
+ my ($self, $c) = @_;
+
+ $self->next::method($c, @_);
+
+ @{ $c->req->{_engine_embeddable}{err} } = @{ $c->error }
+ if $c->req->{_engine_embeddable}{err};
+
+ $c->res->status(500);
+}
+
sub finalize_headers {
my ($self, $c) = @_;
Added: Catalyst-Engine-Embeddable/trunk/t/base.t
===================================================================
--- Catalyst-Engine-Embeddable/trunk/t/base.t (rev 0)
+++ Catalyst-Engine-Embeddable/trunk/t/base.t 2009-11-18 01:27:42 UTC (rev 11881)
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+use HTTP::Request;
+
+BEGIN { $ENV{CATALYST_ENGINE} = 'Embeddable' };
+BEGIN { use_ok('Catalyst::Engine::Embeddable') };
+
+use lib 't/lib';
+require TestApp;
+
+my ($req, $res);
+
+$req = HTTP::Request->new(GET => 'http://www.catalystframework.org/mkuri?foo=bar');
+$res = undef;
+
+TestApp->handle_request($req, \$res);
+
+ok($res, 'Response object defined.');
+is($res->code, 200, 'Response code correct.');
+is($res->content, 'http://www.catalystframework.org/path/to/somewhere');
+
+$req = HTTP::Request->new(GET => 'http://www.catalystframework.org/mkuriwithpath?foo=bar&foo=baz&one=two');
+$res = undef;
+
+TestApp->handle_request($req, \$res);
+
+ok($res, 'Response object defined.');
+is($res->code, 200, 'Response code correct.');
+is($res->content, 'http://www.catalystframework.org/path/to/somewhere?baz=qux');
+
Added: Catalyst-Engine-Embeddable/trunk/t/error.t
===================================================================
--- Catalyst-Engine-Embeddable/trunk/t/error.t (rev 0)
+++ Catalyst-Engine-Embeddable/trunk/t/error.t 2009-11-18 01:27:42 UTC (rev 11881)
@@ -0,0 +1,33 @@
+use strict;
+use warnings;
+
+use Test::More tests => 10;
+
+use HTTP::Request;
+
+BEGIN { $ENV{CATALYST_ENGINE} = 'Embeddable' };
+BEGIN { use_ok('Catalyst::Engine::Embeddable') };
+
+use lib 't/lib';
+require TestApp;
+
+my ($req, $res, @err);
+
+$req = HTTP::Request->new(GET => '/eatit');
+$res = undef;
+
+TestApp->handle_request($req, \$res);
+
+ok($res, 'Response object defined.');
+is($res->code, 500, 'Response code correct.');
+like($res->content, qr/Please come back later/, 'exception handled by catalyst');
+cmp_ok((scalar @err), '==', 0, 'no errors returned');
+
+TestApp->handle_request($req, \$res, \@err);
+
+ok($res, 'Response object defined.');
+is($res->code, 500, 'Response code correct.');
+like($res->content, qr/Please come back later/, 'exception handled by catalyst');
+cmp_ok((scalar @err), '==', 1, '1 error returned');
+like($err[0], qr/Caught exception in TestApp::Controller::Root->eatit "DIAF/, 'first error message');
+
Modified: Catalyst-Engine-Embeddable/trunk/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-Engine-Embeddable/trunk/t/lib/TestApp/Controller/Root.pm 2009-11-18 00:51:29 UTC (rev 11880)
+++ Catalyst-Engine-Embeddable/trunk/t/lib/TestApp/Controller/Root.pm 2009-11-18 01:27:42 UTC (rev 11881)
@@ -20,4 +20,19 @@
$c->res->body('Hello '.$c->req->param('who').'!');
}
+sub mkuri : Local {
+ my ( $self, $c ) = @_;
+ $c->res->body($c->uri_for('/path/to/somewhere'));
+}
+
+sub mkuriwithpath : Local {
+ my ( $self, $c ) = @_;
+ $c->res->body($c->uri_for('/path/to/somewhere', { baz => 'qux' }));
+}
+
+sub eatit : Local {
+ my ( $self, $c ) = @_;
+ die 'DIAF';
+}
+
1;
More information about the Catalyst-commits
mailing list