Add tests which should fail, but don't.
[catagits/Catalyst-Action-REST.git] / t / catalyst-action-rest.t
CommitLineData
d34c067a 1use strict;
2use warnings;
d34635d1 3use Test::More tests => 18;
d34c067a 4use FindBin;
d34c067a 5
89b766ab 6use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
d34c067a 7use Test::Rest;
8
9# Should use the default serializer, YAML
89b766ab 10my $t = Test::Rest->new( 'content_type' => 'text/plain' );
d34c067a 11
12use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
13
14foreach my $method (qw(GET DELETE POST PUT OPTIONS)) {
15 my $run_method = lc($method);
89b766ab 16 my $result = "something $method";
d34c067a 17 my $res;
89b766ab 18 if ( grep /$method/, qw(GET DELETE OPTIONS) ) {
19 $res = request( $t->$run_method( url => '/test' ) );
d34c067a 20 } else {
89b766ab 21 $res = request(
22 $t->$run_method(
23 url => '/test',
50157804 24 data => '',
d34c067a 25 )
26 );
27 }
28 ok( $res->is_success, "$method request succeeded" );
89b766ab 29 is(
30 $res->content,
31 "something $method",
32 "$method request had proper response"
33 );
d34c067a 34}
35
89b766ab 36my $fail_res = request( $t->delete( url => '/notreally' ) );
37is( $fail_res->code, 405, "Request to bad method gets 405 Not Implemented" );
38is( $fail_res->header('allow'), "GET", "405 allow header properly set." );
39
40my $options_res = request( $t->options( url => '/notreally' ) );
41is( $options_res->code, 200, "OPTIONS request handler succeeded" );
42is( $options_res->header('allow'),
43 "GET", "OPTIONS request allow header properly set." );
44
fec6d454 45my $modified_res = request( $t->get( url => '/not_modified' ) );
46is( $modified_res->code, 304, "Not Modified request handler succeeded" );
47
89b766ab 48my $ni_res = request( $t->delete( url => '/not_implemented' ) );
49is( $ni_res->code, 200, "Custom not_implemented handler succeeded" );
50is(
51 $ni_res->content,
52 "Not Implemented Handler",
53 "not_implemented handler had proper response"
54);
d34c067a 55
561;