tests don't pass with CATALYST_DEBUG set to 1
[catagits/Catalyst-Action-REST.git] / t / catalyst-request-rest.t
index 3fd4c09..2226793 100644 (file)
@@ -1,8 +1,8 @@
 use strict;
 use warnings;
-use Test::More tests => 21;
+use Test::More tests => 28;
 use FindBin;
-use lib ( "$FindBin::Bin/../lib" );
+use lib ( "$FindBin::Bin/../lib", "$FindBin::Bin/../t/lib" );
 
 use Catalyst::Request::REST;
 use HTTP::Headers;
@@ -87,7 +87,7 @@ use HTTP::Headers;
     $request->headers( HTTP::Headers->new );
     $request->parameters( {} );
     $request->method('GET');
-    $request->content_type('text/x-json');
+    $request->content_type('application/json');
     $request->headers->header(
         'Accept' =>
         # From Firefox 2.0 when it requests an html page
@@ -95,7 +95,32 @@ use HTTP::Headers;
     );
 
     is_deeply( $request->accepted_content_types,
-               [ qw( text/x-json
+               [ qw( application/json
+                     text/xml application/xml application/xhtml+xml
+                     image/png
+                     text/html
+                     text/plain
+                     */*
+                   ) ],
+               'accept header is parsed properly, and content-type header has precedence over accept' );
+    ok( ! $request->accept_only, 'accept_only is false' );
+}
+
+{
+    my $request = Catalyst::Request::REST->new;
+    $request->{_context} = 'MockContext';
+    $request->headers( HTTP::Headers->new );
+    $request->parameters( {} );
+    $request->method('GET');
+    $request->content_type('application/json');
+    $request->headers->header(
+        'Accept' =>
+        # From Firefox 2.0 when it requests an html page
+        'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
+    );
+
+    is_deeply( $request->accepted_content_types,
+               [ qw( application/json
                      text/xml application/xml application/xhtml+xml
                      image/png
                      text/html
@@ -124,6 +149,44 @@ use HTTP::Headers;
                'each type appears only once' );
 }
 
+{
+    my $request = Catalyst::Request::REST->new;
+    $request->{_context} = 'MockContext';
+    $request->headers( HTTP::Headers->new );
+    $request->parameters( {} );
+    $request->method('GET');
+    $request->content_type('application/json');
+    $request->headers->header(
+        'Accept' => 'text/plain,application/json',
+    );
+
+    is_deeply( $request->accepted_content_types,
+               [ qw( application/json
+                     text/plain
+                   ) ],
+               'each type appears only once' );
+}
+
+{
+  local %ENV=%ENV;
+  $ENV{CATALYST_DEBUG} = 0;
+  my $test = 'Test::Catalyst::Action::REST';
+  use_ok $test;
+  is($test->request_class, 'Catalyst::Request::REST',
+    'Request::REST took over for Request');
+
+  $test->request_class('Some::Other::Class');
+  eval { $test->setup_finished(0); $test->setup };
+  like $@, qr/$test has a custom request class Some::Other::Class/;
+
+  {
+    package My::Request;
+    use base 'Catalyst::Request::REST';
+  }
+  $test->request_class('My::Request');
+  eval { $test->setup_finished(0); $test->setup };
+  is $@, '', 'no error from Request::REST subclass';
+}
 
 package MockContext;