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