[Rt-commit] r18253 - in rt/3.999/branches/lorzy: lib/RT t/lorzy
clkao at bestpractical.com
clkao at bestpractical.com
Thu Feb 5 08:14:36 EST 2009
Author: clkao
Date: Thu Feb 5 08:14:35 2009
New Revision: 18253
Added:
rt/3.999/branches/lorzy/t/lorzy/action.t
Modified:
rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm
Log:
test for replacing autoreply scrip thunked through lorzy.
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy.pm Thu Feb 5 08:14:35 2009
@@ -8,6 +8,7 @@
RT::Ruleset->add( name => 'Lorzy', rules => ['RT::Lorzy::Dispatcher'] );
our $EVAL = Lorzy::Evaluator->new();
$EVAL->load_package($_) for qw(Str Native);
+$EVAL->load_package('RT', 'RT::Lorzy::Package::RT');
sub evaluate {
my ($self, $code, %args) = @_;
@@ -40,7 +41,7 @@
sub commit {
my ($self, $ticket_obj, $transaction_obj) = @_;
- return RT::Lorzy->evaluate( $self->action, ticket => $ticket_obj);
+ return RT::Lorzy->evaluate( $self->action, ticket => $ticket_obj, transaction => $transaction_obj);
}
1;
Modified: rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm
==============================================================================
--- rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm (original)
+++ rt/3.999/branches/lorzy/lib/RT/Lorzy/Package/RT.pm Thu Feb 5 08:14:35 2009
@@ -30,4 +30,21 @@
},
);
+__PACKAGE__->defun( 'ScripAction.Run',
+ signature => {
+ 'name' => Lorzy::FunctionArgument->new( name => 'name' ),
+ 'template' => Lorzy::FunctionArgument->new( name => 'template' ),
+ 'ticket' => Lorzy::FunctionArgument->new( name => 'ticket', type => 'RT::Model::Ticket' ),
+ 'transaction' => Lorzy::FunctionArgument->new( name => 'transaction', type => 'RT::Model::Transaction' ),
+ },
+ native => sub {
+ my $args = shift;
+ my $rule = RT::Rule->new( current_user => $args->{ticket}->current_user,
+ ticket_obj => $args->{ticket},
+ transaction_obj => $args->{transaction}
+ );
+ $rule->run_scrip_action(@{$args}{qw(name template)});
+ },
+);
+
1;
Added: rt/3.999/branches/lorzy/t/lorzy/action.t
==============================================================================
--- (empty file)
+++ rt/3.999/branches/lorzy/t/lorzy/action.t Thu Feb 5 08:14:35 2009
@@ -0,0 +1,78 @@
+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 RT::Test::Email;
+
+use_ok('Lorzy');
+use_ok('RT::Lorzy');
+
+my $tree = [ { name => 'IfThen',
+ args => { if_true => { name => 'True' },
+ if_false => { name => 'False' },
+ condition => { name => 'RT.Condition.Applicable',
+ args => {
+ name => "On Create",
+ ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+ transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
+ }
+ }
+ } } ];
+
+my $builder = Lorzy::Builder->new();
+my $on_created = $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' ) }
+);
+
+$tree = [ { name => 'RT.ScripAction.Run',
+ args => {
+ name => "Autoreply To requestors",
+ template => "Autoreply",
+ ticket => { name => 'Symbol', args => { symbol => 'ticket' }},
+ transaction => { name => 'Symbol', args => { symbol => 'transaction' }},
+ } } ];
+my $auto_reply = $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' ) }
+);
+
+RT::Lorzy::Dispatcher->add_rule(
+ RT::Lorzy::Rule->new( { condition => $on_created,
+ action => $auto_reply } )
+);
+
+# remove all existing scrips
+# XXX: disable the builtin lorzy rules here for test once it's enabled by core.
+my $scrips = RT::Model::ScripCollection->new( current_user => RT->system_user);
+$scrips->unlimit;
+$_->delete for @{$scrips};
+
+
+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 );
+mail_ok {
+lives_ok {
+my ($rv, $msg) = $ticket->create( subject => 'lorzy test', queue => $queue->name, requestor => 'foo at localhost' );
+};
+} { from => qr/lorzy via RT/,
+ to => 'foo at localhost',
+ subject => qr'AutoReply: lorzy test',
+ body => qr/automatically generated/,
+};
More information about the Rt-commit
mailing list