fix Index uri_for_action bug
Matt S Trout [Fri, 5 Mar 2010 03:36:57 +0000 (03:36 +0000)]
Changes
lib/Catalyst/DispatchType/Index.pm
t/aggregate/unit_core_uri_for.t
t/aggregate/unit_core_uri_for_action.t

diff --git a/Changes b/Changes
index 920d745..3cd68f6 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+  Bug fixed:
+    - DispatchType::Index's uri_for_action only returns for actions registered
+      with it (prevents 'index :Path' or similar resolving to the wrong URI)
+
 5.80021 2010-03-03 23:02:01
 
   Bug fixed:
index c0be9e6..6bad124 100644 (file)
@@ -67,7 +67,7 @@ Register an action with this DispatchType.
 sub register {
     my ( $self, $c, $action ) = @_;
 
-    $self->_actions->{ $action->reverse } = $action;
+    $self->_actions->{ $action->reverse } = $action if $action->name eq 'index';
 
     return 1;
 }
@@ -84,7 +84,7 @@ sub uri_for_action {
 
     return undef if @$captures;
 
-    return undef unless $action->name eq 'index';
+    return undef unless exists $self->_actions->{ $action->reverse };
 
     return "/".$action->namespace;
 }
index da40bea..48003d3 100644 (file)
@@ -159,6 +159,17 @@ TODO: {
     );
 }
 
+{
+    my $index_not_private = $dispatcher->get_action_by_path(
+                             '/action/chained/argsorder/index'
+                            );
+
+    is(
+      Catalyst::uri_for( $context, $index_not_private )->as_string,
+      'http://127.0.0.1/argsorder',
+      'Return non-DispatchType::Index path for index action with args'
+    );
+}
 
 done_testing;
 
index 4431f5a..89079f9 100644 (file)
@@ -21,6 +21,8 @@ my $private_action = $dispatcher->get_action_by_path(
                        '/class_forward_test_method'
                      );
 
+warn $dispatcher->uri_for_action($private_action);
+
 ok(!defined($dispatcher->uri_for_action($private_action)),
    "Private action returns undef for URI");