From: Alexander Hartmaier Date: Sat, 7 Aug 2010 15:21:28 +0000 (+0200) Subject: added REST and RPC delete_bulk tests and fixed RPC delete_bulk not working at all X-Git-Tag: 2.002003~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=a1f7106409eb2d3c49aa9cb2c631464c14e911c4 added REST and RPC delete_bulk tests and fixed RPC delete_bulk not working at all use done_testing instead of specifying the number of tests at the beginning of the file --- diff --git a/Changes b/Changes index 5af3679..02186cd 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for Catalyst-Controller-DBIC-API: {{ $dist->version }} {{ $NEXT }} +- Added REST and RPC delete_bulk tests +- Fixed RPC delete_bulk not working at all + 2.002002 2010-08-03 14:40:50 Europe/Vienna - Fixed search for related columns overwriting existing params in generate_column_parameters diff --git a/lib/Catalyst/Controller/DBIC/API/RPC.pm b/lib/Catalyst/Controller/DBIC/API/RPC.pm index eacd523..c52e234 100644 --- a/lib/Catalyst/Controller/DBIC/API/RPC.pm +++ b/lib/Catalyst/Controller/DBIC/API/RPC.pm @@ -169,7 +169,7 @@ Provides an endpoint to the functionality described in Lnext::method($c); + $self->delete($c); } 1; diff --git a/t/rest/delete.t b/t/rest/delete.t index 0021ca5..7ce222f 100644 --- a/t/rest/delete.t +++ b/t/rest/delete.t @@ -10,9 +10,10 @@ my $content_type = [ 'Content-Type', 'application/x-www-form-urlencoded' ]; use RestTest; use DBICTest; -use Test::More tests => 4; +use Test::More; use Test::WWW::Mechanize::Catalyst 'RestTest'; -use HTTP::Request::Common; +use HTTP::Request::Common qw/ DELETE /; +use JSON::Any; my $mech = Test::WWW::Mechanize::Catalyst->new; ok(my $schema = DBICTest->init_schema(), 'got schema'); @@ -20,7 +21,8 @@ ok(my $schema = DBICTest->init_schema(), 'got schema'); my $track = $schema->resultset('Track')->first; my %original_cols = $track->get_columns; -my $track_delete_url = "$base/api/rest/track/" . $track->id; +my $track_url = "$base/api/rest/track/"; +my $track_delete_url = $track_url . $track->id; { my $req = HTTP::Request->new( DELETE => $track_delete_url ); @@ -38,3 +40,18 @@ my $track_delete_url = "$base/api/rest/track/" . $track->id; $mech->request($req); cmp_ok( $mech->status, '==', 400, 'Attempt to delete again caught' ); } + +{ + my $track_cnt = $schema->resultset('Track')->count; + my $tracks_rs = $schema->resultset('Track')->search(undef, { select => ['trackid'], as => ['id'], rows=> 3 }); + $tracks_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + my $test_data = JSON::Any->Dump({ list => [$tracks_rs->all] }); + my $req = DELETE( $track_url, Content => $test_data ); + $req->content_type('text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', 200, 'Attempt to delete three tracks ok' ); + + is($schema->resultset('Track')->count + 3, $track_cnt, 'Three tracks deleted'); +} + +done_testing(); diff --git a/t/rpc/delete.t b/t/rpc/delete.t index f780741..afd2698 100644 --- a/t/rpc/delete.t +++ b/t/rpc/delete.t @@ -21,6 +21,7 @@ my $track = $schema->resultset('Track')->first; my %original_cols = $track->get_columns; my $track_delete_url = "$base/api/rpc/track/id/" . $track->id . "/delete"; +my $tracks_delete_url = "$base/api/rpc/track/delete"; { my $req = POST( $track_delete_url, { @@ -41,4 +42,17 @@ my $track_delete_url = "$base/api/rpc/track/id/" . $track->id . "/delete"; cmp_ok( $mech->status, '==', 400, 'Attempt to delete again caught' ); } +{ + my $track_cnt = $schema->resultset('Track')->count; + my $tracks_rs = $schema->resultset('Track')->search(undef, { select => ['trackid'], as => ['id'], rows=> 3 }); + $tracks_rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + my $test_data = JSON::Any->Dump({ list => [$tracks_rs->all] }); + my $req = POST( $tracks_delete_url, Content => $test_data ); + $req->content_type('text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', 200, 'Attempt to delete three tracks ok' ); + + is($schema->resultset('Track')->count + 3, $track_cnt, 'Three tracks deleted'); +} + done_testing();