[Jifty-commit] r7310 - in jifty/trunk: t

Jifty commits jifty-commit at lists.jifty.org
Mon Jul 13 00:23:35 EDT 2009


Author: c9s
Date: Mon Jul 13 00:23:35 2009
New Revision: 7310

Modified:
   jifty/trunk/lib/Jifty/Model/SessionCollection.pm
   jifty/trunk/t/13-sessions.t

Log:
add expired_update/create helper method to session collection. add tests on these methods

Modified: jifty/trunk/lib/Jifty/Model/SessionCollection.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Model/SessionCollection.pm	(original)
+++ jifty/trunk/lib/Jifty/Model/SessionCollection.pm	Mon Jul 13 00:23:35 2009
@@ -31,4 +31,26 @@
 
 sub current_user { return Jifty->app_class('CurrentUser')->superuser }
 
+=head2 expired_update
+
+find sessions where updated time is expired.
+
+=cut
+
+sub expired_update { 
+    my ($self,$dt) = @_;
+    $self->limit( column => 'updated', operator => '<', value => $dt );
+}
+
+=head2 expired_create 
+
+find sessions where created time is expired.
+
+=cut
+
+sub expired_create {
+    my ($self,$dt) = @_;
+    $self->limit( column => 'created', operator => '<', value => $dt, );
+}
+
 1;

Modified: jifty/trunk/t/13-sessions.t
==============================================================================
--- jifty/trunk/t/13-sessions.t	(original)
+++ jifty/trunk/t/13-sessions.t	Mon Jul 13 00:23:35 2009
@@ -7,7 +7,25 @@
 
 =cut
 
-use Jifty::Test tests => 19;
+use Jifty::Test tests => 21;
+
+{
+    my $session = Jifty::Model::Session->new;
+    $session->create(
+        data_key => 'old',
+        value    => 'one',
+    );
+    $session->set_created( DateTime->now->subtract( days => 14 ) );
+    $session->set_updated( DateTime->now->subtract( days => 14 ) );
+
+    my $collection = Jifty::Model::SessionCollection->new;
+    $collection->expired_update( DateTime->now->subtract( days => 2 ) );
+    is($collection->first->value,'one');
+
+    $collection->unlimit;
+    $collection->expired_create( DateTime->now->subtract( days => 2 ) );
+    is($collection->first->value,'one');
+}
 
 my ($first_id, $third_id);
 


More information about the Jifty-commit mailing list