[Jifty-commit] r989 - in jifty/trunk: . lib/Jifty
t/TestApp/lib/TestApp t/TestApp/lib/TestApp/Action
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu May 4 16:24:51 EDT 2006
Author: alexmv
Date: Thu May 4 16:24:50 2006
New Revision: 989
Added:
jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm
jifty/trunk/t/TestApp/t/05-actions-before-redirect.pm
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Request.pm
jifty/trunk/lib/Jifty/Web.pm
jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
Log:
r12821 at zoq-fot-pik: chmrr | 2006-05-04 16:22:27 -0400
* Redirects in 'before' in the dispatcher should keep track of unrun
actions
Modified: jifty/trunk/lib/Jifty/Request.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Request.pm (original)
+++ jifty/trunk/lib/Jifty/Request.pm Thu May 4 16:24:50 2006
@@ -713,7 +713,7 @@
package Jifty::Request::Action;
use base 'Class::Accessor::Fast';
-__PACKAGE__->mk_accessors( qw/moniker arguments class order active modified/);
+__PACKAGE__->mk_accessors( qw/moniker arguments class order active modified has_run/);
=head2 Jifty::Request::Action
@@ -731,6 +731,8 @@
=head3 active [BOOLEAN]
+=head3 has_run [BOOLEAN]
+
=cut
sub argument {
Modified: jifty/trunk/lib/Jifty/Web.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Web.pm (original)
+++ jifty/trunk/lib/Jifty/Web.pm Thu May 4 16:24:50 2006
@@ -262,6 +262,7 @@
$self->log->debug("Running action.");
eval { $action->run; };
+ $request_action->has_run(1);
if ( my $err = $@ ) {
# poor man's exception propagation
@@ -491,13 +492,25 @@
my $self = shift;
my $page = shift || $self->next_page;
+ my @unrun = grep {not $_->has_run} Jifty->web->request->actions;
+
if ( $self->response->results
- or $self->request->state_variables )
+ or $self->request->state_variables
+ or @unrun )
{
my $request = Jifty::Request->new();
$request->path($page);
$request->add_state_variable( key => $_->key, value => $_->value )
for $self->request->state_variables;
+ for (@unrun) {
+ $request->add_action(
+ moniker => $_->moniker,
+ class => $_->class,
+ order => $_->order,
+ active => $_->active,
+ arguments => $_->arguments,
+ );
+ }
my $cont = Jifty::Continuation->new(
request => $request,
response => $self->response,
Added: jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/lib/TestApp/Action/DoSomething.pm Thu May 4 16:24:50 2006
@@ -0,0 +1,11 @@
+package TestApp::Action::DoSomething;
+
+use base qw/Jifty::Action/;
+
+sub take_action {
+ my $self = shift;
+
+ $self->result->message("Something happened!");
+}
+
+1;
Modified: jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm
==============================================================================
--- jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm (original)
+++ jifty/trunk/t/TestApp/lib/TestApp/Dispatcher.pm Thu May 4 16:24:50 2006
@@ -1,6 +1,16 @@
package TestApp::Dispatcher;
use Jifty::Dispatcher -base;
+before '/redirect' => run {
+ Jifty->web->request->add_action(
+ moniker => 'thing',
+ class => 'DoSomething',
+ );
+ redirect '/index.html';
+};
+
+
+
on '/dispatch/' => run {
dispatch "/dispatch/basic";
};
Added: jifty/trunk/t/TestApp/t/05-actions-before-redirect.pm
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp/t/05-actions-before-redirect.pm Thu May 4 16:24:50 2006
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+=head1 DESCRIPTION
+
+If we do a redirect in a 'before' in the dispatcher, actions should
+still get run.
+
+=cut
+
+BEGIN {chdir "t/TestApp"}
+use lib '../../lib';
+use Jifty::Test tests => 6;
+use Jifty::Test::WWW::Mechanize;
+
+my $server = Jifty::Test->make_server;
+
+isa_ok($server, 'Jifty::Server');
+
+my $URL = $server->started_ok;
+my $mech = Jifty::Test::WWW::Mechanize->new();
+
+$mech->get_ok("$URL/redirect", "Got redirect");
+like($mech->uri, qr|/index.html|, "At index");
+ok($mech->continuation,"We have a continuation");
+$mech->content_like(qr/Something happened/, "Action ran");
+
+1;
+
More information about the Jifty-commit
mailing list