Changeset 1719

Show
Ignore:
Timestamp:
01/10/06 18:05:16
Author:
miyagawa
Message:

0.06; fix the encoding problem and added tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Catalyst-View-JSON/trunk/Changes

    r1718 r1719  
    11Revision history for Perl extension Catalyst::View::JSON 
     2 
     30.06  Tue Jan 10 09:04:34 UTC 2006 
     4        - Oops, 0.05 was broken. Fixed encode() problem and added test 
     5          cases for them. 
    26 
    370.05  Tue Jan 10 08:51:02 UTC 2006 
  • Catalyst-View-JSON/trunk/lib/Catalyst/View/JSON.pm

    r1718 r1719  
    22 
    33use strict; 
    4 our $VERSION = '0.05'; 
     4our $VERSION = '0.06'; 
    55 
    66use base qw( Catalyst::View ); 
     
    7171    # Otherwise it just by passed the stash data in JSON format 
    7272    if ( Encode::is_utf8($json) ) { 
    73         $json = Encode::encode($json, $encoding); 
     73        $json = Encode::encode($encoding, $json); 
    7474    } 
    7575 
  • Catalyst-View-JSON/trunk/t/01_server.t

    r1702 r1719  
    55use lib "$FindBin::Bin/lib"; 
    66 
    7 use Test::More tests => 22; 
     7use Encode; 
     8use Test::More tests => 28; 
    89use Catalyst::Test 'TestApp'; 
    910use JSON (); 
     
    3233    ok( $response->is_success, 'Response Successful 2xx' ); 
    3334    is( $response->code, 200, 'Response Code' ); 
    34     ok( $response->content_type, 'text/javascript+json' ); 
     35    is_deeply( [ $response->content_type ], [ 'text/javascript', 'charset=utf-8' ] ); 
    3536 
    3637    my $data = JSON::jsonToObj($response->content); 
     
    4647    ok( $response->is_success, 'Response Successful 2xx' ); 
    4748    is( $response->code, 200, 'Response Code' ); 
    48     ok( $response->content_type, 'text/javascript+json' ); 
     49    is_deeply( [ $response->content_type ], [ 'text/javascript', 'charset=utf-8' ] ); 
    4950 
    5051    my $data = JSON::jsonToObj($response->content); 
     
    5859    ok( $response->is_success, 'Response Successful 2xx' ); 
    5960    is( $response->code, 200, 'Response Code' ); 
    60     ok( $response->content_type, 'text/javascript+json' ); 
     61    is_deeply( [ $response->content_type ], [ 'text/javascript', 'charset=utf-8' ] ); 
    6162 
    6263    my $body = $response->content; 
     
    7576    like $response->header('X-Error'), qr/Invalid callback parameter/; 
    7677} 
     78 
     79{ 
     80    my $request = HTTP::Request->new( GET => "http://localhost/foo3" ); 
     81 
     82    ok( my $response = request($request), 'Request' ); 
     83    is_deeply( [ $response->content_type ], [ 'text/javascript', 'charset=utf-8' ] ); 
     84    ok decode('utf-8', $response->content); 
     85} 
     86 
     87{ 
     88    my $request = HTTP::Request->new( GET => "http://localhost/foo4" ); 
     89 
     90    ok( my $response = request($request), 'Request' ); 
     91    is_deeply( [ $response->content_type ], [ 'text/javascript', 'charset=euc-jp' ] ); 
     92    ok decode('euc-jp', $response->content); 
     93} 
  • Catalyst-View-JSON/trunk/t/lib/TestApp.pm

    r1702 r1719  
    3939} 
    4040 
     41sub foo3 : Global { 
     42    my( $self, $c ) = @_; 
     43    $c->stash->{json_foo} = "\x{5bae}\x{5ddd}"; 
     44    $c->forward('TestApp::View::JSON'); 
     45} 
     46 
     47sub foo4 : Global { 
     48    my( $self, $c ) = @_; 
     49    $c->stash->{json_foo} = "\x{5bae}\x{5ddd}"; 
     50    $c->component('View::JSON')->encoding('euc-jp'); 
     51    $c->forward('TestApp::View::JSON'); 
     52} 
     53 
    4154sub finalize_error { 
    4255    my $c = shift;