1use strict; 2use Test::More; 3 4BEGIN { 5 eval "use DBD::SQLite"; 6 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 27); 7} 8 9use lib 't/testlib'; 10use Film; 11use Blurb; 12 13is(Blurb->primary_column, "title", "Primary key of Blurb = title"); 14is_deeply [ Blurb->_essential ], [ Blurb->primary_column ], "Essential = Primary"; 15 16eval { Blurb->retrieve(10) }; 17is $@, "", "No problem retrieving non-existent Blurb"; 18 19Film->might_have(info => Blurb => qw/blurb/); 20 21Film->create_test_film; 22{ 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"; 31 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"; 36} 37 38{ 39 my $bt = Film->retrieve('Bad Taste'); 40 my $info = $bt->info; 41 isa_ok $info, 'Blurb'; 42 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"; 47 48 $bt->rating(18); 49 eval { $bt->update }; 50 is $@, '', "No problems updating when do have"; 51 is $bt->rating, 18, "Updated OK"; 52 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 } 61 62} 63 64Film->create_test_film; 65{ 66 ok my $bt = Film->retrieve('Bad Taste'), "Get Film"; 67 $bt->blurb("Wibble bar"); 68 $bt->update; 69 is $bt->blurb, "Wibble bar", "We can write the info"; 70 71 # Bug #15635: Operation `bool': no method found 72 $bt->info->delete; 73 my $blurb = eval { $bt->blurb }; 74 is $@, '', "Can delete the blurb"; 75 76 is $blurb, undef, "Blurb is now undef"; 77 78 eval { $bt->delete }; 79 is $@, '', "Can delete the parent object"; 80} 81 82Film->create_test_film; 83{ 84 ok my $bt = Film->retrieve('Bad Taste'), "Get Film (recreated)"; 85 is $bt->blurb, undef, "Bad taste has no blurb"; 86 $bt->blurb(0); 87 $bt->update; 88 is $bt->blurb, 0, "We can write false values"; 89 90 $bt->blurb(undef); 91 $bt->update; 92 is $bt->blurb, undef, "And explicit NULLs"; 93 $bt->delete; 94} 95 96 97 98