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