Handle a controller where the namespace is the empty string nicely.
Dave Rolsky [Mon, 24 Jan 2011 03:48:41 +0000 (21:48 -0600)]
Add some tests for this.

lib/CatalystX/Routes.pm
t/lib/MyApp1/Controller/Root.pm [new file with mode: 0644]
t/routes.t

index 67e43ef..ccd2fa7 100644 (file)
@@ -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 (file)
index 0000000..21b8481
--- /dev/null
@@ -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;
index b0d03bb..52296ec 100644 (file)
@@ -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();