Skip to content

Commit

Permalink
Added commit object serialization.
Browse files Browse the repository at this point in the history
The syntax change for "with ..." is because of what seems to be a bug in
MooseX::Declare, see http://pastie.org/private/7btrsbgqkvgxxbub1aea.
  • Loading branch information
Dan Brook committed Aug 1, 2010
1 parent 4dacb4b commit 53bb75d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Gitalist/Git/Object.pm
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/Gitalist/URIStructure/Ref.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
22 changes: 22 additions & 0 deletions t/json_view.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;


0 comments on commit 53bb75d

Please sign in to comment.