X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-DBIC-API.git;a=blobdiff_plain;f=t%2Frest%2Fstashedclass.t;fp=t%2Frest%2Fstashedclass.t;h=9a7dc2da8c96b88a9a9455fd2440cb45ac27094a;hp=84abd26111a82b4e903ba6da1c6e5e73a4ae76c7;hb=3649b790ea2d4ef93c32ee315b168b73dba087e6;hpb=850140b0ff0c6880796b9073d2289bbf68475773 diff --git a/t/rest/stashedclass.t b/t/rest/stashedclass.t index 84abd26..9a7dc2d 100644 --- a/t/rest/stashedclass.t +++ b/t/rest/stashedclass.t @@ -53,4 +53,32 @@ my $base_url = "$base/api/rest/stashedclass"; like($response->{messages}[0], qr/current_result_set.*does not pass the type constraint/, 'invalid class'); } + +{ + no warnings; + # stash->{class} should always win over $self->class + *Catalyst::Controller::DBIC::API::class = sub { 'RestTestDB::CD' }; + + my $class = 'RestTestDB::Artist'; + my $req = GET( "$base_url/$class", {}, 'Accept' => 'text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', '200', "status OK" ); + my $response = $json->decode( $mech->content ); + is($response->{success}, 'true', 'success'); + is(scalar( @{$response->{list}} ), 3, 'three results - artist'); +} + +{ + no warnings; + # stash->{class} not present, ->class should be returned + *Catalyst::Controller::DBIC::API::class = sub { 'RestTestDB::CD' }; + + my $req = GET( "$base_url/noclass", {}, 'Accept' => 'text/x-json'); + $mech->request($req); + cmp_ok( $mech->status, '==', '200', "status OK" ); + my $response = $json->decode( $mech->content ); + is($response->{success}, 'true', 'success'); + is(scalar( @{$response->{list}} ), 6, 'six results - cd'); +} + done_testing();