[Jifty-commit] r3554 - in apps/CASPlus/trunk: lib/CASPlus/Model t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Tue Jun 26 09:14:51 EDT 2007


Author: sterling
Date: Tue Jun 26 09:14:51 2007
New Revision: 3554

Added:
   apps/CASPlus/trunk/lib/CASPlus/Model/UniqueProfileIdentifier.pm
   apps/CASPlus/trunk/t/10-model-UniqueProfileIdentifier.t
Modified:
   apps/CASPlus/trunk/   (props changed)

Log:
 r7647 at dynpc145:  andrew | 2007-06-15 22:54:33 -0500
 Added the UniqueProfileIdentifier model for assigning every profile object a unique ID.


Added: apps/CASPlus/trunk/lib/CASPlus/Model/UniqueProfileIdentifier.pm
==============================================================================
--- (empty file)
+++ apps/CASPlus/trunk/lib/CASPlus/Model/UniqueProfileIdentifier.pm	Tue Jun 26 09:14:51 2007
@@ -0,0 +1,46 @@
+use strict;
+use warnings;
+
+package CASPlus::Model::UniqueProfileIdentifier;
+use Jifty::DBI::Schema;
+
+use constant CLASS_UUID => 'F0253FE2-1BBA-11DC-B511-87ADE687E20F';
+
+=head1 NAME
+
+CASPlus::Model::UniqueProfileIdentifier - Assign every profile a unique ID
+
+=head1 DESCRIPTION
+
+This class is used internally to give every profile object a unique identifier.
+
+=cut
+
+use CASPlus::Record schema {
+    column profile =>
+        refers_to CASPlus::Model::Profile,
+        is mandatory,
+        is immutable;
+
+    column object_id =>
+        type is 'int',
+        is mandatory,
+        is immutable;
+};
+
+=head2 WHY?
+
+Every profile object is assigned a unique identifier primarily to aid in role caching.
+
+=head1 AUTHOR
+
+Andrew Sterling Hanenkamp C<< <andrew.hanenkamp at boomer.com> >>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 Boomer Consulting, Inc. This program is free software and may be modified and distributed under the same terms as Perl itself.
+
+=cut
+
+1;
+

Added: apps/CASPlus/trunk/t/10-model-UniqueProfileIdentifier.t
==============================================================================
--- (empty file)
+++ apps/CASPlus/trunk/t/10-model-UniqueProfileIdentifier.t	Tue Jun 26 09:14:51 2007
@@ -0,0 +1,63 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+A basic test harness for the UniqueProfileIdentifier model.
+
+=cut
+
+use Jifty::Test tests => 11;
+
+# Make sure we can load the model
+use_ok('CASPlus::Model::UniqueProfileIdentifier');
+
+# Grab a system user
+my $system_user = CASPlus::CurrentUser->superuser;
+ok($system_user, "Found a system user");
+
+# Create a test profile
+my $profile = CASPlus::Model::Profile->new(current_user => $system_user);
+$profile->create(
+    name         => 'Employee',
+    profile_type => 'user',
+);
+ok($profile->id, 'Created a test profile');
+
+# Try testing a create
+my $o = CASPlus::Model::UniqueProfileIdentifier->new(current_user => $system_user);
+my ($id) = $o->create(
+    profile   => $profile,
+    object_id => 1,
+);
+ok($id, "UniqueProfileIdentifier create returned success");
+ok($o->id, "New UniqueProfileIdentifier has valid id set");
+is($o->id, $id, "Create returned the right id");
+
+# And another
+$o->create(
+    profile   => $profile,
+    object_id => 2,
+);
+ok($o->id, "UniqueProfileIdentifier create returned another value");
+isnt($o->id, $id, "And it is different from the previous one");
+
+# Searches in general
+my $collection =  CASPlus::Model::UniqueProfileIdentifierCollection->new(current_user => $system_user);
+$collection->unlimit;
+is($collection->count, 2, "Finds two records");
+
+# Searches in specific
+$collection->limit(column => 'id', value => $o->id);
+is($collection->count, 1, "Finds one record with specific id");
+
+# Delete one of them
+$o->delete;
+$collection->redo_search;
+is($collection->count, 0, "Deleted row is gone");
+
+# And the other one is still there
+$collection->unlimit;
+is($collection->count, 1, "Still one left");
+


More information about the Jifty-commit mailing list