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=3d8bae216c159548ef6210528c528779286b9338;hp=7cd6ce53624cf03dd5b5d78a205d6f7bc223aba9;hb=bb73aedb99734f11a8419f93915b87faf33ac1bf;hpb=23bb3784750da990dc8f6ded48839ff1b7f0d56c diff --git a/t/rest/update.t b/t/rest/update.t index 7cd6ce5..3d8bae2 100644 --- a/t/rest/update.t +++ b/t/rest/update.t @@ -11,9 +11,9 @@ use DBICTest; use Test::More; use Test::WWW::Mechanize::Catalyst 'RestTest'; use HTTP::Request::Common; -use JSON; +use JSON::MaybeXS; -my $json = JSON->new->utf8; +my $json = JSON::MaybeXS->new(utf8 => 1); my $mech = Test::WWW::Mechanize::Catalyst->new; ok( my $schema = DBICTest->init_schema(), 'got schema' ); @@ -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::MaybeXS::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 { @@ -143,7 +175,7 @@ my $tracks_update_url = $track_url; cmp_ok( $mech->status, '==', 400, 'Attempt to update three nonexisting tracks fails' ); my $response = $json->decode( $mech->content ); - is( $response->{success}, JSON::false, + is( $response->{success}, JSON::MaybeXS::false, 'success property returns unquoted false' ); like( $response->{messages}->[0],