From: Alexander Hartmaier Date: Sun, 8 Aug 2010 13:01:18 +0000 (+0200) Subject: added REST and RPC bulk_update tests for nonexisting objects X-Git-Tag: 2.002003~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=7c8cb609e0239ff5ccbb47f7a19436627c05f2e6 added REST and RPC bulk_update tests for nonexisting objects --- diff --git a/t/rest/update.t b/t/rest/update.t index 263ba40..2f8be2c 100644 --- a/t/rest/update.t +++ b/t/rest/update.t @@ -85,6 +85,7 @@ my $tracks_update_url = $track_url; is($track->cd->year, 2009, 'related row updated'); } +# bulk_update existing objects { # order to get a stable order of rows my $tracks_rs = $schema->resultset('Track')->search(undef, { order_by => 'trackid', rows => 3 }); @@ -100,4 +101,17 @@ my $tracks_update_url = $track_url; } } +# bulk_update nonexisting objects +{ + # order to get a stable order of rows + my $test_data = JSON::Any->Dump({ list => [map +{ id => $_, title => 'Track ' . $_ }, (1000..1002)] }); + my $req = PUT( $tracks_update_url, Content => $test_data ); + $req->content_type('text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', 400, 'Attempt to update three nonexisting tracks fails' ); + my $response = JSON::Any->Load( $mech->content); + is( $response->{success}, JSON::Any::false, 'success property returns false' ); + like( $response->{messages}->[0], qr/No object found for id/, 'correct message returned' ); +} + done_testing(); diff --git a/t/rpc/update.t b/t/rpc/update.t index 80d12d1..cbe7eab 100644 --- a/t/rpc/update.t +++ b/t/rpc/update.t @@ -131,6 +131,7 @@ my $tracks_update_url = "$base/api/rpc/track/update"; is($track->get_column('position'), '14', 'Position changed'); } +# bulk_update existing objects { # order to get a stable order of rows my $tracks_rs = $schema->resultset('Track')->search(undef, { order_by => 'trackid', rows => 3 }); @@ -146,4 +147,17 @@ my $tracks_update_url = "$base/api/rpc/track/update"; } } +# bulk_update nonexisting objects +{ + # order to get a stable order of rows + my $test_data = JSON::Any->Dump({ list => [map +{ id => $_, title => 'Track ' . $_ }, (1000..1002)] }); + my $req = POST( $tracks_update_url, Content => $test_data ); + $req->content_type('text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', 400, 'Attempt to update three nonexisting tracks fails' ); + my $response = JSON::Any->Load( $mech->content); + is( $response->{success}, JSON::Any::false, 'success property returns false' ); + like( $response->{messages}->[0], qr/No object found for id/, 'correct message returned' ); +} + done_testing();