X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Fconfigured_comps.t;fp=t%2Fconfigured_comps.t;h=84a5a8e8361bb762dbb414aa895861b5592b1d9c;hp=0000000000000000000000000000000000000000;hb=ec4d72594fb7a701c2f36e85ecf9a680ca1abba2;hpb=d9f0a350554cca79adefd4e97b4982d431f8c914 diff --git a/t/configured_comps.t b/t/configured_comps.t new file mode 100644 index 0000000..84a5a8e --- /dev/null +++ b/t/configured_comps.t @@ -0,0 +1,76 @@ +use warnings; +use strict; +use HTTP::Request::Common; +use Test::More; + +{ + package Local::Controller::Errors; + + use Moose; + use MooseX::MethodAttributes; + + extends 'Catalyst::Controller'; + + has ['a', 'b'] => (is=>'ro', required=>1); + + sub not_found :Local { pop->res->from_psgi_response(404, [], ['Not Found']) } + + package MyApp::Model::User; + $INC{'MyApp/Model/User.pm'} = __FILE__; + + use base 'Catalyst::Model'; + + our %users = ( + 1 => { name => 'john', age => 46 }, + 2 => { name => 'mary', age => 36 }, + 3 => { name => 'ian', age => 25 }, + 4 => { name => 'visha', age => 18 }, + ); + + sub find { + my ($self, $id) = @_; + my $user = $users{$id} || return; + return bless $user, "MyApp::Model::User::user"; + } + + package MyApp::Controller::Root; + $INC{'MyApp/Controller/Root.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + + extends 'Catalyst::Controller'; + + sub user :Local Args(1) { + my ($self, $c, $int) = @_; + my $user = $c->model("User")->find($int); + $c->res->body("name: $user->{name}, age: $user->{age}"); + } + + sub default :Default { + my ($self, $c, $int) = @_; + $c->res->body('default'); + } + + MyApp::Controller::Root->config(namespace=>''); + + package MyApp; + use Catalyst; + + MyApp->config({ + 'Controller::Err' => { + component => 'Local::Controller::Errors' + } + }); + + MyApp->setup; +} + +use Catalyst::Test 'MyApp'; + +{ + my $res = request '/user/1'; + is $res->content, 'name: john, age: 46'; +} + +done_testing;