Add tests which should fail, but don't.
[catagits/Catalyst-Action-REST.git] / t / catalyst-action-serialize-accept.t
index bea3d3a..64732f5 100644 (file)
@@ -1,21 +1,22 @@
 use strict;
 use warnings;
-use Test::More tests => 16;
+use Test::More;
 use Data::Serializer;
 use FindBin;
 
 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken");
 use Test::Rest;
+use Catalyst::Action::Serialize::YAML;
 
 # Should use Data::Dumper, via YAML
 my $t = Test::Rest->new('content_type' => 'text/x-yaml');
 
 use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
 
-my $data = <<EOH;
----
-lou: is my cat
-EOH
+# to avoid whatever serialization bugs YAML::Syck has,
+# e.g. http://rt.cpan.org/Public/Bug/Display.html?id=46983,
+# we won't hardcode the expected output
+my $output_YAML = Catalyst::Action::Serialize::YAML->serialize({lou => 'is my cat'});
 
 {
     my $req = $t->get(url => '/serialize/test');
@@ -29,7 +30,7 @@ EOH
                 $res->content =~ m#Content-Type text/x-yaml is not supported#
              );
         ok( $res->is_success, 'GET the serialized request succeeded' );
-        is( $res->content, $data, "Request returned proper data");
+        is( $res->content, $output_YAML, "Request returned proper data");
         is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
 
     };
@@ -49,31 +50,31 @@ SKIP: {
     is( $res->header('Content-type'), 'application/json', 'Accept header used if content-type mapping not found')
 };
 
-# Make sure we don't get a bogus content-type when using default
-# serializer (rt.cpan.org ticket 27949)
+# Make sure we don't get a bogus content-type when using the default
+# serializer (https://rt.cpan.org/Ticket/Display.html?id=27949)
 {
     my $req = $t->get(url => '/serialize/test');
     $req->remove_header('Content-Type');
     $req->header('Accept', '*/*');
     my $res = request($req);
     ok( $res->is_success, 'GET the serialized request succeeded' );
-    is( $res->content, $data, "Request returned proper data");
+    is( $res->content, $output_YAML, "Request returned proper data");
     is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
 }
 
-# Make that using content_type_stash_key, an invalid value in the stash gets ignored
+# Make sure that when using content_type_stash_key, an invalid value in the stash gets ignored
 {
     my $req = $t->get(url => '/serialize/test_second?serialize_content_type=nonesuch');
     $req->remove_header('Content-Type');
     $req->header('Accept', '*/*');
     my $res = request($req);
     ok( $res->is_success, 'GET the serialized request succeeded' );
-    is( $res->content, $data, "Request returned proper data");
+    is( $res->content, $output_YAML, "Request returned proper data");
     is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
 }
 
-# Make that using content_type_stash_key, a valid value in the stash gets priority
-# this also tests that application-level config is properly passed to
+# Make sure that when using content_type_stash_key, a valid value in the stash gets priority.
+# This also tests that application-level config is properly passed to
 # individual controllers; see t/lib/Test/Catalyst/Action/REST.pm
 {
     my $req = $t->get(url =>
@@ -87,4 +88,14 @@ SKIP: {
     is( $res->header('Content-type'), 'text/x-data-dumper', '... with expected content-type')
 }
 
-1;
+# Make sure that the default content type you specify really gets used.
+{
+    my $req = $t->get(url => '/override/test');
+    $req->remove_header('Content-Type');
+    my $res = request($req);
+    ok( $res->is_success, 'GET the serialized request succeeded' );
+    is( $res->content, "--- \nlou: is my cat\n", "Request returned proper data");
+}
+
+done_testing;
+