| 1 |
use strict; |
| 2 |
use Test::More; |
| 3 |
use Class::DBI::Sweet; |
| 4 |
Class::DBI::Sweet->default_search_attributes({ use_resultset_cache => 0 }); |
| 5 |
Class::DBI::Sweet->cache(Cache::MemoryCache->new( |
| 6 |
{ namespace => "SweetTest", default_expires_in => 60 } ) ); |
| 7 |
|
| 8 |
BEGIN { |
| 9 |
eval "use Cache::MemoryCache"; |
| 10 |
plan skip_all => "needs Cache::Cache for testing" if $@; |
| 11 |
eval "use DBD::SQLite"; |
| 12 |
plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 18); |
| 13 |
} |
| 14 |
|
| 15 |
use lib 't/cdbi-t/testlib'; |
| 16 |
use Film; |
| 17 |
use Blurb; |
| 18 |
|
| 19 |
is(Blurb->primary_column, "title", "Primary key of Blurb = title"); |
| 20 |
is_deeply [ Blurb->_essential ], [ Blurb->primary_column ], "Essential = Primary"; |
| 21 |
|
| 22 |
eval { Blurb->retrieve(10) }; |
| 23 |
is $@, "", "No problem retrieving non-existent Blurb"; |
| 24 |
|
| 25 |
Film->might_have(info => Blurb => qw/blurb/); |
| 26 |
|
| 27 |
Film->create_test_film; |
| 28 |
{ |
| 29 |
ok my $bt = Film->retrieve('Bad Taste'), "Get Film"; |
| 30 |
isa_ok $bt, "Film"; |
| 31 |
is $bt->info, undef, "No blurb yet"; |
| 32 |
# bug where we couldn't write a class with a might_have that didn't_have |
| 33 |
$bt->rating(16); |
| 34 |
eval { $bt->update }; |
| 35 |
is $@, '', "No problems updating when don't have"; |
| 36 |
is $bt->rating, 16, "Updated OK"; |
| 37 |
|
| 38 |
is $bt->blurb, undef, "Bad taste has no blurb"; |
| 39 |
$bt->blurb("Wibble bar"); |
| 40 |
$bt->update; |
| 41 |
is $bt->blurb, "Wibble bar", "And we can write the info"; |
| 42 |
} |
| 43 |
|
| 44 |
{ |
| 45 |
my $bt = Film->retrieve('Bad Taste'); |
| 46 |
my $info = $bt->info; |
| 47 |
isa_ok $info, 'Blurb'; |
| 48 |
|
| 49 |
is $bt->blurb, $info->blurb, "Blurb is the same as fetching the long way"; |
| 50 |
ok $bt->blurb("New blurb"), "We can set the blurb"; |
| 51 |
$bt->update; |
| 52 |
is $bt->blurb, $info->blurb, "Blurb has been set"; |
| 53 |
|
| 54 |
$bt->rating(18); |
| 55 |
eval { $bt->update }; |
| 56 |
is $@, '', "No problems updating when do have"; |
| 57 |
is $bt->rating, 18, "Updated OK"; |
| 58 |
|
| 59 |
# cascade delete? |
| 60 |
{ |
| 61 |
my $blurb = Blurb->retrieve('Bad Taste'); |
| 62 |
isa_ok $blurb => "Blurb"; |
| 63 |
$bt->delete; |
| 64 |
$blurb = Blurb->retrieve('Bad Taste'); |
| 65 |
is $blurb, undef, "Blurb has gone"; |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
|