From: Alexander Hartmaier Date: Wed, 13 Jun 2018 17:26:52 +0000 (+0200) Subject: add test for bulk update for existing objects with database error X-Git-Tag: 2.007001~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=commitdiff_plain;h=257cb2149dd762b4f5af045a7340197296e3e50a add test for bulk update for existing objects with database error --- 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 {