CatalystX-Resource
view release on metacpan or search on metacpan
t/02_crud.t view on Meta::CPAN
#!/usr/bin/env perl
use FindBin qw/$Bin/;
use lib "$Bin/lib";
use CatalystX::Resource::TestKit;
use Test::Exception;
use HTTP::Request::Common;
use Catalyst::Test qw/TestApp/;
my ($res, $c) = ctx_request('/');
my $schema = $c->model('DB')->schema;
ok(defined $schema, 'got a schema');
lives_ok(sub { $schema->deploy }, 'deploy schema');
# populate DB
$schema->resultset('Resource::Artist')->create({
id => 1,
name => 'davewood',
password => 'asdf',
});
my $artist = $schema->resultset('Resource::Artist')->create({
id => 2,
name => 'flipper',
password => 'asdf',
});
my $concert = $artist->concerts->create({
location => 'Madison Cube Garden',
});
lives_ok(sub { $artist->albums->create({ id => 1, name => 'Mach et einfach!' }); }, 'create album');
# test / for no special reason
{
my $path = '/';
my $res = request($path);
ok($res->is_success, "$path returns HTTP 200");
like($res->decoded_content, '/TestApp/', "$path content contains string 'TestApp'");
}
# identifier_candidates
{
my $path = '/artists/' . $artist->id . '/concerts/'. $concert->id . '/edit';
#my $res = request(POST $path);
my $res = request(POST $path, [ location => 'Madison Square Garden' ]);
ok($res->is_redirect, "$path returns HTTP 302");
my $uri = URI->new($res->header('location'));
is($uri->path, '/artists/' . $artist->id . '/concerts/list', 'redirect location is correct');
my $cookie = $res->header('Set-Cookie');
my $content = request(GET $uri->path, Cookie => $cookie)->decoded_content;
like($content, '/Madison Square Garden updated/', 'check update success notification');
}
# SHOW
{
my $path ='/artists/1/show';
my $res = request($path);
ok($res->is_success, "$path returns HTTP 200");
like($res->decoded_content, '/davewood/', "$path content contains string 'davewood'");
$path = '/artists/99/show';
ok(request($path)->code == 404, "Unknown resource $path returns HTTP 404");
}
# LIST
{
my $path ='/artists/list';
my $res = request($path);
( run in 2.660 seconds using v1.01-cache-2.11-cpan-d8267643d1d )