Fix some more legacy uri tests
Tomas Doran [Tue, 2 Feb 2010 02:57:19 +0000 (02:57 +0000)]
lib/Gitalist/Controller/LegacyURI.pm
t/03legacy_uri.t

index 83bbb08..cd8b599 100644 (file)
@@ -6,15 +6,15 @@ use namespace::autoclean;
 BEGIN { extends 'Gitalist::Controller' }
 
 sub handler : Chained('/base') PathPart('legacy') Args() {
-    my ( $self, $c ) = @_;
-    my $action;
+    my ( $self, $c, $repos ) = @_;
+    my ($action, @captures);
     if (my $a = $c->req->param('a')) {
         $a eq 'opml' && do { $action = '/opml/opml'; };
         $a eq 'project_index' && do { $action = '/legacyuri/project_index'; };
-        $a eq 'summary' && do { $action = '/repository/summary'; };
+        $a =~ /^(summary|heads|tags)$/ && do { $action = "/repository/$1"; push(@captures, $repos); };
     }
     die("Not supported") unless $action;
-    $c->res->redirect($c->uri_for_action($action));
+    $c->res->redirect($c->uri_for_action($action, \@captures));
     $c->res->status(301);
 }
 
index c85e931..4390baa 100644 (file)
@@ -7,10 +7,11 @@ ok( request('/')->is_success, 'Request should succeed' );
 
 sub test {
     my ($uri, $qs) = @_;
-    my $request = $uri; 
+    my $request = "/$uri";
+    $request =~ s{/+}{/}g;
     $request .= "?$qs" if defined $qs;
     my $response = request($request);
-    $uri = $response->header('Location');
+    $uri = $response->header('Location') || '';
     is($response->code, 301, "ok $request 301 to " . $uri)
         or return $response;
     $response = request($uri);
@@ -24,13 +25,16 @@ sub test {
 test('/', 'a=project_index');
 test('/', 'a=opml');
 
-{
-    local *test = curry_test_uri('repos1', \&test);
-    local $TODO = 'FIXME';
-
+no warnings 'redefine';
+local *test = curry_test_uri('repo1', \&test);
+test('/', 'a=project_index');
+test('/', 'a=opml');
 test('/', 'a=summary');
 test('/', 'a=heads');
 test('/', 'a=tags');
+{
+
+    local $TODO = 'FIXME';
 
 test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
 test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD');