Add strict/warnings test, adjust all offenders (wow, that was a lot)
[dbsrgits/DBIx-Class.git] / t / cdbi / 14-might_have.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 use lib 't/cdbi/testlib';
6 use Film;
7 use Blurb;
8
9 is(Blurb->primary_column, "title", "Primary key of Blurb = title");
10 is_deeply [ Blurb->columns('Essential') ], [ Blurb->primary_column ], "Essential = Primary";
11
12 eval { Blurb->retrieve(10) };
13 is $@, "", "No problem retrieving non-existent Blurb";
14
15 Film->might_have(info => Blurb => qw/blurb/);
16
17 Film->create_test_film;
18
19 {
20   ok my $bt = Film->retrieve('Bad Taste'), "Get Film";
21   isa_ok $bt, "Film";
22   is $bt->info, undef, "No blurb yet";
23   # bug where we couldn't write a class with a might_have that didn't_have
24   $bt->rating(16);
25   eval { $bt->update };
26   is $@, '', "No problems updating when don't have";
27   is $bt->rating, 16, "Updated OK";
28
29   is $bt->blurb, undef, "Bad taste has no blurb";
30   $bt->blurb("Wibble bar");
31   $bt->update;
32   is $bt->blurb, "Wibble bar", "And we can write the info";
33 }
34
35 {
36   my $bt   = Film->retrieve('Bad Taste');
37   my $info = $bt->info;
38   isa_ok $info, 'Blurb';
39
40   is $bt->blurb, $info->blurb, "Blurb is the same as fetching the long way";
41   ok $bt->blurb("New blurb"), "We can set the blurb";
42   $bt->update;
43   is $bt->blurb, $info->blurb, "Blurb has been set";
44
45   $bt->rating(18);
46   eval { $bt->update };
47   is $@, '', "No problems updating when do have";
48   is $bt->rating, 18, "Updated OK";
49
50   # cascade delete?
51   {
52     my $blurb = Blurb->retrieve('Bad Taste');
53     isa_ok $blurb => "Blurb";
54     $bt->delete;
55     $blurb = Blurb->retrieve('Bad Taste');
56     is $blurb, undef, "Blurb has gone";
57   }
58
59 }
60
61 {
62     my $host = Film->create({ title => "Gwoemul" });
63     $host->blurb("Monsters are real.");
64     my $info = $host->info;
65     is $info->blurb, "Monsters are real.";
66
67     $host->discard_changes;
68     is $host->info->id, $info->id,
69         'relationships still valid after discard_changes';
70
71     ok $host->info->delete;
72     $host->discard_changes;
73     ok !$host->info, 'relationships rechecked after discard_changes';
74 }
75
76 done_testing;