| 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 => 5); |
| 13 |
} |
| 14 |
|
| 15 |
use lib 't/cdbi-t/testlib'; |
| 16 |
use Film; |
| 17 |
use Director; |
| 18 |
|
| 19 |
{ # Cascade Strategies |
| 20 |
Director->has_many(nasties => Film => { cascade => 'Fail' }); |
| 21 |
|
| 22 |
my $dir = Director->insert({ name => "Nasty Noddy" }); |
| 23 |
my $kk = $dir->add_to_nasties({ Title => 'Killer Killers' }); |
| 24 |
is $kk->director, $dir, "Director set OK"; |
| 25 |
is $dir->nasties, 1, "We have one nasty"; |
| 26 |
eval { $dir->delete }; |
| 27 |
like $@, qr/1/, "Can't delete while films exist"; |
| 28 |
my $rr = $dir->add_to_nasties({ Title => 'Revenge of the Revengers' }); |
| 29 |
eval { $dir->delete }; |
| 30 |
like $@, qr/2/, "Still can't delete"; |
| 31 |
$dir->nasties->delete_all; |
| 32 |
eval { $dir->delete }; |
| 33 |
is $@, '', "Can delete once films are gone"; |
| 34 |
} |