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
{