[Bps-public-commit] r11971 - in sd/trunk: bin lib/App/SD/Collection t

jesse at bestpractical.com jesse at bestpractical.com
Tue Apr 29 19:39:52 EDT 2008


Author: jesse
Date: Tue Apr 29 19:39:51 2008
New Revision: 11971

Added:
   sd/trunk/lib/App/SD/Collection/Attachment.pm
   sd/trunk/lib/App/SD/Model/Attachment.pm
   sd/trunk/t/sd-comments.t
Modified:
   sd/trunk/bin/sd
   sd/trunk/lib/App/SD/Collection/Ticket.pm
   sd/trunk/lib/App/SD/Model/Ticket.pm

Log:
* Create/Update/List comments now works

Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd	(original)
+++ sd/trunk/bin/sd	Tue Apr 29 19:39:51 2008
@@ -2,10 +2,10 @@
 use warnings;
 use strict;
 
-$ENV{'PROPHET_REPLICA_TYPE'} ||= 'prophet';
-$ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} || $ENV{'HOME'}.'/.svb';
+$ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} || $ENV{'HOME'}.'/.sd';
 
 use Prophet::CLI;
+use App::SD::Model::Ticket;
 my $cli = Prophet::CLI->new( { app_class => 'App::SD' } );
 $cli->run_one_command;
 
@@ -15,6 +15,19 @@
 package App::SD::CLI::Command;
 use base qw/Prophet::CLI::Command/;
 
+package App::SD::CLI::Command::Ticket::Comment;
+use base qw/App::SD::CLI::Command/;
+
+use constant record_class => 'App::SD::Model::Comment';
+
+package App::SD::CLI::Command::Ticket::Comment::Create;
+use base qw/App::SD::CLI::Command::Ticket::Comment Prophet::CLI::Command::Create/;
+
+# override args to feed in that ticket's uuid as an argument to the comment
+sub args {
+    my $self = shift;
+    return { %{$self->SUPER::args}, ticket => $self->uuid};
+}
 
 
 package App::SD::CLI::Command::Help;
@@ -39,34 +52,46 @@
 }
 
 
+package App::SD::CLI::Command::Ticket::Show;
+use base qw/App::SD::CLI::Command Prophet::CLI::Command::Show/;
+
+
+
+
+
 package App::SD::CLI::Command::Details;
 use base qw/App::SD::CLI::Command/;
 sub run {
-    App::SD::Command::Ticket::Show->run();
-    App::SD::Command::Comments->run();
+    my $self = shift;
+    print "\n=head1 METADATA\n\n"; 
+    $self->App::SD::CLI::Command::Ticket::Show::run();
+    print "\n=head1 COMMENTS\n\n";
+    $self->App::SD::CLI::Command::Ticket::Comments::run();
 }
 
-package App::SD::CLI::Command::Comments;
+package App::SD::CLI::Command::Ticket;
 use base qw/App::SD::CLI::Command/;
+
+use constant record_class => 'App::SD::Model::Ticket';
+
+package App::SD::CLI::Command::Ticket::Comments;
+use base qw/App::SD::CLI::Command::Ticket/;
+
 sub run {
     my $self = shift;
-    my ($ticket) = $self->args->{'uuid'};
-    my $record = App::SD::Model::Ticket->new( { handle => $self->app_handle->handle } );
-    $record->load( uuid => $ticket );
-    print "id: " . $record->uuid . "\n";
+    my $record = $self->_get_record();
+    $record->load( uuid => $self->cli->uuid );
     unless (@{$record->comments}) {
         print "No comments found\n";
     }
 
     for (@{$record->comments}) {
         print "comment id: ".$_->uuid."\n";
-        print "Content:\n".$_->prop('content');
-        print "\n\n";
+        print "Content:\n".$_->prop('content')."\n";
     }
 
 }
 
-
 package App::SD::CLI::Command::Merge;
 use base qw/App::SD::CLI::Command Prophet::CLI::Command::Merge/;
 

Added: sd/trunk/lib/App/SD/Collection/Attachment.pm
==============================================================================
--- (empty file)
+++ sd/trunk/lib/App/SD/Collection/Attachment.pm	Tue Apr 29 19:39:51 2008
@@ -0,0 +1,10 @@
+use warnings;
+use strict;
+package App::SD::Collection::Attachment;
+use base 'Prophet::Collection';
+
+use constant record_class => 'App::SD::Model::Attachment';
+
+
+1;
+

Modified: sd/trunk/lib/App/SD/Collection/Ticket.pm
==============================================================================
--- sd/trunk/lib/App/SD/Collection/Ticket.pm	(original)
+++ sd/trunk/lib/App/SD/Collection/Ticket.pm	Tue Apr 29 19:39:51 2008
@@ -5,8 +5,6 @@
 package App::SD::Collection::Ticket;
 use base 'Prophet::Collection';
 
-
-
 use constant record_class => 'App::SD::Model::Ticket';
 
 1;

Added: sd/trunk/lib/App/SD/Model/Attachment.pm
==============================================================================
--- (empty file)
+++ sd/trunk/lib/App/SD/Model/Attachment.pm	Tue Apr 29 19:39:51 2008
@@ -0,0 +1,15 @@
+use warnings;
+use strict;
+
+package App::SD::Model::Attachment;
+use base qw/App::SD::Record/;
+
+use constant collection_class => 'App::SD::Collection::Attachment';
+use constant record_type => 'attachment';
+
+use constant summary_format => '%u %s';
+use constant summary_props => qw(filename);
+
+__PACKAGE__->register_reference( ticket => 'App::SD::Model::Ticket');
+
+1;

Modified: sd/trunk/lib/App/SD/Model/Ticket.pm
==============================================================================
--- sd/trunk/lib/App/SD/Model/Ticket.pm	(original)
+++ sd/trunk/lib/App/SD/Model/Ticket.pm	Tue Apr 29 19:39:51 2008
@@ -11,9 +11,6 @@
 use constant summary_format => '%u %s %s';
 use constant summary_props => qw(summary status);
 
-
-
-
 sub validate_prop_status {
     my ($self, %args) = @_;
 
@@ -27,8 +24,7 @@
 
 }
 
-__PACKAGE__->register_reference( comments => 'App::SD::Collection::Comment',
-                                 by => 'ticket'
-                               );
+__PACKAGE__->register_reference( comments => 'App::SD::Collection::Comment', by => 'ticket');
+__PACKAGE__->register_reference( attachments => 'App::SD::Collection::Attachment', by => 'ticket');
 
 1;

Added: sd/trunk/t/sd-comments.t
==============================================================================
--- (empty file)
+++ sd/trunk/t/sd-comments.t	Tue Apr 29 19:39:51 2008
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Prophet::Test tests => 9;
+
+no warnings 'once';
+
+BEGIN {
+    require File::Temp;
+    $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = File::Temp::tempdir( CLEANUP => 0 ) . '/_svb';
+    warn $ENV{'PROPHET_REPO'};
+}
+# create from sd and push
+my $yatta_uuid;
+run_output_matches( 'sd', [ 'ticket',
+    'create', '--summary', 'YATTA', '--status', 'new' ],
+    [qr/Created ticket (.*)(?{ $yatta_uuid = $1 })/]
+);
+
+run_output_matches( 'sd', [ 'ticket',  
+    'list', '--regex', '.' ],
+    [ sort "$yatta_uuid YATTA new"]
+);
+
+my $comment_uuid;
+run_output_matches('sd', [qw/ticket comment create --uuid/, $yatta_uuid, '--content', "'This is a test'"], [qr/Created comment (.*?)(?{ $comment_uuid = $1})$/], [], "Added a comment");
+ok($comment_uuid);
+
+run_output_matches('sd', [qw/ticket comments --uuid/, $yatta_uuid], [qr/^comment id: $comment_uuid/,'Content:',"'This is a test'"], [], "Found the comment");
+
+run_output_matches('sd', [qw/ticket comment show --uuid/, $comment_uuid], ["id: $comment_uuid", qr/This is a test/, "ticket: $yatta_uuid"], [], "Found the comment");
+run_output_matches('sd', [qw/ticket comment update --uuid/, $comment_uuid, qw/--content/, "I hate you" ], [qr/comment $comment_uuid updated/], [], "updated the comment");
+run_output_matches('sd', [qw/ticket comment show --uuid/, $comment_uuid], ["id: $comment_uuid", qr/I hate you/, "ticket: $yatta_uuid"], [], "Found the comment new version");
+
+run_output_matches('sd', [qw/ticket comment list --uuid/, $yatta_uuid], [qr/$comment_uuid/], [], "Found the comment when we tried to search for all comments on a ticket by the ticket's uuid");



More information about the Bps-public-commit mailing list