Use accessor instead of low level header value in tests
André Walker [Tue, 20 Jan 2015 16:55:03 +0000 (14:55 -0200)]
The test was failing in recent Catalyst versions because it was fetching
the header value using $res->header('Content-Type') instead of
$res->content_type. The former would get the entire HTTP header, which
recent versions would append the charset, thus changing the expected
value from 'text/x-yaml' to 'text/x-yaml; charset=UTF-8'.

The ->content_type accessor parses the header, and returns (in the
example): ('text/x-yaml', 'charset=UTF-8') in list context, and simply
'text/x-yaml' in scalar context. Using this, the test doesn't have to
worry about low level details such as the charset defined, which is out
of the scope of the test.

t/catalyst-action-serialize-accept.t

index e843186..8f5a38f 100644 (file)
@@ -31,7 +31,7 @@ my $output_YAML = Catalyst::Action::Serialize::YAML->serialize({lou => 'is my ca
              );
         ok( $res->is_success, 'GET the serialized request succeeded' );
         is( $res->content, $output_YAML, "Request returned proper data");
-        is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
+        is( $res->content_type, 'text/x-yaml', '... with expected content-type')
 
     };
 }
@@ -47,7 +47,7 @@ SKIP: {
     ok( $res->is_success, 'GET the serialized request succeeded' );
     my $ret = $json->decode($res->content);
     is( $ret->{lou}, 'is my cat', "Request returned proper data");
-    is( $res->header('Content-type'), 'application/json', 'Accept header used if content-type mapping not found')
+    is( $res->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 the default
@@ -59,7 +59,7 @@ SKIP: {
     my $res = request($req);
     ok( $res->is_success, 'GET the serialized request succeeded' );
     is( $res->content, $output_YAML, "Request returned proper data");
-    is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
+    is( $res->content_type, 'text/x-yaml', '... with expected content-type')
 }
 
 # Make sure that when using content_type_stash_key, an invalid value in the stash gets ignored
@@ -70,7 +70,7 @@ SKIP: {
     my $res = request($req);
     ok( $res->is_success, 'GET the serialized request succeeded' );
     is( $res->content, $output_YAML, "Request returned proper data");
-    is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type')
+    is( $res->content_type, 'text/x-yaml', '... with expected content-type')
 }
 
 # Make sure that the default content type you specify really gets used.