[Bps-public-commit] r11432 - in SVN-PropDB: bin t

clkao at bestpractical.com clkao at bestpractical.com
Thu Apr 3 05:59:40 EDT 2008


Author: clkao
Date: Thu Apr  3 05:59:40 2008
New Revision: 11432

Modified:
   SVN-PropDB/bin/sd
   SVN-PropDB/lib/Prophet/CLI.pm
   SVN-PropDB/lib/Prophet/Record.pm
   SVN-PropDB/t/validate.t

Log:
make validation throw exception.

Modified: SVN-PropDB/bin/sd
==============================================================================
--- SVN-PropDB/bin/sd	(original)
+++ SVN-PropDB/bin/sd	Thu Apr  3 05:59:40 2008
@@ -21,6 +21,17 @@
 
 use constant record_type => 'ticket';
 
+sub validate_status {
+    my ($self, %args) = @_;
+
+    return 1 if scalar grep { $args{props}{status} eq $_ }
+        qw(new open closed stalled);
+
+    $args{errors}{status} = 'hate';
+    return 0;
+
+    
+}
 
 #has many SVK::Model::Comment
 #has status

Modified: SVN-PropDB/lib/Prophet/CLI.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/CLI.pm	(original)
+++ SVN-PropDB/lib/Prophet/CLI.pm	Thu Apr  3 05:59:40 2008
@@ -160,7 +160,9 @@
 sub do_create {
     my $cli = shift;
     my $record = $cli->_get_record;
-    my ( $id, $results ) = $record->create( props => $cli->args );
+
+    $record->create( props => $cli->args );
+
     print "Created " . $record->record_type . " " . $record->uuid . "\n";
 
 }

Modified: SVN-PropDB/lib/Prophet/Record.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Record.pm	(original)
+++ SVN-PropDB/lib/Prophet/Record.pm	Thu Apr  3 05:59:40 2008
@@ -59,11 +59,16 @@
     my %args = validate( @_, { props => 1 } );
     my $uuid = $UUIDGEN->create_str;
 
+    $self->_canonicalize_props( $args{'props'} );
+    $self->_validate_props( $args{'props'} ) or return undef;
+
     $self->uuid($uuid);
 
-    $self->_canonicalize_props( $args{'props'} );
-    $self->_validate_props( $args{'props'} ) || return undef;
-    $self->handle->create_node( props => $args{'props'}, uuid => $self->uuid, type => $self->type );
+    $self->handle->create_node(
+        props => $args{'props'},
+        uuid  => $self->uuid,
+        type  => $self->type );
+
     return $self->uuid;
 }
 
@@ -112,7 +117,7 @@
     my %args = validate( @_, { props => 1 } );
 
     $self->_canonicalize_props( $args{'props'} );
-    $self->_validate_props( $args{'props'} ) || return undef;
+    $self->_validate_props( $args{'props'} );
     $self->handle->set_node_props( type => $self->type, uuid => $self->uuid, props => $args{'props'} );
 }
 
@@ -175,7 +180,7 @@
     for my $key ( keys %$props ) {
         return undef unless ( $self->_validate_prop_name($key) );
         if ( my $sub = $self->can( 'validate_' . $key ) ) {
-            $sub->( $self, props => $props, errors => $errors ) || return undef;
+            $sub->( $self, props => $props, errors => $errors ) or die "validation error on $key: $errors->{$key}\n";
         }
     }
     return 1;

Modified: SVN-PropDB/t/validate.t
==============================================================================
--- SVN-PropDB/t/validate.t	(original)
+++ SVN-PropDB/t/validate.t	Thu Apr  3 05:59:40 2008
@@ -3,6 +3,7 @@
 use Test::More 'no_plan';
 use File::Temp qw'tempdir';
 use lib 't/lib';
+use Test::Exception;
 
 use_ok('Prophet::Handle');
 my $REPO = tempdir( CLEANUP => 0 ) . '/repo-' . $$;
@@ -21,5 +22,6 @@
 my $uuid = $record->create( props => { name => 'Jesse', age => 31 } );
 ok($uuid);
 
-my $kuuid = $record->create( props => { name => 'Bob', age => 31 } );
-ok( !$kuuid );
+throws_ok {
+    $record->create( props => { name => 'Bob', age => 31 } );
+} qr/validation error/;



More information about the Bps-public-commit mailing list