From: Dave Rolsky Date: Fri, 21 Jan 2011 18:44:31 +0000 (-0600) Subject: tests are passing X-Git-Tag: 0.01~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-Routes.git;a=commitdiff_plain;h=69d9fc4e5373a24f09d58f289d7b773b186a8479 tests are passing --- diff --git a/lib/CatalystX/Routes.pm b/lib/CatalystX/Routes.pm index 0d7f6b9..e284835 100644 --- a/lib/CatalystX/Routes.pm +++ b/lib/CatalystX/Routes.pm @@ -92,6 +92,19 @@ sub _process_args { $p{ActionClass} ||= 'REST'; + unless ( exists $p{Chained} ) { + $p{Chained} = q{/}; + + unless ( exists $p{PathPart} ) { + ( my $part = $path ) =~ s{^/}{}; + $p{PathPart} = [$part]; + } + } + + unless ( exists $p{Args} ) { + $p{Args} = [0]; + } + ( my $name = $path ) =~ s/(\W)/'X' . sprintf( '%x', ord($1) )/eg; return $name, \%p, $sub; diff --git a/t/lib/MyApp1/Controller/C1.pm b/t/lib/MyApp1/Controller/C1.pm index 9aeaba7..d8cc767 100644 --- a/t/lib/MyApp1/Controller/C1.pm +++ b/t/lib/MyApp1/Controller/C1.pm @@ -3,13 +3,15 @@ package MyApp1::Controller::C1; use Moose; use CatalystX::Routes; -extends 'Catalyst::Controller'; +BEGIN { extends 'Catalyst::Controller' } -sub _get { } -sub _get_html { } -sub _post { } -sub _put { } -sub _del { } +our %REQ; + +sub _get { $REQ{get}++ } +sub _get_html { $REQ{get_html}++ } +sub _post { $REQ{post}++ } +sub _put { $REQ{put}++ } +sub _del { $REQ{delete}++ } get '/foo' => \&_get; @@ -21,4 +23,8 @@ put '/foo' => \&_put; del '/foo' => \&_del; +sub normal : Chained('/') : Args(0) { + $REQ{normal}++; +} + 1; diff --git a/t/routes.t b/t/routes.t index ef7c160..9f63dd2 100644 --- a/t/routes.t +++ b/t/routes.t @@ -4,15 +4,61 @@ use warnings; use Test::More 0.88; use lib 't/lib'; -use MyApp1; +use Catalyst::Test 'MyApp1'; +use HTTP::Request::Common qw( GET PUT POST DELETE ); -my $app = MyApp1->new(); +get('/foo'); -ok( $app, 'instantiated MyApp1' ); +is( + $MyApp1::Controller::C1::REQ{get}, 1, + 'GET request for /foo went to the right sub' +); -my $action = $app->dispatcher()->get_action('/foo'); +request( + GET '/foo', + [ + Accept => '*/*', + ] +); -ok( $action, 'got an action for /foo' ); +is( + $MyApp1::Controller::C1::REQ{get_html}, 1, + 'GET request for /foo that looks like a browser went to the right sub' +); +request( POST '/foo' ); + +is( + $MyApp1::Controller::C1::REQ{post}, 1, + 'POST request for /foo went to the right sub' +); + +request( PUT '/foo' ); + +is( + $MyApp1::Controller::C1::REQ{put}, 1, + 'PUT request for /foo went to the right sub' +); + +request( DELETE '/foo' ); + +is( + $MyApp1::Controller::C1::REQ{delete}, 1, + 'DELETE request for /foo went to the right sub' +); + +get('/normal'); + +is( + $MyApp1::Controller::C1::REQ{normal}, 1, + 'GET request for /norma went to the right sub' +); + +request( POST '/normal' ); + +is( + $MyApp1::Controller::C1::REQ{normal}, 2, + 'POST request for /norma went to the right sub' +); done_testing();