[Rt-commit] r19959 - in rt/3.999/trunk: lib/RT/Lorzy/Package

clkao at bestpractical.com clkao at bestpractical.com
Wed Jun 10 07:44:50 EDT 2009


Author: clkao
Date: Wed Jun 10 07:44:49 2009
New Revision: 19959

Added:
   rt/3.999/trunk/t/lorzy/condition-lambda.t
Modified:
   rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm

Log:
Make Condition.PriorityExceeds take priority and returns a lambda.
Test for applying (dynamic) lambda from rules.


Modified: rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm	(original)
+++ rt/3.999/trunk/lib/RT/Lorzy/Package/RT.pm	Wed Jun 10 07:44:49 2009
@@ -114,10 +114,16 @@
 );
 
 __PACKAGE__->defun( 'Condition.PriorityExceeds', # XXX: lambday required, doesn't work yet
-    signature => $sig_ticket_txn,
+    signature => { 'priority' => Lorzy::FunctionArgument->new( name => 'priority', type => 'Int' ),
+               },
     native => sub {
-        my $args = shift;
-        return $args->{ticket}->priority > $args->{argument};
+        my $xargs = shift;
+        return Lorzy::Lambda::Native->new
+            ( body => sub {
+                  my $args = shift;
+                  $args->{ticket}->priority > $xargs->{priority};
+              },
+              signature => $sig_ticket_txn );
     },
 );
 

Added: rt/3.999/trunk/t/lorzy/condition-lambda.t
==============================================================================
--- (empty file)
+++ rt/3.999/trunk/t/lorzy/condition-lambda.t	Wed Jun 10 07:44:49 2009
@@ -0,0 +1,65 @@
+use Test::More tests => 6;
+use RT::Test;
+
+use strict;
+use warnings;
+
+use RT::Model::Queue;
+use RT::Model::User;
+use RT::Model::Group;
+use RT::Model::Ticket;
+use RT::Model::ACE;
+use RT::CurrentUser;
+use Test::Exception;
+
+use_ok('Lorzy');
+
+my $eval = Lorzy::Evaluator->new();
+$eval->load_package($_) for qw(Str Native);
+$eval->load_package('RT', 'RT::Lorzy::Package::RT');
+
+my $priority10 = { name => 'RT.Condition.PriorityExceeds',
+                   args => {
+                       priority => 10
+                   }
+               };
+
+my $tree    = [ { name => 'Apply',
+                  args => {
+                      lambda => $priority10,
+                      apply_args =>
+                      { ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+                        transaction => { name => 'Symbol', args => { symbol => 'transaction' }} },
+                  }
+              } ];
+
+my $builder = Lorzy::Builder->new();
+my $important  = $builder->defun(
+    ops => $tree,
+    signature =>
+        { ticket => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+          transaction => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ) }
+);
+
+my $queue = RT::Model::Queue->new(current_user => RT->system_user);
+my ($queue_id) = $queue->create( name =>  'lorzy');
+ok( $queue_id, 'queue created' );
+
+my $ticket = RT::Model::Ticket->new(current_user => RT->system_user );
+my ($rv, $msg) = $ticket->create( subject => 'watcher tests', queue => $queue->name );
+
+my $txn = $ticket->transactions->first;
+
+my $ret;
+lives_ok {
+    $ret = $eval->apply_script( $important, { 'ticket' => $ticket, transaction => $txn } );
+};
+ok(!$ret);
+
+$ticket->set_priority('11');
+
+lives_ok {
+    $ret = $eval->apply_script( $important, { 'ticket' => $ticket, transaction => $ticket->transactions->last } );
+};
+ok($ret);
+


More information about the Rt-commit mailing list