Help language development. Donate to The Perl Foundation

Red cpan:FCO last updated on 2020-07-23

use v6;

# This is the same as the t/09-alternate-relation.t
# except the model classes are in separate modules
# this is to discover precomp issues.

use Test;

use Red;

use lib <t/lib>;

use Person;
use Post;

my $*RED-DEBUG          = $_ with %*ENV<RED_DEBUG>;
my @conf                = (%*ENV<RED_DATABASE> // "SQLite").split(" ");
my $driver              = @conf.shift;
my $*RED-DB             = database $driver, |%( { do given .split: "=" { .[0] => .[1] } } );

lives-ok { schema(Person, Post).create }, "create table for Person and Post";

my $p;
$p = Person.^create: :name<Fernando>;
isa-ok $p, Person;
is $, "Fernando", "and it is the person we expected";
ok $, "primary key is defined";;
is $, 1, "and it is the value we expected";

my $post;
lives-ok {
    $post = $p.posts.create: :title("Red's commit"), :body("Merge branch 'master' of") ;
}, "create a related post";
isa-ok $post, Post;
is $, $, "and the author-id of the post is the one we expected";
is $post.title, "Red's commit", "post title is correct";
is $post.body, "Merge branch 'master' of", "post body is correct";