Introduce ad hoc requirements and add skip_without method to optdeps
[dbsrgits/DBIx-Class-Historic.git] / t / cdbi / 23-cascade.t
CommitLineData
37702ea5 1use strict;
4a233f30 2use warnings;
37702ea5 3use Test::More;
dec1bfe0 4use Data::Dumper;
37702ea5 5
deff792e 6INIT {
50891152 7 use lib 't/cdbi/testlib';
deff792e 8 use Film;
9 use Director;
37702ea5 10}
deff792e 11
12{ # Cascade on delete
13 Director->has_many(nasties => 'Film');
14
15 my $dir = Director->insert({
16 name => "Lewis Teague",
17 });
18 my $kk = $dir->add_to_nasties({
19 Title => 'Alligator'
20 });
21 is $kk->director, $dir, "Director set OK";
22 is $dir->nasties, 1, "We have one nasty";
23
24 ok $dir->delete;
25 ok !Film->retrieve("Alligator"), "has_many cascade deletes by default";
26}
27
28
29# Two ways of saying not to cascade
30for my $args ({ no_cascade_delete => 1 }, { cascade => "None" }) {
31 Director->has_many(nasties => 'Film', $args);
32
33 my $dir = Director->insert({
34 name => "Lewis Teague",
35 });
36 my $kk = $dir->add_to_nasties({
37 Title => 'Alligator'
38 });
39 is $kk->director, $dir, "Director set OK";
40 is $dir->nasties, 1, "We have one nasty";
41
42 ok $dir->delete;
dec1bfe0 43 local $Data::Dumper::Terse = 1;
44 ok +Film->retrieve("Alligator"), 'has_many with ' . Dumper ($args);;
deff792e 45 $kk->delete;
46}
47
48
49#{ # Fail on cascade
50# local $TODO = 'cascade => "Fail" unimplemented';
8273e845 51#
deff792e 52# Director->has_many(nasties => Film => { cascade => 'Fail' });
53#
54# my $dir = Director->insert({ name => "Nasty Noddy" });
55# my $kk = $dir->add_to_nasties({ Title => 'Killer Killers' });
56# is $kk->director, $dir, "Director set OK";
57# is $dir->nasties, 1, "We have one nasty";
58#
59# ok !eval { $dir->delete };
60# like $@, qr/1/, "Can't delete while films exist";
61#
62# my $rr = $dir->add_to_nasties({ Title => 'Revenge of the Revengers' });
63# ok !eval { $dir->delete };
64# like $@, qr/2/, "Still can't delete";
65#
66# $dir->nasties->delete_all;
67# ok eval { $dir->delete };
68# is $@, '', "Can delete once films are gone";
69#}
d9bd5195 70
71done_testing;