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 81 82
|
#!/usr/bin/perl -w
use strict;
use Test::More tests => 32;
use lib "t/springfield";
use Springfield;
for my $fairy ("FaerieHairy", "Faerie") {
#---------------------------------------------------------------------
# Test simple insertion of an explicitly listed field.
{
my $storage = Springfield::connect_empty();
my $bert = new $fairy( name => "Bert" );
my $bob = new $fairy( name => "Bob" );
$bert->{friends} = [ "Jesus" # everyone's friend
];
$bob->{friends} = { first => "Buddha" };
$bob->{foo} = "bar";
$storage->insert($bert, $bob);
ok($storage->id($bert), "Bert got an ID ($fairy)");
ok($storage->id($bob), "Bob got an ID ($fairy)");
}
is(leaked, 0, "leaktest");
# test update of an explicitly listed field, that contains a reference
# to another object.
{
my $storage = Springfield::connect();
my $pixie = $storage->remote($fairy);
my ($bert) = $storage->select($pixie, $pixie->{name} eq "Bert");
ok($bert, "Fetched Bert by name");
is($bert->{friends}->[0], "Jesus", "Jesus still Bert's friend");
my ($bob) = $storage->select($pixie, $pixie->{name} eq "Bob");
ok($bob, "Fetched Bob by name");
is($bob->{friends}->{first}, "Buddha",
"The Buddha still on Bob's side");
is($bob->{foo},
(($fairy eq "Faerie") ? "bar" : undef),
"Unknown attribute saved appropriately");
push @{ $bert->{friends} }, $bob;
$bob->{friends}->{second} = $bert;
#local($Tangram::TRACE)=\*STDERR;
$storage->update($bert, $bob);
delete $bert->{friends}; # break cyclic reference...
}
is(leaked, 0, "leaktest");
# test that the above worked.
{
my $storage = Springfield::connect();
my $pixie = $storage->remote($fairy);
my ($bert) = $storage->select($pixie, $pixie->{name} eq "Bert");
ok($bert, "Fetched Bert by name");
ok($bert->{friends}->[1], "Bert has another friend now");
is($bert->{friends}->[1]->{name}, "Bob", "Bert's other friend is Bob");
my ($bob) = $storage->select($pixie, $pixie->{name} eq "Bob");
ok($bob, "Fetched Bob by name");
ok($bob->{friends}->{second}, "Bob's has another friend now");
is($bob->{friends}->{second}, $bert, "Bob's other friend is Bert");
$storage->update($bert, $bob);
delete $bert->{friends}; # break cyclic reference...
}
is(leaked, 0, "leaktest");
}
|