[Rt-commit] r4462 - in rt/branches/3.5-TESTING: . html/Admin/Elements lib/RT

kevinr at bestpractical.com kevinr at bestpractical.com
Wed Feb 1 22:27:12 EST 2006


Author: kevinr
Date: Wed Feb  1 22:27:10 2006
New Revision: 4462

Added:
   rt/branches/3.5-TESTING/lib/t/regression/25scrip_order.t
Modified:
   rt/branches/3.5-TESTING/   (props changed)
   rt/branches/3.5-TESTING/html/Admin/Elements/EditScrips
   rt/branches/3.5-TESTING/lib/RT/Scrips_Overlay.pm

Log:
 r10739 at RANDOM-ONE-NINETY-THREE:  kevinr | 2006-02-01 22:26:27 -0500
 RT-Ticket: 7295
 RT-Status: resolved
 RT-Update: correspond
 
 We now order scrips by their description, so you can force them to run in a
 particular order by prepending numbers to their descriptions.  Updated the
 perldoc and EditScrips UI element to reflect this and wrote tests for it.


Modified: rt/branches/3.5-TESTING/html/Admin/Elements/EditScrips
==============================================================================
--- rt/branches/3.5-TESTING/html/Admin/Elements/EditScrips	(original)
+++ rt/branches/3.5-TESTING/html/Admin/Elements/EditScrips	Wed Feb  1 22:27:10 2006
@@ -74,6 +74,7 @@
 	Caption => loc("Delete selected scrips"), 
 	Label => loc("Delete") &>
 </form>
+
 <%init>
 my (@actions);
 
@@ -92,6 +93,7 @@
         $Scrips->LimitToGlobal();
 }                                           
 
+$Scrips->OrderBy( FIELD => 'description' );
 
 
 

Modified: rt/branches/3.5-TESTING/lib/RT/Scrips_Overlay.pm
==============================================================================
--- rt/branches/3.5-TESTING/lib/RT/Scrips_Overlay.pm	(original)
+++ rt/branches/3.5-TESTING/lib/RT/Scrips_Overlay.pm	Wed Feb  1 22:27:10 2006
@@ -157,7 +157,9 @@
 
 =head2 Apply
 
-Run through the relevant scrips. 
+Run through the relevant scrips.  Scrips will run in order based on 
+description.  (Most common use case is to prepend a number to the description,
+forcing the scrips to run in ascending alphanumerical order.)
 
 =cut
 
@@ -304,7 +306,10 @@
 
 =head2 _FindScrips
 
-Find only the apropriate scrips for whatever we're doing now
+Find only the apropriate scrips for whatever we're doing now.  Order them 
+by their description.  (Most common use case is to prepend a number to the
+description, forcing the scrips to display and run in ascending alphanumerical 
+order.)
 
 =cut
 
@@ -353,6 +358,9 @@
         ENTRYAGGREGATOR => 'OR',
     );
 
+    # Promise some kind of ordering
+    $self->OrderBy( FIELD => 'description' );
+
     $RT::Logger->debug("Found ".$self->Count. " scrips");
 }
 

Added: rt/branches/3.5-TESTING/lib/t/regression/25scrip_order.t
==============================================================================
--- (empty file)
+++ rt/branches/3.5-TESTING/lib/t/regression/25scrip_order.t	Wed Feb  1 22:27:10 2006
@@ -0,0 +1,57 @@
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More qw/no_plan/;
+
+use RT;
+RT::LoadConfig();
+RT::Init;
+
+# {{{ test scrip ordering based on description
+
+my $scrip_queue = RT::Queue->new($RT::SystemUser);
+my ($queue_id, $msg) = $scrip_queue->Create( Name => "ScripOrdering-$$", 
+    Description => 'Test scrip ordering by description' );
+ok($queue_id, "Created scrip-ordering test queue? ".$msg);
+
+my $priority_ten_scrip = RT::Scrip->new($RT::SystemUser);
+(my $id, $msg) = $priority_ten_scrip->Create( 
+    Description => "10 set priority $$",
+    Queue => $queue_id, 
+    ScripCondition => 'On Create',
+    ScripAction => 'User Defined', 
+    CustomPrepareCode => '$RT::Logger->debug("Setting priority to 10..."); return 1;',
+    CustomCommitCode => '$self->TicketObj->SetPriority(10);',
+    Template => 'Blank',
+    Stage => 'TransactionCreate',
+);
+ok($id, "Created priority-10 scrip? ".$msg);
+
+my $priority_five_scrip = RT::Scrip->new($RT::SystemUser);
+($id, $msg) = $priority_ten_scrip->Create( 
+    Description => "05 set priority $$",
+    Queue => $queue_id, 
+    ScripCondition => 'On Create',
+    ScripAction => 'User Defined', 
+    CustomPrepareCode => '$RT::Logger->debug("Setting priority to 5..."); return 1;',
+    CustomCommitCode => '$self->TicketObj->SetPriority(5);', 
+    Template => 'Blank',
+    Stage => 'TransactionCreate',
+);
+ok($id, "Created priority-5 scrip? ".$msg);
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+($id, $msg) = $ticket->Create( 
+    Queue => $queue_id, 
+    Requestor => 'order at example.com',
+    Subject => "Scrip order test $$",
+);
+ok($ticket->id, "Created ticket? id=$id");
+
+ok($ticket->Priority != 0, "Ticket shouldn't be priority 0");
+ok($ticket->Priority != 5, "Ticket shouldn't be priority 5");
+ok($ticket->Priority == 10, "Ticket should be priority 10");
+
+# }}}
+
+1;


More information about the Rt-commit mailing list