[Rt-commit] rt branch, lcore, updated. 300560fc03eecf6fbdc3b9c75c22e7d0a7eb1ecd
clkao at bestpractical.com
clkao at bestpractical.com
Tue Oct 20 10:11:25 EDT 2009
The branch, lcore has been updated
via 300560fc03eecf6fbdc3b9c75c22e7d0a7eb1ecd (commit)
from 67afbf1eff8802a2c746af9542734e9ea944aecb (commit)
Summary of changes:
lib/RT/Lorzy.pm | 13 ++++++++-----
t/lorzy/update.t | 20 ++++++++++++++++++--
2 files changed, 26 insertions(+), 7 deletions(-)
- Log -----------------------------------------------------------------
commit 300560fc03eecf6fbdc3b9c75c22e7d0a7eb1ecd
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Tue Oct 20 22:11:05 2009 +0800
tests for invalid params passed to update action
diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index e42cd01..3f17a3e 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -9,6 +9,8 @@ RT::Ruleset->register( 'RT::Lorzy::Dispatcher' );
use LCore;
use LCore::Level2;
+use Moose::Util::TypeConstraints;
+
our $LCORE = LCore->new( env => LCore::Level2->new );
require RT::Lorzy::Package::RT;
$LCORE->env->set_symbol('Native.Invoke' => LCore::Primitive->new
@@ -76,6 +78,8 @@ sub install_model_accessors {
my $modelname = lc($model);
$modelname =~ s/.*://;
+ my $param_type = $model.'Param';
+ type $param_type;
$env->set_symbol($model.'.Update' => LCore::Primitive->new
( body => sub {
@@ -91,7 +95,7 @@ sub install_model_accessors {
slurpy => 1,
parameters => [
LCore::Parameter->new({ name => $modelname, type => $model }),
- LCore::Parameter->new({ name => 'update', type => "ArrayRef[${model}Param]" }) ],
+ LCore::Parameter->new({ name => 'update', type => "ArrayRef[$param_type]" }) ],
return_type => 'Any',
));
@@ -112,6 +116,8 @@ sub install_model_accessors {
$env->set_symbol($model.'.'.$name => LCore::Primitive->new
( body => sub {
my ($object) = @_;
+ Carp::cluck unless $object;
+
$object->$name
},
lazy => 0,
@@ -125,17 +131,14 @@ sub install_model_accessors {
return [$name => $val]
},
parameters => [ LCore::Parameter->new({ name => $name, type => $type }) ],
- return_type => $model.'Param',
+ return_type => $param_type,
));
-
-
}
}
install_model_accessors($RT::Lorzy::LCORE->env, $_)
for qw(RT::Model::Ticket RT::Model::Transaction RT::Model::Queue);
-
my %cond_compat_map = ( 'On Create' => 'OnCreate',
'On Transaction' => 'OnTransaction',
'On Correspond' => 'OnCorrespond',
diff --git a/t/lorzy/update.t b/t/lorzy/update.t
index b89f0a7..937d2a8 100644
--- a/t/lorzy/update.t
+++ b/t/lorzy/update.t
@@ -1,4 +1,4 @@
-use Test::More tests => 7;
+use Test::More tests => 10;
use RT::Test;
use strict;
@@ -20,16 +20,32 @@ my $l = $RT::Lorzy::LCORE;
my $on_created_lcore = q{
(lambda (ticket transaction)
- (Str.Eq (Native.Invoke transaction "type") "create"))
+ (Str.Eq (RT::Model::Transaction.type transaction) "create"))
};
+ok( $l->analyze_it($on_created_lcore) );
+
my $update_ticket_lcore = q{
(lambda (ticket transaction context)
(RT::Model::Ticket.Update ticket
+ "fooo"
(RT::Model::TicketParam.subject "moose")
(RT::Model::TicketParam.priority 10)))
};
+throws_ok {
+ $l->analyze_it($update_ticket_lcore)
+} qr/type mismatch for array element 1: expecting RT::Model::TicketParam, got Str/;
+
+$update_ticket_lcore = q{
+(lambda (ticket transaction context)
+ (RT::Model::Ticket.Update ticket
+ (RT::Model::TicketParam.subject "moose")
+ (RT::Model::TicketParam.priority 10)))
+};
+
+ok( $l->analyze_it($update_ticket_lcore) );
+
RT::Lorzy::Dispatcher->reset_rules;
my $rule = RT::Model::Rule->new( current_user => RT->system_user );
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list