X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=t%2Frest%2Fupdate.t;h=d0a916eb89a4d1fb4383b07ab2b5dc032f3109bb;hp=7cd6ce53624cf03dd5b5d78a205d6f7bc223aba9;hb=257cb2149dd762b4f5af045a7340197296e3e50a;hpb=7f3ed65229c15d978fd4ac17848947da0a454369 diff --git a/t/rest/update.t b/t/rest/update.t index 7cd6ce5..d0a916e 100644 --- a/t/rest/update.t +++ b/t/rest/update.t @@ -101,6 +101,38 @@ my $tracks_update_url = $track_url; is( $track->cd->year, 2009, 'related row updated' ); } +# bulk update existing objects with database error +{ + + # order to get a stable order of rows + my $tracks_rs = + $schema->resultset('Track') + ->search( undef, { order_by => 'trackid', rows => 3 } ); + my @tracks = $tracks_rs->all; + my @tracks_new_data = map +{ id => $_->id, title => 'Track ' . $_->id }, + @tracks; + # set position column to NULL to force error + $tracks_new_data[0]->{position} = undef; + my $test_data = $json->encode({ list => \@tracks_new_data }); + 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 tracks fails' ); + my $response = $json->decode( $mech->content ); + is( $response->{success}, JSON::false, + 'success property returns unquoted false' ); + like( + $response->{messages}->[0], + qr/a database error has occured/, + 'correct message returned' + ); + + $tracks_rs->reset; + while ( my $track = $tracks_rs->next ) { + isnt( $track->title, 'Track ' . $track->id, 'Title unchanged' ); + } +} + # bulk_update existing objects {