[Jifty-commit] r3552 - 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:40 EDT 2007
Author: sterling
Date: Tue Jun 26 09:14:39 2007
New Revision: 3552
Added:
apps/CASPlus/trunk/t/40-is_mine.t
Modified:
apps/CASPlus/trunk/ (props changed)
apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm
Log:
r7644 at dynpc145: andrew | 2007-06-14 23:30:02 -0500
Added record_class to Profile and added a test for is_mine.
Modified: apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm
==============================================================================
--- apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm (original)
+++ apps/CASPlus/trunk/lib/CASPlus/Model/Profile.pm Tue Jun 26 09:14:39 2007
@@ -252,6 +252,28 @@
return $self->SUPER::current_user_can($right, %args);
}
+=head2 record_class
+
+ my $instance_class = $profile->record_class;
+
+This is a shortcut for:
+
+ my $instance_class = $profile->model_class->qualified_class;
+
+This allows the user to perform actions such as:
+
+ my $instance = $profile->record_class->new;
+ $instance->load($id);
+
+This is a little cleaner (IMO) than the alternative.
+
+=cut
+
+sub record_class {
+ my $self = shift;
+ return $self->model_class->qualified_class;
+}
+
=head1 AUTHOR
Andrew Sterling Hanenkamp C<<hanenkamp at cpan.org>>
Added: apps/CASPlus/trunk/t/40-is_mine.t
==============================================================================
--- (empty file)
+++ apps/CASPlus/trunk/t/40-is_mine.t Tue Jun 26 09:14:39 2007
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Jifty::Test tests => 5;
+
+# Grab a system user
+my $system_user = CASPlus::CurrentUser->superuser;
+ok($system_user, 'Found a system user');
+
+# Create a profile to test with
+my $profile = CASPlus::Model::Profile->new(current_user => $system_user);
+$profile->create(
+ name => 'Employee',
+ profile_type => 'user',
+);
+ok($profile->id, 'Created an employee profile');
+
+# Create a test user
+my $user = CASPlus::Model::User->new(current_user => $system_user);
+$user->create(
+ username => 'test123',
+ password => 'test123',
+);
+ok($user->id, 'Created a user');
+
+# Create a test employee
+my $employee = $profile->record_class->new(current_user => $system_user);
+$employee->create(
+ user_object => $user,
+);
+my $employee_id = $employee->id;
+ok($employee->id, 'created an employee to test with');
+
+# Set the user object as current
+Jifty->web->current_user($user);
+
+# Reload the employee
+$employee = $profile->record_class->new;
+$employee->load($employee_id);
+
+# It must be mine!
+ok($employee->is_mine, 'employee is_mine');
More information about the Jifty-commit
mailing list