File: back-inflation.t

package info (click to toggle)
libtangram-perl 2.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,304 kB
  • sloc: perl: 10,260; makefile: 9
file content (80 lines) | stat: -rw-r--r-- 1,944 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl

use strict;
use warnings;

use lib "t";
use TestNeeds qw(Class::Tangram::Generator DBConfig);
use Test::More tests => 11;

BEGIN {
    use_ok('Tangram');
    use_ok('Class::Tangram::Generator');
};

my $schemahash = {
    classes => {
       Hat => {
            fields => {
                string   => [ qw( colour ) ],
            },
       },
       NaturalPerson => {
            fields => {
                string   => [ qw( firstName name ) ],
                int      => [ qw( age ) ],
                ref      => { partner => { null => 1 } },
                iset    => {
                    hats => {
                        class => 'Hat',
                        back => 'owner',
                    },
                },
            },
       },
    }
};

my $schema = Tangram::Schema->new($schemahash);

DBConfig->setup($schema);

my $gen     = Class::Tangram::Generator->new($schema);
my $storage = Tangram::Relational->connect($schema, DBConfig->cparm);

my $hat = $gen->new('Hat', colour => 'blue');
my $person = $gen->new('NaturalPerson', name => 'tangram');
$person->hats->insert($hat);
ok(scalar $person->hats, 'hat given to owner');

$storage->insert($person);

undef $person;
undef $hat;

$storage->recycle;

($person) = $storage->select('NaturalPerson');
ok(ref($person) eq 'NaturalPerson', 'person inserted and retrieved');

($hat) = $person->hats;
ok(ref($hat) eq 'Hat', 'person has a hat');

(my $owner) = $hat->owner;
ok(ref($owner) eq 'NaturalPerson', 'owner of hat is a person');

use Scalar::Util qw(refaddr);
is(refaddr($owner), refaddr($person), "same person");

ok(@{$owner->hats}, 'owner of hat has hats');


my $rem = $storage->remote('Hat');
($hat) = $storage->select($rem, $rem->{owner} eq $person);
ok(ref($hat) eq 'Hat', 'hat inserted and retrieved');

($owner) = $hat->owner;
ok(ref($owner) eq 'NaturalPerson', 'owner of hat is a person');

ok(@{$owner->hats}, 'owner of hat has hats');