CatalystX-CRUD-Controller-REST
view release on metacpan or search on metacpan
t/001-file.t view on Meta::CPAN
#!/usr/bin/env perl
use Test::More tests => 43;
use strict;
use lib qw( lib t/lib );
use_ok('CatalystX::CRUD::Model::File');
use_ok('CatalystX::CRUD::Object::File');
use Catalyst::Test 'MyApp';
use Data::Dump qw( dump );
use HTTP::Request::Common;
use JSON;
####################################################
# basic CRUD
sub json_PUT {
my ( $url, $body, $headers ) = @_;
my $req = HTTP::Request->new( PUT => $url );
$req->headers($headers) if $headers;
$req->header( 'Content-Type' => 'application/json' );
$req->header( 'Content-Length' => length($body) );
$req->content($body);
$req;
}
my $res;
# confirm testfile is not there
t/001-file.t view on Meta::CPAN
"PUT new file"
);
is( $res->code, 201, "PUT returns 201" );
is_deeply(
decode_json( $res->content ),
{ content => "hello world", file => "testfile" },
"PUT new file response"
);
# read the file we just created
ok( $res = request( HTTP::Request->new( GET => '/rest/file/testfile' ) ),
"GET new file" );
#diag( $res->content );
is_deeply(
decode_json( $res->content ),
{ content => "hello world", file => "testfile" },
"GET file response"
);
( run in 0.452 second using v1.01-cache-2.11-cpan-de7293f3b23 )