[Catalyst-commits] r12230 - in
Catalyst-Controller-DBIC-API/1.003/trunk: .
lib/Catalyst/Controller/DBIC lib/Catalyst/Controller/DBIC/API
t/lib/RestTest/Controller/API/RPC t/rpc t/var
abraxxa at dev.catalyst.perl.org
abraxxa at dev.catalyst.perl.org
Mon Dec 7 11:08:00 GMT 2009
Author: abraxxa
Date: 2009-12-07 11:08:00 +0000 (Mon, 07 Dec 2009)
New Revision: 12230
Modified:
Catalyst-Controller-DBIC-API/1.003/trunk/Changes
Catalyst-Controller-DBIC-API/1.003/trunk/Makefile.PL
Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm
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/CD.pm
Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t
Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_json_search.t
Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_prefetch.t
Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_search_allows.t
Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/setup_dbic_args.t
Catalyst-Controller-DBIC-API/1.003/trunk/t/var/DBIxClass.db
Log:
Database errors are also handled for searches + tests
totalcount isn't included in the response if a db error occurs while fetching data
converted no_plan tests to done_testing (required Test::More 0.88)
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/Changes
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/Changes 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/Changes 2009-12-07 11:08:00 UTC (rev 12230)
@@ -1,5 +1,10 @@
Revision history for Catalyst-Controller-DBIC-API
+1.003004
+- Database errors are also handled for searches + tests
+- totalcount isn't included in the response if a db error occurs while fetching data
+- converted no_plan tests to done_testing (required Test::More 0.88)
+
1.003003
- Database errors are properly handled + test
- Fixed isa redefined warnings
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/Makefile.PL
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/Makefile.PL 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/Makefile.PL 2009-12-07 11:08:00 UTC (rev 12230)
@@ -11,7 +11,7 @@
requires 'JSON::Any' => 1.19;
requires 'Test::Deep' => 0.104;
-build_requires 'Test::More' => 0.7;
+build_requires 'Test::More' => 0.88;
build_requires 'Catalyst::Model::DBIC::Schema' => 0.20;
build_requires 'Test::WWW::Mechanize' => 0.20;
build_requires 'Test::WWW::Mechanize::Catalyst' => 0.37;
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-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API/Base.pm 2009-12-07 11:08:00 UTC (rev 12230)
@@ -74,9 +74,19 @@
$c->stash->{$self->rs_stash_key} = $c->stash->{$self->rs_stash_key}->search($params, $args);
# add the total count of all rows in case of a paged resultset
- $c->stash->{_dbic_api}->{totalcount} = $c->stash->{$self->rs_stash_key}->pager->total_entries
- if $args->{page};
- $c->forward('format_list');
+ eval {
+ $c->stash->{_dbic_api}->{totalcount} = $c->stash->{$self->rs_stash_key}->pager->total_entries
+ if $args->{page};
+ };
+ 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.' });
+ }
+ else {
+ $c->forward('format_list');
+ }
}
sub generate_dbic_search_args :Private {
@@ -225,12 +235,23 @@
# it still is what they expect (and not inflating to a hash ref)
my $rs = $c->stash->{$self->rs_stash_key}->search;
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
- $c->stash->{response}->{list} = [ $rs->all ];
- if (my $totalcount = $c->stash->{_dbic_api}->{totalcount}) {
- # numify which is important for JSON
- $totalcount += 0;
- $c->stash->{response}->{totalcount} = $totalcount;
+ eval {
+ $c->stash->{response}->{list} = [ $rs->all ];
+ };
+ 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.' });
}
+ else {
+ # only add the totalcount to the response if also data is returned
+ if (my $totalcount = $c->stash->{_dbic_api}->{totalcount}) {
+ # numify which is important for JSON
+ $totalcount += 0;
+ $c->stash->{response}->{totalcount} = $totalcount;
+ }
+ }
}
sub create :Private {
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/lib/Catalyst/Controller/DBIC/API.pm 2009-12-07 11:08:00 UTC (rev 12230)
@@ -5,11 +5,11 @@
=head1 VERSION
-Version 1.003000
+Version 1.003004
=cut
-our $VERSION = '1.003003';
+our $VERSION = '1.003004';
=head1 NAME
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/CD.pm
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/CD.pm 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/lib/RestTest/Controller/API/RPC/CD.pm 2009-12-07 11:08:00 UTC (rev 12230)
@@ -9,7 +9,8 @@
( action => { setup => { PathPart => 'cd', Chained => '/api/rpc/rpc_base' } },
class => 'RestTestDB::CD',
create_requires => ['artist', 'title', 'year' ],
- update_allows => ['title', 'year']
+ update_allows => ['title', 'year'],
+ list_prefetch_allows => [[qw/ tracks /]],
);
1;
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list.t 2009-12-07 11:08:00 UTC (rev 12230)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More qw(no_plan);
+use Test::More;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -207,3 +207,29 @@
is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for search on col which exists for me and related table' );
}
}
+
+{
+ my $uri = URI->new( $cd_list_url );
+ $uri->query_form({ 'list_ordered_by' => 'invalid_column' });
+ my $req = GET( $uri, 'Accept' => 'text/x-json' );
+ $mech->request($req);
+ if (cmp_ok( $mech->status, '==', 400, 'order_by on non-existing col returns error' )) {
+ my $response = JSON::Syck::Load( $mech->content);
+ is_deeply( $response, { messages => ['a database error has occured.'], success => 'false' },
+ 'error returned for order_by on non-existing col' );
+ }
+}
+
+{
+ my $uri = URI->new( $cd_list_url );
+ $uri->query_form({ 'list_ordered_by' => 'invalid_column', 'list_count' => 2, 'list_page' => 1 });
+ my $req = GET( $uri, 'Accept' => 'text/x-json' );
+ $mech->request($req);
+ if (cmp_ok( $mech->status, '==', 400, 'order_by on invalid col with paging returns error' )) {
+ my $response = JSON::Syck::Load( $mech->content);
+ is_deeply( $response, { messages => ['a database error has occured.'], success => 'false' },
+ 'error returned for order_by on non-existing col with paging' );
+ }
+}
+
+done_testing();
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_json_search.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_json_search.t 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_json_search.t 2009-12-07 11:08:00 UTC (rev 12230)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More qw(no_plan);
+use Test::More;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -54,3 +54,5 @@
my $response = JSON::Syck::Load( $mech->content);
is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct data returned for complex query' );
}
+
+done_testing();
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_prefetch.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_prefetch.t 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_prefetch.t 2009-12-07 11:08:00 UTC (rev 12230)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More tests => 13;
+use Test::More tests => 15;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -62,3 +62,14 @@
is_deeply({ success => 'false',messages => ["prefetch validation failed"]}, $response, 'correct message returned' );
}
+{
+ my $uri = URI->new( $cd_list_url );
+ $uri->query_form({ 'list_prefetch' => 'tracks', 'list_ordered_by' => 'title', 'list_count' => 2, 'list_page' => 1 });
+ my $req = GET( $uri, 'Accept' => 'text/x-json' );
+ $mech->request($req);
+ if (cmp_ok( $mech->status, '==', 400, 'order_by on non-unique col with paging returns error' )) {
+ my $response = JSON::Syck::Load( $mech->content);
+ is_deeply( $response, { messages => ['a database error has occured.'], success => 'false' },
+ 'error returned for order_by on non-existing col with paging' );
+ }
+}
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_search_allows.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_search_allows.t 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/list_search_allows.t 2009-12-07 11:08:00 UTC (rev 12230)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More qw(no_plan);
+use Test::More;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -125,3 +125,5 @@
my $response = JSON::Syck::Load( $mech->content);
is_deeply({ success => 'true',list => \@expected_response }, $response, 'correct message returned' );
}
+
+done_testing();
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/setup_dbic_args.t
===================================================================
--- Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/setup_dbic_args.t 2009-12-07 08:13:45 UTC (rev 12229)
+++ Catalyst-Controller-DBIC-API/1.003/trunk/t/rpc/setup_dbic_args.t 2009-12-07 11:08:00 UTC (rev 12230)
@@ -10,7 +10,7 @@
use RestTest;
use DBICTest;
use URI;
-use Test::More qw(no_plan);
+use Test::More;
use Test::WWW::Mechanize::Catalyst 'RestTest';
use HTTP::Request::Common;
use JSON::Syck;
@@ -33,3 +33,5 @@
my $response = JSON::Syck::Load( $mech->content);
is_deeply( { list => \@expected_response, success => 'true' }, $response, 'correct message returned' );
}
+
+done_testing();
Modified: Catalyst-Controller-DBIC-API/1.003/trunk/t/var/DBIxClass.db
===================================================================
(Binary files differ)
More information about the Catalyst-commits
mailing list