4 @YA::Film::ISA = 'Film';
6 #local $SIG{__WARN__} = sub { };
9 use lib 't/cdbi/testlib';
14 Film->create_test_film;
15 ok(my $btaste = Film->retrieve('Bad Taste'), "We have Bad Taste");
16 ok(my $pj = $btaste->Director, "Bad taste has_a() director");
17 ok(!ref($pj), ' ... which is not an object');
19 ok(Film->has_a('Director' => 'Director'), "Link Director table");
23 Name => 'Peter Jackson',
24 Birthday => -300000000,
31 $btaste = Film->retrieve('Bad Taste');
33 ok($pj = $btaste->Director, "Bad taste now has_a() director");
34 isa_ok($pj => 'Director');
35 is($pj->id, 'Peter Jackson', ' ... and is the correct director');
37 # Oh no! Its Peter Jacksons even twin, Skippy! Born one minute after him.
38 my $sj = Director->create(
40 Name => 'Skippy Jackson',
41 Birthday => (-300000000 + 60),
46 is($sj->id, 'Skippy Jackson', 'We have a new director');
48 Film->has_a(CoDirector => 'Director');
50 $btaste->CoDirector($sj);
52 is($btaste->CoDirector->Name, 'Skippy Jackson', 'He co-directed');
54 $btaste->Director->Name,
56 "Didnt interfere with each other"
59 { # Ensure search can take an object
60 my @films = Film->search(Director => $pj);
61 is @films, 1, "1 Film directed by $pj";
62 is $films[0]->id, "Bad Taste", "Bad Taste";
69 # Skippy directs a film and Peter helps!
70 $sj = Director->retrieve('Skippy Jackson');
71 $pj = Director->retrieve('Peter Jackson');
73 fail_with_bad_object($sj, $btaste);
78 my $btaste = YA::Film->retrieve('Bad Taste');
79 is(ref($btaste->Director), 'Director', 'inheriting has_a()');
80 is(ref($btaste->CoDirector), 'Director', 'inheriting has_a()');
81 is($btaste->CoDirector->Name, 'Skippy Jackson', ' ... correctly');
85 my ($dir, $codir) = @_;
86 my $tastes_bad = YA::Film->create(
88 Title => 'Tastes Bad',
92 NumExplodingSheep => 23
95 is($tastes_bad->_Director_accessor, 'Skippy Jackson', 'Director_accessor');
96 is($tastes_bad->Director->Name, 'Skippy Jackson', 'Director');
97 is($tastes_bad->CoDirector->Name, 'Peter Jackson', 'CoDirector');
99 $tastes_bad->_CoDirector_accessor,
101 'CoDirector_accessor'
105 sub fail_with_bad_object {
106 my ($dir, $codir) = @_;
110 Title => 'Tastes Bad',
112 CoDirector => $codir,
114 NumExplodingSheep => 23
123 __PACKAGE__->table('foo');
124 __PACKAGE__->columns('All' => qw/ id fav /);
126 __PACKAGE__->db_Main->do( qq{
136 __PACKAGE__->table('bar');
137 __PACKAGE__->columns('All' => qw/ id fav /);
139 __PACKAGE__->db_Main->do( qq{
147 Foo->has_a("fav" => "Film");
148 Bar->has_a("fav" => "Foo");
149 my $foo = Foo->create({ id => 6, fav => 'Bad Taste' });
150 my $bar = Bar->create({ id => 2, fav => 6 });
151 isa_ok($bar->fav, "Foo");
152 isa_ok($foo->fav, "Film");
156 Foo->add_trigger(after_create => sub { $foo = shift->fav });
157 my $gwh = Foo->create({ id => 93, fav => 'Good Will Hunting' });
158 isa_ok $foo, "Film", "Object in after_create trigger";