5 eval "use DBD::SQLite";
6 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 30);
13 Film->has_many(actors => Actor => 'Film', { order_by => 'name' });
14 Actor->has_a(Film => 'Film');
15 is(Actor->primary_column, 'id', "Actor primary OK");
17 ok(Actor->can('Salary'), "Actor table set-up OK");
18 ok(Film->can('actors'), " and have a suitable method in Film");
20 Film->create_test_film;
22 ok(my $btaste = Film->retrieve('Bad Taste'), "We have Bad Taste");
25 my $pvj = Actor->create(
27 Name => 'Peter Vere-Jones',
29 Salary => '30_000', # For a voice!
34 is $pvj->Name, "Peter Vere-Jones", "PVJ name ok";
35 is $pvj->Film, undef, "No film";
36 ok $pvj->set_Film($btaste), "Set film";
38 is $pvj->Film->id, $btaste->id, "Now film";
40 my @actors = $btaste->actors;
41 is(@actors, 1, "Bad taste has one actor");
42 is($actors[0]->Name, $pvj->Name, " - the correct one");
46 Name => 'Peter Jackson',
47 Salary => '0', # it's a labour of love
50 eval { my $pj = Film->add_to_actors(\%pj_data) };
51 like $@, qr/class/, "add_to_actors must be object method";
53 eval { my $pj = $btaste->add_to_actors(%pj_data) };
54 like $@, qr/needs/, "add_to_actors takes hash";
57 my $pj = $btaste->add_to_actors(
59 Name => 'Peter Jackson',
60 Salary => '0', # it's a labour of love
65 is $pj->Name, "Peter Jackson", "PJ ok";
66 is $pvj->Name, "Peter Vere-Jones", "PVJ still ok";
69 my @actors = $btaste->actors;
70 is @actors, 2, " - so now we have 2";
71 is $actors[0]->Name, $pj->Name, "PJ first";
72 is $actors[1]->Name, $pvj->Name, "PVJ first";
76 my @actors = $btaste->actors(Name => $pj->Name);
77 is @actors, 1, "One actor from restricted (sorted) has_many";
78 is $actors[0]->Name, $pj->Name, "It's PJ";
80 is $@, '', "No errors";
82 my $as = Actor->create(
84 Name => 'Arnold Schwarzenegger',
85 Film => 'Terminator 2',
86 Salary => '15_000_000'
90 eval { $btaste->actors($pj, $pvj, $as) };
92 is($btaste->actors, 2, " - so we still only have 2 actors");
94 my @bta_before = Actor->search(Film => 'Bad Taste');
95 is(@bta_before, 2, "We have 2 actors in bad taste");
96 ok($btaste->delete, "Delete bad taste");
97 my @bta_after = Actor->search(Film => 'Bad Taste');
98 is(@bta_after, 0, " - after deleting there are no actors");
100 # While we're here, make sure Actors have unreadable mutators and
101 # unwritable accessors
103 eval { $as->Name("Paul Reubens") };
105 eval { my $name = $as->set_Name };
108 is($as->Name, 'Arnold Schwarzenegger', "Arnie's still Arnie");