[Rt-commit] rt branch, lcore, updated. 67afbf1eff8802a2c746af9542734e9ea944aecb

clkao at bestpractical.com clkao at bestpractical.com
Tue Oct 20 09:26:57 EDT 2009


The branch, lcore has been updated
       via  67afbf1eff8802a2c746af9542734e9ea944aecb (commit)
       via  8903da40bdb6960654fbcc26dd828f50f4b382ae (commit)
       via  cf277a62ce1d15dd5f6d02ed3691e5e44ee49ea5 (commit)
      from  25bdc4ae88a087446a8ef9c67ca338ed1ddd77d2 (commit)

Summary of changes:
 lib/RT/Lorzy.pm                |   18 +++++++++++++-----
 t/lorzy/{action.t => update.t} |   36 ++++++++++++------------------------
 2 files changed, 25 insertions(+), 29 deletions(-)
 copy t/lorzy/{action.t => update.t} (52%)

- Log -----------------------------------------------------------------
commit cf277a62ce1d15dd5f6d02ed3691e5e44ee49ea5
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Oct 20 21:08:18 2009 +0800

    make update action slurpy and take the record object.

diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index d124004..756850a 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -82,8 +82,10 @@ sub install_model_accessors {
                                my @params = @_;
                                die 'not yet';
                            },
+                           slurpy => 1,
                            parameters => [
-                               LCore::Parameter->new({ name => 'params', type => "ArrayRef[${model}Param]" }) ],
+                               LCore::Parameter->new({ name => $modelname, type => $model }),
+                               LCore::Parameter->new({ name => 'update', type => "ArrayRef[${model}Param]" }) ],
                            return_type => 'Any',
                        ));
 

commit 8903da40bdb6960654fbcc26dd828f50f4b382ae
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Oct 20 21:08:55 2009 +0800

    failing test for new ticket update lcore entrace

diff --git a/t/lorzy/update.t b/t/lorzy/update.t
new file mode 100644
index 0000000..5dfacad
--- /dev/null
+++ b/t/lorzy/update.t
@@ -0,0 +1,49 @@
+use Test::More tests => 7;
+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('RT::Lorzy');
+use_ok('LCore');
+use_ok('LCore::Level2');
+my $l = $RT::Lorzy::LCORE;
+
+my $on_created_lcore = q{
+(lambda (ticket transaction)
+  (Str.Eq (Native.Invoke transaction "type") "create"))
+};
+
+my $update_ticket_lcore = q{
+(lambda (ticket transaction context)
+  (RT::Model::Ticket.Update ticket
+        (RT::Model::TicketParam.subject "moose")
+        (RT::Model::TicketParam.priority 10)))
+};
+
+RT::Lorzy::Dispatcher->reset_rules;
+
+my $rule = RT::Model::Rule->new( current_user => RT->system_user );
+$rule->create( condition_code => $on_created_lcore,
+               action_code    => $update_ticket_lcore );
+
+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 => 'lorzy test', queue => $queue->name, requestor => 'foo at localhost' );
+
+ok($ticket->id);
+is($ticket->subject, 'moose');
+is($ticket->priority, 10);

commit 67afbf1eff8802a2c746af9542734e9ea944aecb
Author: Chia-liang Kao <clkao at bestpractical.com>
Date:   Tue Oct 20 21:26:35 2009 +0800

    make the update action work using ticket->update.

diff --git a/lib/RT/Lorzy.pm b/lib/RT/Lorzy.pm
index 756850a..e42cd01 100644
--- a/lib/RT/Lorzy.pm
+++ b/lib/RT/Lorzy.pm
@@ -79,9 +79,15 @@ sub install_model_accessors {
 
     $env->set_symbol($model.'.Update' => LCore::Primitive->new
                          ( body => sub {
-                               my @params = @_;
-                               die 'not yet';
+                               my ($ticket, $update) = @_;
+                               # update is [ ['tag', $value], .... ]
+                               my %params = map { @$_ } @$update;
+                               use Data::Dumper;
+                               my ( $ret, $msg ) = $ticket->update(
+                                   attributes_ref => [keys %params],
+                                   args_ref       => \%params );
                            },
+                           lazy => 0,
                            slurpy => 1,
                            parameters => [
                                LCore::Parameter->new({ name => $modelname, type => $model }),
@@ -115,8 +121,8 @@ sub install_model_accessors {
 
         $env->set_symbol($model.'Param.'.$name => LCore::Primitive->new
                              ( body => sub {
-                                   my ($object) = @_;
-                                   die 'not yet';
+                                   my $val = shift;
+                                   return [$name => $val]
                                },
                                parameters => [ LCore::Parameter->new({ name => $name, type => $type }) ],
                                return_type => $model.'Param',
diff --git a/t/lorzy/update.t b/t/lorzy/update.t
index 5dfacad..b89f0a7 100644
--- a/t/lorzy/update.t
+++ b/t/lorzy/update.t
@@ -47,3 +47,5 @@ my ($rv, $msg) = $ticket->create( subject => 'lorzy test', queue => $queue->name
 ok($ticket->id);
 is($ticket->subject, 'moose');
 is($ticket->priority, 10);
+
+

-----------------------------------------------------------------------


More information about the Rt-commit mailing list