[Jifty-commit] r5229 - in jifty/trunk: lib/Jifty

Jifty commits jifty-commit at lists.jifty.org
Tue Mar 18 14:39:53 EDT 2008


Author: dpavlin
Date: Tue Mar 18 14:39:52 2008
New Revision: 5229

Added:
   jifty/trunk/t/TestApp/t/22-canonicalize-load_or_create.t
Modified:
   jifty/trunk/lib/Jifty/Record.pm

Log:
run canonicalization before load in load_or_create

Modified: jifty/trunk/lib/Jifty/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Record.pm	Tue Mar 18 14:39:52 2008
@@ -143,6 +143,13 @@
 
     my %args = (@_);
 
+    foreach my $key ( keys %args ) {
+        $args{$key} = $self->run_canonicalization_for_column(
+            column => $key,
+            value  => $args{$key}
+        );
+    }
+
     my ( $id, $msg ) = $self->load_by_cols(%args);
     unless ( $self->id ) {
         return $self->create(%args);

Added: jifty/trunk/t/TestApp/t/22-canonicalize-load_or_create.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/22-canonicalize-load_or_create.t	Tue Mar 18 14:39:52 2008
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+Test canonicalize on load_or_create
+
+=cut
+
+use lib 't/lib';
+use Jifty::SubTest;
+
+use Jifty::Test tests => 9;
+use_ok('TestApp::Model::CanonTest');
+
+# Grab a system use
+my $system_user = TestApp::CurrentUser->superuser;
+ok($system_user, "Found a system user");
+
+# Try testing a create
+my $o = TestApp::Model::CanonTest->new(current_user => $system_user);
+my ($id) = $o->create( column_1 => 'foo#$bar' );
+ok($id, "CanonTest create returned success");
+ok($o->id, "New CanonTest has valid id set");
+is($o->id, $id, "Create returned the right id");
+is($o->column_1, 'foobar', "Created object has the right column_1");
+
+# And another
+$o->load_or_create( column_1 => 'foo()bar' );
+ok($o->id, "CanonTest create returned value");
+is($o->id, $id, "And it is same from the previous one");
+
+# Searches in general
+my $collection =  TestApp::Model::CanonTestCollection->new(current_user => $system_user);
+$collection->unlimit;
+is($collection->count, 1, "Finds one records");
+


More information about the Jifty-commit mailing list