[Jifty-commit] r2894 - in jifty/branches/template-declare: . t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat Mar 3 12:56:38 EST 2007


Author: jesse
Date: Sat Mar  3 12:56:38 2007
New Revision: 2894

Modified:
   jifty/branches/template-declare/   (props changed)
   jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FasterSwallow.pm
   jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FavoriteColor.pm
   jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t

Log:
 r52953 at pinglin:  jesse | 2007-03-03 17:54:26 +0000
 * Testing canonicalizers, validators AND pre-create hooks, now


Modified: jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FasterSwallow.pm
==============================================================================
--- jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FasterSwallow.pm	(original)
+++ jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FasterSwallow.pm	Sat Mar  3 12:56:38 2007
@@ -11,7 +11,6 @@
 
 sub register_triggers {
     my $self = shift;
-    warn "Adding a trigger for $self";
     $self->add_trigger(name => 'before_create', callback => \&before_create, abortable => 1);
 }
 

Modified: jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FavoriteColor.pm
==============================================================================
--- jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FavoriteColor.pm	(original)
+++ jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/lib/TestApp/Plugin/FavoriteColor.pm	Sat Mar  3 12:56:38 2007
@@ -12,15 +12,26 @@
 
 sub register_triggers {
     my $self = shift;
-    $self->add_trigger(name => 'before_create', callback => \&before_create, abortable => 1);
+    $self->add_trigger(name => 'validate_color', callback => \&validate_color, abortable => 1);
+    $self->add_trigger(name => 'canonicalize_color', callback => \&canonicalize_color, abortable => 0);
 }
 
 
+sub canonicalize_color {
+    my $self = shift;
+    my $color = shift;
+
+    if ($color eq 'grey') {
+        return 'gray';
+    }
+    return $color;
+
+}
 
-sub before_create {
+sub validate_color {
     my $self = shift;
-    my $args = shift;
-    return undef unless ($args->{'color'} eq 'yellow');
+    my $arg = shift;
+    return undef unless ($arg eq 'gray');
     return 1;
 }
 

Modified: jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t
==============================================================================
--- jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t	(original)
+++ jifty/branches/template-declare/t/TestApp-Plugin-PasswordAuth/t/00-model-User.t	Sat Mar  3 12:56:38 2007
@@ -10,7 +10,7 @@
 use lib 't/lib';
 use Jifty::SubTest;
 
-use Jifty::Test tests => 14;
+use Jifty::Test tests => 15;
 
 # Make sure we can load the model
 use_ok('TestApp::Plugin::PasswordAuth::Model::User');
@@ -23,7 +23,7 @@
 my $o = TestApp::Plugin::PasswordAuth::Model::User->new(current_user => $system_user);
 my ($id) = $o->create( name => 'jesse',
                        username => 'jrv',
-                       color => 'yellow',
+                       color => 'gray',
                        swallow_type => 'african',
                        password => 'secret');
 ok($id, "User create returned success");
@@ -36,7 +36,7 @@
 ok(!$o->password, "Can't get the password");
 can_ok($o,'set_password');
 ok($o->password_is( 'secret'));
-is($o->color, 'yellow');
+is($o->color, 'gray');
 is ($o->swallow_type, 'african');
 
 
@@ -51,7 +51,16 @@
 my $q = TestApp::Plugin::PasswordAuth::Model::User->new(current_user => $system_user);
 ($id) = $p->create( name => 'jesse2',
                        username => 'jrv2',
-                       color => 'yellow',
+                       color => 'gray',
                        swallow_type => 'european',
                        password => 'secret');
 ok(!$id, "Users can't be created if they don't know african swallow_types are faster");
+
+my $r = TestApp::Plugin::PasswordAuth::Model::User->new(current_user => $system_user);
+ ($id) = $r->create( name => 'jesse2',
+                       username => 'jrv2',
+                       color => 'grey',
+                       swallow_type => 'african',
+                       password => 'secret');
+ok($id, "Created with grey");
+


More information about the Jifty-commit mailing list