[Jifty-commit] r5563 - in jifty/trunk: . lib/Jifty/Action/Record t/TestApp/lib/TestApp/Action
Jifty commits
jifty-commit at lists.jifty.org
Mon Jul 21 10:39:07 EDT 2008
Author: sterling
Date: Mon Jul 21 10:39:05 2008
New Revision: 5563
Added:
jifty/trunk/t/TestApp/lib/TestApp/Action/NewSomething.pm
jifty/trunk/t/TestApp/t/24-extend-create-action.t
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Action/Record/Create.pm
jifty/trunk/t/TestApp/t/23-extend-update-action.t
Log:
r98274 at shanenka-lt-osx: shanenka | 2008-07-21 09:38:17 -0500
Making it so that Create record actions are more easily extended.
Modified: jifty/trunk/lib/Jifty/Action/Record/Create.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record/Create.pm (original)
+++ jifty/trunk/lib/Jifty/Action/Record/Create.pm Mon Jul 21 10:39:05 2008
@@ -18,6 +18,8 @@
use base qw/Jifty::Action::Record/;
+use Hash::Merge;
+
=head1 METHODS
=head2 arguments
@@ -39,7 +41,11 @@
$args->{$arg}{default_value} = $column->default;
}
}
- return $args;
+
+ return Hash::Merge::merge(
+ $args,
+ (eval { $self->PARAMS } || {}),
+ );
}
=head2 take_action
@@ -67,6 +73,9 @@
# Iterate through all that are set, except for the virtual ones
for (grep { defined $self->argument_value($_) && !$self->arguments->{$_}->{virtual} } $self->argument_names) {
+ # Ignore values that don't have corresponding columns in the record
+ next unless defined $record->column($_);
+
# Prepare the hash to pass to create for each argument
$values{$_} = $self->argument_value($_);
Added: jifty/trunk/t/TestApp/lib/TestApp/Action/NewSomething.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/lib/TestApp/Action/NewSomething.pm Mon Jul 21 10:39:05 2008
@@ -0,0 +1,36 @@
+use strict;
+use warnings;
+
+package TestApp::Action::NewSomething;
+use base qw/ TestApp::Action::CreateSomething /;
+
+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
Modified: jifty/trunk/t/TestApp/t/23-extend-update-action.t
==============================================================================
--- jifty/trunk/t/TestApp/t/23-extend-update-action.t (original)
+++ jifty/trunk/t/TestApp/t/23-extend-update-action.t Mon Jul 21 10:39:05 2008
@@ -5,7 +5,7 @@
=head1 DESCRIPTION
-Try out and make sure the the Do record action extends nicely.
+Try out and make sure the the Update record action extends nicely.
=cut
Added: jifty/trunk/t/TestApp/t/24-extend-create-action.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/24-extend-create-action.t Mon Jul 21 10:39:05 2008
@@ -0,0 +1,48 @@
+#!/usr/bin/env perl
+
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+Try out and make sure the the Create record action extends nicely.
+
+=cut
+
+use lib 't/lib';
+use Jifty::SubTest;
+use Jifty::Test tests => 5;
+
+Jifty::Test->web;
+
+my $action = Jifty->web->new_action(
+ class => 'NewSomething',
+ arguments => {
+ direction => 'forward',
+ test3 => 'Prefect',
+ },
+);
+
+is_deeply(
+ [ sort $action->argument_names ],
+ [ 'direction', 'test3' ],
+ 'action has arguments');
+
+$action->run;
+
+ok($action->record->id, 'create a record');
+is($action->record->test3, 'Prefect', 'changed to Prefect');
+
+$action = Jifty->web->new_action(
+ class => 'NewSomething',
+ arguments => {
+ direction => 'reverse',
+ test3 => 'Beeblebrox',
+ },
+);
+
+$action->run;
+
+ok($action->record->id, 'create a record again');
+is($action->record->test3, 'xorbelbeeB', 'ends with Beeblebrox backwards');
+
More information about the Jifty-commit
mailing list