[Jifty-commit] r5557 - in jifty/trunk: . lib/Jifty/Action/Record t/TestApp/lib/TestApp/Action
Jifty commits
jifty-commit at lists.jifty.org
Sun Jul 20 23:16:50 EDT 2008
Author: sterling
Date: Sun Jul 20 23:16:49 2008
New Revision: 5557
Added:
jifty/trunk/t/TestApp/lib/TestApp/Action/ChangeSomething.pm
jifty/trunk/t/TestApp/t/23-extend-update-action.t
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Action/Record/Update.pm
Log:
r98262 at shanenka-lt-osx: shanenka | 2008-07-20 20:39:52 -0500
Updated the update action to make it easier to extend via Jifty::Param::Schema
Modified: jifty/trunk/lib/Jifty/Action/Record/Update.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Update.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record/Update.pm Sun Jul 20 23:16:49 2008
@@ -19,6 +19,7 @@
use base qw/Jifty::Action::Record/;
use Scalar::Util qw/ blessed /;
+use Hash::Merge;
=head1 METHODS
@@ -50,7 +51,12 @@
$arguments->{$pk}{'render_as'} = 'Unrendered';
# primary key fields should always be hidden fields
}
- return $arguments;
+
+ # XXX Should this be moved up into Jifty::Action::Record?
+ return Hash::Merge::merge(
+ $arguments,
+ ($self->can('PARAMS') && $self->PARAMS)
+ );
}
=head2 validate_arguments
Added: jifty/trunk/t/TestApp/lib/TestApp/Action/ChangeSomething.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/lib/TestApp/Action/ChangeSomething.pm Sun Jul 20 23:16:49 2008
@@ -0,0 +1,36 @@
+use strict;
+use warnings;
+
+package TestApp::Action::ChangeSomething;
+use base qw/ TestApp::Action::UpdateSomething /;
+
+use Jifty::Param::Schema;
+use Jifty::Action schema {
+ param direction =>
+ is mandatory,
+ default is 'forward',
+ valid_values are qw/
+ forward
+ reverse
+ /,
+ ;
+};
+
+sub take_action {
+ my $self = shift;
+
+ my $test3 = $self->argument_value('test3');
+ if ($self->argument_value('direction') eq 'reverse'
+ and defined $test3) {
+
+ $test3 = reverse $test3;
+ $self->argument_value( test3 => $test3 );
+ }
+
+ $self->argument_value( test3 => $test3 . $self->argument_value('append') )
+ if defined $self->argument_value('append');
+
+ $self->SUPER::take_action(@_);
+}
+
+1
Added: jifty/trunk/t/TestApp/t/23-extend-update-action.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/23-extend-update-action.t Sun Jul 20 23:16:49 2008
@@ -0,0 +1,56 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+Try out and make sure the the Do record action extends nicely.
+
+=cut
+
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 4;
+
+Jifty::Test->web;
+
+my $model = TestApp::Model::Something->new;
+$model->create( test3 => 'Dent' );
+my $id = $model->id;
+
+is($model->test3, 'Dent', 'starts as Dent');
+
+my $action = Jifty->web->new_action(
+ class => 'ChangeSomething',
+ record => $model,
+ arguments => {
+ direction => 'forward',
+ test3 => 'Prefect',
+ },
+);
+
+is_deeply(
+ [ sort $action->argument_names ],
+ [ 'direction', 'id', 'test3' ],
+ 'action has arguments');
+
+$action->run;
+
+$model->load($id);
+is($model->test3, 'Prefect', 'changed to Prefect');
+
+$action = Jifty->web->new_action(
+ class => 'ChangeSomething',
+ record => $model,
+ arguments => {
+ direction => 'reverse',
+ test3 => 'Beeblebrox',
+ },
+);
+
+$action->run;
+
+$model->load($id);
+is($model->test3, 'xorbelbeeB', 'ends with Beeblebrox backwards');
+
More information about the Jifty-commit
mailing list