[Bps-public-commit] r11899 - in sd/trunk: bin t

jesse at bestpractical.com jesse at bestpractical.com
Fri Apr 25 16:03:52 EDT 2008


Author: jesse
Date: Fri Apr 25 16:03:51 2008
New Revision: 11899

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

Log:
* Actually validate status as you commit it now.

Modified: sd/trunk/bin/sd
==============================================================================
--- sd/trunk/bin/sd	(original)
+++ sd/trunk/bin/sd	Fri Apr 25 16:03:51 2008
@@ -1,7 +1,6 @@
 #!/usr/bin/perl 
 use warnings;
 use strict;
-use Carp::Always;
 
 $ENV{'PROPHET_REPLICA_TYPE'} ||= 'prophet';
 $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} || $ENV{'HOME'}.'/.svb';
@@ -13,7 +12,6 @@
 my $command = shift @ARGV;
 
 my $func = main->can('cmd_'.$command) || main->can('cmd_help');
-
 $func->();
 
 
@@ -35,6 +33,10 @@
 
 }
 
+sub cmd_details {
+    $CLI->do_show;
+    cmd_comments($CLI->uuid);
+}
 
 sub cmd_comments {
     my ($ticket) = @ARGV;
@@ -42,7 +44,7 @@
     $record->load( uuid => $ticket );
     print "id: " . $record->uuid . "\n";
     unless (@{$record->comments}) {
-        print "No commnets found\n";
+        print "No comments found\n";
     }
 
     for (@{$record->comments}) {
@@ -80,7 +82,6 @@
 
 }
 
-
 sub cmd_pull {
     my $url = shift @ARGV;
     local $ENV{PROPHET_RESOLVER} = 'Prompt';
@@ -91,6 +92,7 @@
         
 #         [ 'merge', '--prefer', 'to', '--from', repo_uri_for($from), '--to', repo_uri_for( $self->name ) ],
 }
+
 =begin comment
     # Trivial first pass:
     

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	Fri Apr 25 16:03:51 2008
@@ -1,5 +1,6 @@
 use warnings;
 use strict;
+
 package App::SD::Model::Ticket;
 use base qw/App::SD::Record/;
 
@@ -13,22 +14,19 @@
 
 
 
-sub validate_status {
+sub validate_prop_status {
     my ($self, %args) = @_;
+
+
     # XXX: validater not called when a value is unset, so can't do
     # mandatory check here
-    return 1 if scalar grep { $args{props}{status} eq $_ }
-        qw(new open closed stalled);
+    return 1 if scalar grep { $args{props}{status} eq $_ } qw(new open closed stalled);
 
-    $args{errors}{status} = 'hate';
+    $args{errors}{status} = "'".$args{props}->{status}."' is not a valid status";
     return 0;
 
 }
 
-#has many SVK::Model::Comment
-#has status
-#has owner
-
 __PACKAGE__->register_reference( comments => 'App::SD::Collection::Comment',
                                  by => 'ticket'
                                );

Added: sd/trunk/t/sd-validation.t
==============================================================================
--- (empty file)
+++ sd/trunk/t/sd-validation.t	Fri Apr 25 16:03:51 2008
@@ -0,0 +1,71 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Prophet::Test tests => 6;
+
+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"]
+);
+
+
+is_script_output( 'sd', [ 'ticket',  
+    '--update', '--uuid', $yatta_uuid, '--status', 'super'
+    ],
+   [undef],  # stdout
+    [qr/Validation error for 'status': 'super' is not a valid status/], # stderr
+    "Despite the magic power phrase of 'yatta', super is not a valid bug status"
+);
+
+run_output_matches( 'sd', [ 'ticket',  
+    '--list', '--regex', '.' ],
+    [ sort "$yatta_uuid YATTA new"]
+);
+
+
+is_script_output( 'sd', [ 'ticket',  
+    '--update', '--uuid', $yatta_uuid, '--status', 'stalled'
+    ],
+   [qr/ticket $yatta_uuid updated./], # stdout
+   [], # stderr
+   "Setting the status to stalled went ok"
+
+);
+
+run_output_matches( 'sd', [ 'ticket',  
+    '--list', '--regex', '.' ],
+    [ sort "$yatta_uuid YATTA stalled"]
+);
+
+
+my $sylar_uuid;
+is_script_output( 'sd', [ 'ticket',
+    '--create', '--summary', 'Sylar!', '--status', 'evil' ],
+    [undef],
+    [qr/Validation error for 'status': 'evil' is not a valid status/],
+    "Sylar can't create an eeevil ticket"
+);
+
+run_output_matches( 'sd', [ 'ticket',  
+    '--list', '--regex', '.' ],
+    [ sort "$yatta_uuid YATTA stalled"]
+);
+
+
+1;
+



More information about the Bps-public-commit mailing list