From: Dave Rolsky Date: Mon, 24 Jan 2011 03:48:41 +0000 (-0600) Subject: Handle a controller where the namespace is the empty string nicely. X-Git-Tag: 0.01~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalystX-Routes.git;a=commitdiff_plain;h=7bdb05c2732d4d130a42713e8bd6507d7fadb44c Handle a controller where the namespace is the empty string nicely. Add some tests for this. --- diff --git a/lib/CatalystX/Routes.pm b/lib/CatalystX/Routes.pm index 67e43ef..ccd2fa7 100644 --- a/lib/CatalystX/Routes.pm +++ b/lib/CatalystX/Routes.pm @@ -112,6 +112,7 @@ sub _process_args { unless ( $part =~ s{^/}{} ) { $part = join q{/}, $meta->name()->action_namespace('FakeConfig'), $part; + $part =~ s{^/}{}; } } diff --git a/t/lib/MyApp1/Controller/Root.pm b/t/lib/MyApp1/Controller/Root.pm new file mode 100644 index 0000000..21b8481 --- /dev/null +++ b/t/lib/MyApp1/Controller/Root.pm @@ -0,0 +1,16 @@ +package MyApp1::Controller::Root; + +use Moose; +use CatalystX::Routes; + +BEGIN { extends 'Catalyst::Controller' } + +__PACKAGE__->config()->{namespace} = q{}; + +our %REQ; + +get q{} => args 0 => sub { $REQ{root}++ }; + +get q{foo.txt} => args 0 => sub { $REQ{'foo.txt'}++ }; + +1; diff --git a/t/routes.t b/t/routes.t index b0d03bb..52296ec 100644 --- a/t/routes.t +++ b/t/routes.t @@ -144,4 +144,20 @@ use HTTP::Request::Common qw( GET PUT POST DELETE ); ); } +{ + request( GET '/' ); + + is( + $MyApp1::Controller::Root::REQ{root}, 1, + 'GET request for / went to the right sub (routes work when namespace is empty string)' + ); + + request( GET '/foo.txt' ); + + is( + $MyApp1::Controller::Root::REQ{'foo.txt'}, 1, + 'GET request for /foo.txt went to the right sub (routes work when namespace is empty string)' + ); +} + done_testing();