Made /blob & /blob_plain actions a little more robust.
Dan Brook [Sat, 21 Nov 2009 00:47:05 +0000 (00:47 +0000)]
Tidied up legacy tests.

lib/Gitalist/Controller/Root.pm
root/blob_plain.tt2 [deleted file]
root/nav/actions.tt2
t/03legacy_uri.t

index a14935a..12701c2 100644 (file)
@@ -167,13 +167,7 @@ sub blame : Local {
   
 }
 
-=head2 blob
-
-The blob action i.e the contents of a file.
-
-=cut
-
-sub blob : Local {
+sub _blob_objs {
   my ( $self, $c ) = @_;
   my $project = $c->stash->{Project};
   my $h  = $c->req->param('h')
@@ -185,9 +179,27 @@ sub blob : Local {
 
   my $filename = $c->req->param('f') || '';
 
+  my $blob = $project->get_object($h);
+  $blob = $project->get_object(
+    $project->hash_by_path($h || $hb, $filename)
+  ) if $blob->type ne 'blob';
+
+  return $blob, $project->get_object($hb), $filename;
+}
+
+=head2 blob
+
+The blob action i.e the contents of a file.
+
+=cut
+
+sub blob : Local {
+  my ( $self, $c ) = @_;
+
+  my($blob, $head, $filename) = $self->_blob_objs($c);
   $c->stash(
-    blob     => $project->get_object($h)->content,
-    head     => $project->get_object($hb),
+    blob     => $blob->content,
+    head     => $head,
     filename => $filename,
     # XXX Hack hack hack, see View::SyntaxHighlight
     language => ($filename =~ /\.p[lm]$/ ? 'Perl' : ''),
@@ -198,15 +210,27 @@ sub blob : Local {
     unless $c->stash->{no_wrapper};
 }
 
+=head2 blob_plain
+
+The plain text version of blob, where file is rendered as is.
+
+=cut
+
 sub blob_plain : Local {
   my($self, $c) = @_;
 
-  $c->stash(no_wrapper => 1);
+  my($blob) = $self->_blob_objs($c);
   $c->response->content_type('text/plain; charset=utf-8');
-
-  $c->forward('blob');
+  $c->response->body($blob->content);
+  $c->response->status(200);
 }
 
+=head2 blobdiff_plain
+
+The plain text version of blobdiff.
+
+=cut
+
 sub blobdiff_plain : Local {
   my($self, $c) = @_;
 
@@ -214,7 +238,6 @@ sub blobdiff_plain : Local {
   $c->response->content_type('text/plain; charset=utf-8');
 
   $c->forward('blobdiff');
-
 }
 
 =head2 blobdiff
diff --git a/root/blob_plain.tt2 b/root/blob_plain.tt2
deleted file mode 100644 (file)
index 592f8c5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-[% blob %]
index 81db1fb..dd51adf 100644 (file)
@@ -10,6 +10,7 @@
     [% IF filename %]
     §
     <a href="[% c.uri_for('blob', {h=object.sha1,f=filename}) %]">blob</a> &bull;
+    <a href="[% c.uri_for('blob_plain', {h=object.sha1,f=filename}) %]">raw</a> &bull;
     <a href="[% c.uri_for('blame', {h=object.sha1,f=filename}) %]">blame</a> &bull;
     <a href="[% c.uri_for('shortlog', {h=object.sha1,f=filename}) %]">history</a> &bull;
     <a href="[% c.uri_for(action, {f=filename}) %]">HEAD</a>
index a895bda..b638fde 100644 (file)
@@ -16,6 +16,7 @@ local *test = curry_test_uri('repo1');
 
 test('/', 'a=summary');
 test('/', 'a=heads');
+test('/', 'a=tags');
 
 test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
 test('/', 'a=blob;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD');
@@ -229,38 +230,22 @@ test('/', 'a=rss;h=refs/heads/master');
 test('/', 'a=rss;h=refs/heads/master;opt=--no-merges');
 test('/', 'a=rss;opt=--no-merges');
 
-TODO: {
-  local $TODO = 'The project_index action is yet to be implemented';
-  test('/', 'a=project_index');
-}
+test('/', 'a=project_index');
+
 TODO: {
   local $TODO = 'The opml action is yet to be implemented';
   test('/', 'a=opml');
 }
-TODO: {
-  local $TODO = 'The tags action is yet to be implemented';
-  test('/', 'a=tags');
-}
-TODO: {
-  local $TODO = 'The blame action is yet to be implemented';
 
-  test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
-  test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=HEAD');
-  test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=master');
-  test('/', 'a=blame;f=dir1/file2;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=refs/heads/master');
-  test('/', 'a=blame;f=dir1/file2;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
-  test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99');
-  test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=257cc5642cb1a054f08cc83f2d943e56fd3ebe99');
-  test('/', 'a=blame;f=file1;h=257cc5642cb1a054f08cc83f2d943e56fd3ebe99;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
-  test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
-  test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
-  test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=5716ca5987cbf97d6bb54920bea6adde242d87e6');
-  test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=HEAD');
-  test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=master');
-  test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=refs/heads/master');
-  test('/', 'a=blame;f=file1;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
-  test('/', 'a=blame;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
-}
+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');
+test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
+test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=HEAD');
+test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=master');
+test('/', 'a=blame;f=file1;h=5716ca5987cbf97d6bb54920bea6adde242d87e6;hb=refs/heads/master');
+test('/', 'a=blame;f=file1;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
+test('/', 'a=blame;f=file1;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
 
 done_testing;