[Catalyst-commits] r11038 - in
Catalyst-Controller-DBIC-API/1.003/trunk: .
lib/Catalyst/Controller/DBIC/API
t/lib/RestTest/Controller/API/RPC t/rpc
abraxxa at dev.catalyst.perl.org
abraxxa at dev.catalyst.perl.org
Thu Aug 6 12:17:44 GMT 2009
Author: abraxxa
Date: 2009-08-06 12:17:43 +0000 (Thu, 06 Aug 2009)
New Revision: 11038
Modified:
Catalyst-Controller-DBIC-API/1.003/trunk/Changes
Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/Producer.pm
Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/create.t
Log:
Database errors are properly handled + test
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/Changes 2009-08-06 09:57:02 UTC (rev 11037)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/Changes 2009-08-06 12:17:43 UTC (rev 11038)
@@ -1,5 +1,8 @@
Revision history for Catalyst-Controller-DBIC-API
+1.003003
+- Database errors are properly handled + test
+
1.003002
- Added totalcount to paged list responses
- Fixed some tests weren't run in t/rpc/list.t
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-08-06 09:57:02 UTC (rev 11037)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-08-06 12:17:43 UTC (rev 11038)
@@ -281,7 +281,6 @@
if $c->debug;
return;
}
-# use Data::Dumper; warn Dumper($params);
if ( $c->debug ) {
$c->log->debug("Saving object: $object");
$c->log->_dump( $params );
@@ -360,20 +359,29 @@
sub save_object {
my ($self, $c, $object, $params) = @_;
-
- if ($object->in_storage) {
- foreach my $key (keys %{$params}) {
- if (ref $params->{$key}) {
- my $related_params = delete $params->{$key};
- my $row = $object->find_related($key, {} , {});
- $row->update($related_params);
- }
- }
- $object->update($params);
- } else {
- $object->set_columns($params);
- $object->insert;
- }
+
+ eval {
+ if ($object->in_storage) {
+ foreach my $key (keys %{$params}) {
+ if (ref $params->{$key}) {
+ my $related_params = delete $params->{$key};
+ my $row = $object->find_related($key, {} , {});
+ $row->update($related_params);
+ }
+ }
+ $object->update($params);
+ } else {
+ $object->set_columns($params);
+ $object->insert;
+ }
+ };
+ if ($@) {
+ $c->log->error($@);
+ # send a generic error to the client to not give out infos about
+ # the database schema
+ $self->push_error($c, { message => 'a database error has occured.' });
+ }
+
return $object;
}
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/Producer.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/Producer.pm 2009-08-06 09:57:02 UTC (rev 11037)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/Producer.pm 2009-08-06 12:17:43 UTC (rev 11038)
@@ -9,6 +9,7 @@
( action => { setup => { PathPart => 'producer', Chained => '/api/rpc/rpc_base' } },
class => 'RestTestDB::Producer',
create_requires => ['name'],
+ create_allows => ['producerid'],
update_allows => ['name'],
list_returns => ['name']
);
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/create.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/create.t 2009-08-06 09:57:02 UTC (rev 11037)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/create.t 2009-08-06 12:17:43 UTC (rev 11038)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
-use Test::More tests => 11;
+use Test::More tests => 12;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -73,3 +73,15 @@
my $response = JSON::Syck::Load( $mech->content);
is_deeply( $response, { success => 'true' }, 'json for new artist returned' );
}
+
+# test create returns an error as expected when passing invalid value
+{
+ my $long_string = '-' x 1024;
+
+ my $req = POST( $producer_create_url, {
+ producerid => $long_string,
+ name => $long_string,
+ }, 'Accept' => 'text/json' );
+ $mech->request($req, $content_type);
+ cmp_ok( $mech->status, '==', 400, 'invalid param value produces error' );
+}
More information about the Catalyst-commits
mailing list