Added commit object serialization.
Dan Brook [Mon, 10 May 2010 21:57:55 +0000 (22:57 +0100)]
The syntax change for "with ..." is because of what seems to be a bug in
MooseX::Declare, see http://pastie.org/private/7btrsbgqkvgxxbub1aea.

lib/Gitalist/Git/Object.pm
lib/Gitalist/URIStructure/Ref.pm
t/json_view.t

index 33a4f75..78c5448 100644 (file)
@@ -1,10 +1,12 @@
 use MooseX::Declare;
 use Moose::Autobox;
 
-class Gitalist::Git::Object with Gitalist::Serializeable {
+class Gitalist::Git::Object {
     use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/;
     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
 
+    with 'Gitalist::Serializeable';
+
     # repository and sha1 are required initargs
     has repository => ( isa => 'Gitalist::Git::Repository',
                      required => 1,
@@ -35,8 +37,8 @@ class Gitalist::Git::Object with Gitalist::Serializeable {
                       required => 1,
                       is => 'ro',
                       lazy_build => 1,
-                      handles => [ 'content',
-                               ],
+                      handles => [ 'content' ],
+                      traits => [qw/ DoNotSerialize /],
                   );
 
     # objects can't determine their mode or filename
index da71487..2536dc5 100644 (file)
@@ -22,6 +22,7 @@ sub find : Chained('base') PathPart('') CaptureArgs(1) {
     # FIXME - Should not be here!
     $c->stash->{Commit} = $c->stash->{Repository}->get_object_or_head($sha1part)
         or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
+    $c->stash->{data} = $c->stash->{Commit};
 }
 
 sub diff : Chained('find') CaptureArgs(0) {}
index b4d683e..f275d59 100644 (file)
@@ -32,6 +32,28 @@ is_deeply $data, {
           'description' => 'some test repository'
         };
 
+$res = request(GET 'http://localhost/repo1/3f7567c7bdf7e7ebf410926493b92d398333116e/commit', 'Content-Type' => 'application/json');
+is $res->code, 200;
+$data = $j->decode($res->content);
+is ref($data), 'HASH';
+delete $data->{repository}{owner}
+  if $data && exists $data->{repository}{owner};
+is_deeply $data, {
+  'repository' => {
+    'is_bare' => 1,
+    '__CLASS__' => 'Gitalist::Git::Repository',
+    'last_change' => '2009-11-12T19:00:34Z',
+    'name' => 'repo1',
+    'description' => 'some test repository'
+  },
+  '__CLASS__' => 'Gitalist::Git::Object::Commit',
+  'sha1' => '3f7567c7bdf7e7ebf410926493b92d398333116e',
+  'mode' => 0,
+  'type' => 'commit',
+  'modestr' => '----------',
+  'size' => '218'
+};
+
 done_testing;