Commit | Line | Data |
e76caa30 |
1 | use strict; |
4a233f30 |
2 | use warnings; |
e76caa30 |
3 | use Test::More; |
4 | |
50891152 |
5 | use lib 't/cdbi/testlib'; |
e76caa30 |
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 | { |
6a3bf251 |
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"; |
e76caa30 |
28 | |
6a3bf251 |
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"; |
e76caa30 |
33 | } |
34 | |
35 | { |
6a3bf251 |
36 | my $bt = Film->retrieve('Bad Taste'); |
37 | my $info = $bt->info; |
38 | isa_ok $info, 'Blurb'; |
e76caa30 |
39 | |
6a3bf251 |
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"; |
e76caa30 |
44 | |
6a3bf251 |
45 | $bt->rating(18); |
46 | eval { $bt->update }; |
47 | is $@, '', "No problems updating when do have"; |
48 | is $bt->rating, 18, "Updated OK"; |
e76caa30 |
49 | |
6a3bf251 |
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 | } |
8273e845 |
58 | |
e76caa30 |
59 | } |
60 | |
e60dc79f |
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'; |
d9bd5195 |
74 | } |
75 | |
76 | done_testing; |