X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=t%2Frpc%2Fcreate.t;h=7f46b2dea24887675b729649ce08ece7939d0c83;hp=7d7fe41fa288e5623680d6c1c087ef2e9af4c479;hb=HEAD;hpb=a5bf6db237f004118bb8743ac941458946b21473 diff --git a/t/rpc/create.t b/t/rpc/create.t index 7d7fe41..7f46b2d 100644 --- a/t/rpc/create.t +++ b/t/rpc/create.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' ); @@ -102,15 +102,25 @@ my $producer_create_url = "$base/api/rpc/producer/create"; # test create returns an error as expected when passing invalid value { - my $long_string = '-' x 1024; + my $data = { + producerid => 100, + name => 'Producer', + }; - my $req = POST( - $producer_create_url, - { producerid => $long_string, - name => $long_string, - }, - 'Accept' => 'text/json' + my $req = POST($producer_create_url, $data, 'Accept' => 'text/json'); + $mech->request( $req, $content_type ); + cmp_ok( $mech->status, '==', 200, 'create with pk value ok' ); + my $response = $json->decode( $mech->content ); + is_deeply( + $response, + { success => 'true', list => $data }, + 'json for producer with pk value ok' ); + # try to insert same data again, as this seems to be the only way to + # force an insert to fail for SQLite. + # It accepts too long columns as well as wrong datatypes without errors. + # The bind with datatype of newer DBIC versions numifies non-integer + # values passed as pk value too. $mech->request( $req, $content_type ); cmp_ok( $mech->status, '==', 400, 'invalid param value produces error' ); }