Ado
view release on metacpan or search on metacpan
t/command/crud.t view on Meta::CPAN
#t/command/adoplugin.t
use Mojo::Base -strict;
use Cwd;
use File::Spec::Functions qw(catdir catfile);
use File::Temp qw(tempdir);
use Mojo::Util qw(decamelize);
use Test::Mojo;
use Test::More;
my $tempdir = tempdir(CLEANUP => 1);
my $create_table = [
'DROP TABLE IF EXISTS testatii',
<<TAB,
CREATE TABLE IF NOT EXISTS testatii (
id INTEGER PRIMARY KEY,
title VARCHAR NOT NULL UNIQUE,
body TEXT NOT NULL,
published BOOL DEFAULT '0',
deleted BOOL NOT NULL DEFAULT '0',
user_id INTEGER REFERENCES users(id),
group_id INTEGER REFERENCES groups(id),
permissions VARCHAR(10) DEFAULT '-rwxr-xr-xr'
)
TAB
'CREATE INDEX testatii_published ON testatii(published)',
'CREATE INDEX testatii_deleted ON testatii(deleted)',
];
my $t = Test::Mojo->new('Ado');
my $ado = $t->app;
my $command = 'Ado::Command::generate::crud';
use_ok($command);
# check defaults
isa_ok(
my $c = $command->new(app => $ado)->initialise(
'-t' => 'testatii',
'-H' => $tempdir,
'-T' => catdir($tempdir, 'site_templates')
),
$command
);
is_deeply(
$c->args,
{ controller_namespace => $ado->routes->namespaces->[0],
#dsn => undef,
lib => catdir($tempdir, 'lib'),
model_namespace => 'Ado::Model',
#no_dsc_code => undef,
#password => undef,
overwrite => undef,
templates_root => catdir($tempdir, 'site_templates'),
tables => ['testatii'],
home_dir => $tempdir,
#user => undef,
},
'args are ok'
);
is(ref($c->routes), 'ARRAY', '$c->routes ISA ARRAY');
is_deeply(
$c->routes->[0],
{ route => '/testatii',
via => ['GET'],
to => "testatii#list",
},
'first root is OK'
);
#create the table
for my $sql (@$create_table) {
$ado->dbix->dbh->do($sql);
}
$ado->dbix->query(
'INSERT INTO testatii(title,body,user_id,group_id)' . 'VALUES(?,?,?,?)',
'Hello', 'more text in the body',
2, 2
);
$ado->dbix->query(
'INSERT INTO testatii(title,body,user_id,group_id)' . 'VALUES(?,?,?,?)',
'Hello2', 'more text in the body2',
2, 2
);
ok($c->run);
unshift @INC, $c->args->{lib};
#Run tests on the generated code?!?!
unshift @{$ado->renderer->paths}, catdir($tempdir, 'site_templates');
$t->get_ok('/testatii/list', {Accept => 'text/plain'})->status_is(415)
->content_like(qr|Unsupported.+Please.+list\.json|x, 'Unsupported Media Type - ok');
$t->get_ok('/testatii/list.json')->status_is(200);
$t->get_ok('/testatii/list.html')->status_is(200)
->content_like(qr|table.+id</th>.+permissions</th.+Hello</td.+Hello2|smx);
$t->post_ok(
'/testatii/create.html' => form => {
title => 'Hello3',
body =>
'Ðла, бала, ниÑа ÑÑÑÑка паниÑа, Хей гиди ÐанÑо, Ð½Ð°Ñ ÐºÐ°Ð¿Ð¸ÑанÑо...'
}
);
$t->get_ok('/testatii/read/3.html')->status_is(200)
->content_like(qr|Hello3|smx, 'reading content - ok');
$t->put_ok(
'/testatii/update/3.html' => form => {
id => 3,
title => 'Hello3 Updated',
( run in 0.505 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )