Made the test more clear, works here..
Tomas Doran [Wed, 26 Aug 2009 21:40:36 +0000 (22:40 +0100)]
t/catalyst-action-rest-action-dispatch.t
t/lib/Test/Action/Class.pm
t/lib/Test/Catalyst/Action/REST/Controller/Actions.pm

index 93ffb17..a092690 100644 (file)
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 23;
+use Test::More tests => 21;
 use FindBin;
 
 use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
@@ -13,7 +13,6 @@ use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
 
 foreach my $method (qw(GET DELETE POST PUT OPTIONS)) {
     my $run_method = lc($method);
-    my $result     = "something $method";
     my $res;
     if ( grep /$method/, qw(GET DELETE OPTIONS) ) {
         $res = request( $t->$run_method( url => '/actions/test' ) );
@@ -28,34 +27,18 @@ foreach my $method (qw(GET DELETE POST PUT OPTIONS)) {
     ok( $res->is_success, "$method request succeeded" );
     is(
         $res->content,
-        "something $method",
+        "$method",
         "$method request had proper response"
     );
     is(
+        $res->header('X-Was-In-TopLevel'),
+        '1',
+        "went through top level action for dispatching to $method"
+    );
+    is(
         $res->header('Using-Action'),
         'STATION',
         "went through action for dispatching to $method"
     );
 }
 
-my $fail_res = request( $t->delete( url => '/actions/notreally' ) );
-is( $fail_res->code, 405, "Request to bad method gets 405 Not Implemented" );
-is( $fail_res->header('allow'), "GET", "405 allow header properly set." );
-
-my $options_res = request( $t->options( url => '/actions/notreally' ) );
-is( $options_res->code, 200, "OPTIONS request handler succeeded" );
-is( $options_res->header('allow'),
-    "GET", "OPTIONS request allow header properly set." );
-
-my $modified_res = request( $t->get( url => '/actions/not_modified' ) );
-is( $modified_res->code, 304, "Not Modified request handler succeeded" );
-
-my $ni_res = request( $t->delete( url => '/actions/not_implemented' ) );
-is( $ni_res->code, 200, "Custom not_implemented handler succeeded" );
-is(
-    $ni_res->content,
-    "Not Implemented Handler",
-    "not_implemented handler had proper response"
-);
-
-1;
index 84f651a..4dd8884 100644 (file)
@@ -1,9 +1,7 @@
 package Test::Action::Class;
-use strict;
-use warnings;
-
 use Moose;
-BEGIN { extends 'Catalyst::Action' };
+
+extends 'Catalyst::Action';
 
 before execute => sub {
    my ($self, $controller, $c, @args) = @_;
index 2612a4e..596e4e0 100644 (file)
@@ -4,89 +4,39 @@ use warnings;
 
 use base qw/Catalyst::Controller::REST/;
 
-__PACKAGE__->config( namespace => 'actions' );
+__PACKAGE__->_action_class('Test::Action::Class');
 
 sub begin {}  # Don't need serialization..
 
-sub test : Local : ActionClass('REST') {
+sub test : Local : ActionClass('+Catalyst::Action::REST') {
     my ( $self, $c ) = @_;
-    $c->stash->{'entity'} = 'something';
+    $c->res->header('X-Was-In-TopLevel', 1);
 }
 
-sub test_GET : Private ActionClass('+Test::Action::Class') {
+sub test_GET : Private {
     my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} .= " GET";
-    $c->forward('ok');
+    $c->res->body('GET');
 }
 
-sub test_POST : Action ActionClass('+Test::Action::Class') {
+sub test_POST : Action {
     my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} .= " POST";
-    $c->forward('ok');
+    $c->res->body('POST');
 }
 
 sub test_PUT :ActionClass('+Test::Action::Class') {
     my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} .= " PUT";
-    $c->forward('ok');
-}
-
-sub test_DELETE :ActionClass('+Test::Action::Class') {
-    my ( $self, $c ) = @_;
-    $c->stash->{'entity'} .= " DELETE";
-    $c->forward('ok');
-}
-
-sub test_OPTIONS :ActionClass('+Test::Action::Class') {
-    my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} .= " OPTIONS";
-    $c->forward('ok');
+    $c->res->body('PUT');
 }
 
-sub notreally : Local : ActionClass('REST') {
-}
-
-sub notreally_GET :ActionClass('+Test::Action::Class') {
-    my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} = "notreally GET";
-    $c->forward('ok');
-}
-
-sub not_implemented : Local : ActionClass('REST') {
-}
-
-sub not_implemented_GET :ActionClass('+Test::Action::Class') {
-    my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} = "not_implemented GET";
-    $c->forward('ok');
-}
-
-sub not_implemented_not_implemented :ActionClass('+Test::Action::Class') {
-    my ( $self, $c ) = @_;
-
-    $c->stash->{'entity'} = "Not Implemented Handler";
-    $c->forward('ok');
-}
-
-sub not_modified : Local : ActionClass('REST') { }
-
-sub not_modified_GET {
+sub test_DELETE : Local {
     my ( $self, $c ) = @_;
-    $c->res->status(304);
-    return 1;
+    $c->res->body('DELETE');
 }
 
-sub ok : Private {
+sub test_OPTIONS : Path('foobar') {
     my ( $self, $c ) = @_;
 
-    $c->res->content_type('text/plain');
-    $c->res->body( $c->stash->{'entity'} );
+    $c->res->body('OPTIONS');
 }
 
 sub end : Private {} # Don't need serialization..