Fixed the forwarding fix :)
Sebastian Riedel [Thu, 10 Nov 2005 13:33:41 +0000 (13:33 +0000)]
lib/Catalyst/Dispatcher.pm
t/live/component/controller/action/forward.t

index 8f94316..b64ad45 100644 (file)
@@ -80,13 +80,6 @@ sub forward {
     my $c       = shift;
     my $command = shift;
 
-    # Get the calling class
-    my $caller = ( caller(0) )[0];
-    if ( $caller->isa('Catalyst') ) {
-        if    ( ( caller(2) )[3] =~ /detach$/ )  { $caller = caller(3) }
-        elsif ( ( caller(0) )[3] =~ /forward$/ ) { $caller = caller(1) }
-    }
-
     unless ($command) {
         $c->log->debug('Nothing to forward to') if $c->debug;
         return 0;
@@ -100,11 +93,8 @@ sub forward {
         my $command_copy = $command;
 
         unless ( $command_copy =~ s/^\/// ) {
-            my $prefix =
-              Catalyst::Utils::class2prefix( $caller,
-                $c->config->{case_sensitive} )
-              || '';
-            $command_copy = "${prefix}/${command}";
+            my $namespace = $c->stack->[-1]->namespace;
+            $command_copy = "${namespace}/${command}";
         }
 
         unless ( $command_copy =~ /\// ) {
@@ -145,7 +135,9 @@ qq/Couldn't forward to command "$command". Invalid action or component./;
                     code      => $code,
                     reverse   => "$class->$method",
                     class     => $class,
-                    namespace => $class,
+                    namespace => Catalyst::Utils::class2prefix(
+                        $class, $c->config->{case_sensitive}
+                    ),
                 }
             );
             $result = $action;
index d64b5f9..db1c8ea 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
 
-use Test::More tests => 30*$iters;
+use Test::More tests => 44 * $iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -33,7 +33,7 @@ sub run_tests {
           TestApp::Controller::Action::Forward->four
           TestApp::Controller::Action::Forward->five
           TestApp::View::Dump::Request->process
-         TestApp->end
+          TestApp->end
         ];
 
         my $expected = join( ", ", @expected );
@@ -81,7 +81,7 @@ sub run_tests {
           TestApp::Controller::Action::Forward->four
           TestApp::Controller::Action::Forward->five
           TestApp::View::Dump::Request->process
-         TestApp->end
+          TestApp->end
         ];
 
         my $expected = join( ", ", @expected );
@@ -146,4 +146,80 @@ sub run_tests {
         ok( $response->is_success, 'Response Successful 2xx' );
         is( $response->content, 'ok' );
     }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Relative->begin
+          TestApp::Controller::Action::Relative->relative
+          TestApp::Controller::Action::Forward->one
+          TestApp::Controller::Action::Forward->two
+          TestApp::Controller::Action::Forward->three
+          TestApp::Controller::Action::Forward->four
+          TestApp::Controller::Action::Forward->five
+          TestApp::View::Dump::Request->process
+          TestApp->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        # Test forward to chain of actions.
+        ok( my $response = request('http://localhost/action/relative/relative'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            'action/relative/relative', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Relative',
+            'Test Class'
+        );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Relative->begin
+          TestApp::Controller::Action::Relative->relative_two
+          TestApp::Controller::Action::Forward->one
+          TestApp::Controller::Action::Forward->two
+          TestApp::Controller::Action::Forward->three
+          TestApp::Controller::Action::Forward->four
+          TestApp::Controller::Action::Forward->five
+          TestApp::View::Dump::Request->process
+          TestApp->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        # Test forward to chain of actions.
+        ok(
+            my $response =
+              request('http://localhost/action/relative/relative_two'),
+            'Request'
+        );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is(
+            $response->header('X-Catalyst-Action'),
+            'action/relative/relative_two',
+            'Test Action'
+        );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Relative',
+            'Test Class'
+        );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
 }