6 eval "use DBIx::Class::CDBICompat;";
7 plan skip_all => 'Class::Trigger and DBIx::ContextualFetch required' if $@;
8 eval "use DBD::SQLite";
9 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 30);
16 Film->has_many(actors => Actor => 'Film', { order_by => 'name' });
17 Actor->has_a(Film => 'Film');
18 is(Actor->primary_column, 'id', "Actor primary OK");
20 ok(Actor->can('Salary'), "Actor table set-up OK");
21 ok(Film->can('actors'), " and have a suitable method in Film");
23 Film->create_test_film;
25 ok(my $btaste = Film->retrieve('Bad Taste'), "We have Bad Taste");
28 my $pvj = Actor->create(
30 Name => 'Peter Vere-Jones',
32 Salary => '30_000', # For a voice!
37 is $pvj->Name, "Peter Vere-Jones", "PVJ name ok";
38 is $pvj->Film, undef, "No film";
39 ok $pvj->set_Film($btaste), "Set film";
41 is $pvj->Film->id, $btaste->id, "Now film";
43 my @actors = $btaste->actors;
44 is(@actors, 1, "Bad taste has one actor");
45 is($actors[0]->Name, $pvj->Name, " - the correct one");
49 Name => 'Peter Jackson',
50 Salary => '0', # it's a labour of love
53 eval { my $pj = Film->add_to_actors(\%pj_data) };
54 like $@, qr/class/, "add_to_actors must be object method";
56 eval { my $pj = $btaste->add_to_actors(%pj_data) };
57 like $@, qr/needs/, "add_to_actors takes hash";
60 my $pj = $btaste->add_to_actors(
62 Name => 'Peter Jackson',
63 Salary => '0', # it's a labour of love
68 is $pj->Name, "Peter Jackson", "PJ ok";
69 is $pvj->Name, "Peter Vere-Jones", "PVJ still ok";
72 my @actors = $btaste->actors;
73 is @actors, 2, " - so now we have 2";
74 is $actors[0]->Name, $pj->Name, "PJ first";
75 is $actors[1]->Name, $pvj->Name, "PVJ first";
79 my @actors = $btaste->actors(Name => $pj->Name);
80 is @actors, 1, "One actor from restricted (sorted) has_many";
81 is $actors[0]->Name, $pj->Name, "It's PJ";
83 is $@, '', "No errors";
85 my $as = Actor->create(
87 Name => 'Arnold Schwarzenegger',
88 Film => 'Terminator 2',
89 Salary => '15_000_000'
93 eval { $btaste->actors($pj, $pvj, $as) };
95 is($btaste->actors, 2, " - so we still only have 2 actors");
97 my @bta_before = Actor->search(Film => 'Bad Taste');
98 is(@bta_before, 2, "We have 2 actors in bad taste");
99 ok($btaste->delete, "Delete bad taste");
100 my @bta_after = Actor->search(Film => 'Bad Taste');
101 is(@bta_after, 0, " - after deleting there are no actors");
103 # While we're here, make sure Actors have unreadable mutators and
104 # unwritable accessors
106 eval { $as->Name("Paul Reubens") };
108 eval { my $name = $as->set_Name };
111 is($as->Name, 'Arnold Schwarzenegger', "Arnie's still Arnie");