Get a couple of the legacy uri tests working
Tomas Doran [Tue, 2 Feb 2010 02:42:27 +0000 (02:42 +0000)]
lib/Gitalist/Controller/LegacyURI.pm
t/03legacy_uri.t

index 07f338d..83bbb08 100644 (file)
@@ -6,10 +6,19 @@ use namespace::autoclean;
 BEGIN { extends 'Gitalist::Controller' }
 
 sub handler : Chained('/base') PathPart('legacy') Args() {
-    die("Not supported");
+    my ( $self, $c ) = @_;
+    my $action;
+    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'; };
+    }
+    die("Not supported") unless $action;
+    $c->res->redirect($c->uri_for_action($action));
+    $c->res->status(301);
 }
 
-sub repository_index : Chained('/base') Args(0) {
+sub project_index : Chained('/base') Args(0) {
       my ( $self, $c ) = @_;
 
       $c->response->content_type('text/plain');
index df7ffde..c85e931 100644 (file)
@@ -1,12 +1,32 @@
 #!/usr/bin/env perl
 use FindBin qw/$Bin/;
 use lib "$Bin/lib";
-use TestGitalist;
+use TestGitalist qw/request curry_test_uri done_testing ok is $TODO/;
 
 ok( request('/')->is_success, 'Request should succeed' );
 
+sub test {
+    my ($uri, $qs) = @_;
+    my $request = $uri; 
+    $request .= "?$qs" if defined $qs;
+    my $response = request($request);
+    $uri = $response->header('Location');
+    is($response->code, 301, "ok $request 301 to " . $uri)
+        or return $response;
+    $response = request($uri);
+    ok($response->is_success, "ok $uri");
+    return $response;
+}
+# FIXME
 # URI tests for repo1
-local *test = curry_test_uri('repo1');
+#local *test = curry_test_uri('repo1');
+
+test('/', 'a=project_index');
+test('/', 'a=opml');
+
+{
+    local *test = curry_test_uri('repos1', \&test);
+    local $TODO = 'FIXME';
 
 test('/', 'a=summary');
 test('/', 'a=heads');
@@ -224,10 +244,6 @@ test('/', 'a=rss;h=refs/heads/master');
 test('/', 'a=rss;h=refs/heads/master;opt=--no-merges');
 test('/', 'a=rss;opt=--no-merges');
 
-test('/', 'a=project_index');
-
-test('/', 'a=opml');
-
 test('/', 'a=blame;f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
 test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
 test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
@@ -238,5 +254,7 @@ test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=refs/he
 test('/', 'a=blame;f=file1;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
 test('/', 'a=blame;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
 
+}
+
 done_testing;