[Catalyst-commits] r8264 - in CatalystX-CRUD/CatalystX-CRUD/trunk:
lib/CatalystX/CRUD t
karpet at dev.catalyst.perl.org
karpet at dev.catalyst.perl.org
Sat Aug 23 04:30:48 BST 2008
Author: karpet
Date: 2008-08-23 04:30:47 +0100 (Sat, 23 Aug 2008)
New Revision: 8264
Modified:
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t
Log:
slight optimization for legibility; update tests
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2008-08-23 03:24:19 UTC (rev 8263)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/Controller.pm 2008-08-23 03:30:47 UTC (rev 8264)
@@ -181,7 +181,7 @@
sub get_primary_key {
my ( $self, $c, $id ) = @_;
- return () unless defined $id;
+ return () unless defined $id and length $id;
my $pk = $self->primary_key;
my @ret;
if ( ref $pk ) {
@@ -529,6 +529,7 @@
if ( uc( $c->req->method ) ne 'POST' ) {
$c->res->status(400);
$c->res->body('GET request not allowed');
+ $c->stash->{error} = 1; # so has_errors() will return true
return;
}
}
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2008-08-23 03:24:19 UTC (rev 8263)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/lib/CatalystX/CRUD/REST.pm 2008-08-23 03:30:47 UTC (rev 8264)
@@ -12,7 +12,7 @@
=head1 NAME
-CatalystX::CRUD::REST - REST-style controller for CRUD
+CatalystX::CRUD::REST - RESTful CRUD controller
=head1 SYNOPSIS
@@ -20,6 +20,7 @@
package MyApp::Controller::Foo;
use strict;
use base qw( CatalystX::CRUD::REST );
+ use MyForm::Foo;
__PACKAGE__->config(
form_class => 'MyForm::Foo',
@@ -109,7 +110,7 @@
sub create : Local {
my ( $self, $c ) = @_;
- $c->res->redirect( $c->uri_for('create_form') );
+ $c->res->redirect( $c->uri_for( $self->action_for('create_form') ) );
}
=head2 rest
@@ -221,6 +222,9 @@
sub _rest {
my ( $self, $c, @arg ) = @_;
+ # default oid to emptry string and not 0
+ # so we can test for length and
+ # still have a false value for fetch()
my $oid = shift @arg || '';
my $rpc = shift @arg;
@@ -299,10 +303,7 @@
=cut
-sub edit {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub edit { shift->next::method(@_) }
=head2 view( I<context> )
@@ -310,10 +311,7 @@
=cut
-sub view {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub view { shift->next::method(@_) }
=head2 save( I<context> )
@@ -321,10 +319,7 @@
=cut
-sub save {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub save { shift->next::method(@_) }
=head2 rm( I<context> )
@@ -332,10 +327,7 @@
=cut
-sub rm {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub rm { shift->next::method(@_) }
=head2 remove( I<context> )
@@ -343,10 +335,7 @@
=cut
-sub remove {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub remove { shift->next::method(@_) }
=head2 add( I<context> )
@@ -354,10 +343,7 @@
=cut
-sub add {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub add { shift->next::method(@_) }
=head2 delete( I<context> )
@@ -365,10 +351,7 @@
=cut
-sub delete {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub delete { shift->next::method(@_) }
=head2 read( I<context> )
@@ -376,10 +359,7 @@
=cut
-sub read {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub read { shift->next::method(@_) }
=head2 update( I<context> )
@@ -387,10 +367,7 @@
=cut
-sub update {
- my ( $self, $c ) = @_;
- return $self->next::method($c);
-}
+sub update { shift->next::method(@_) }
=head2 postcommit( I<context>, I<object> )
Modified: CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t
===================================================================
--- CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t 2008-08-23 03:24:19 UTC (rev 8263)
+++ CatalystX-CRUD/CatalystX-CRUD/trunk/t/03-rest.t 2008-08-23 03:30:47 UTC (rev 8264)
@@ -1,4 +1,4 @@
-use Test::More tests => 43;
+use Test::More tests => 47;
use strict;
use lib qw( lib t/lib );
use_ok('CatalystX::CRUD::Model::File');
@@ -61,6 +61,8 @@
# test the Arg matching with no rpc
+ok( $res = request('/rest/file/create'), "/rest/file/create" );
+is( $res->headers->{status}, 302, "/rest/file/create" );
ok( $res = request('/rest/file'), "zero" );
is( $res->headers->{status}, 302, "redirect == zero" );
ok( $res = request('/rest/file/testfile'), "one" );
@@ -95,6 +97,8 @@
# turn rpc enable on and run again
MyApp->controller('REST::File')->enable_rpc_compat(1);
+ok( $res = request('/rest/file/create'), "/rest/file/create" );
+is( $res->headers->{status}, 302, "/rest/file/create" );
ok( $res = request('/rest/file'), "zero with rpc" );
is( $res->headers->{status}, 302, "redirect == zero with rpc" );
ok( $res = request('/rest/file/testfile'), "one with rpc" );
More information about the Catalyst-commits
mailing list