1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
use strict;
use Test::More;
BEGIN {
eval "use DBD::SQLite";
plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 23);
}
INIT {
use lib 't/testlib';
use Film;
use OtherFilm;
use Actor;
Film->CONSTRUCT;
OtherFilm->CONSTRUCT;
Actor->CONSTRUCT;
}
local $SIG{__WARN__} = sub { ::pass("deprecated warnings") };
ok(my $btaste = Film->retrieve('Bad Taste'), "Fetch Bad Taste again");
eval { my $diff_taste = Actor->move($btaste, "Bad Taste"); };
like $@, qr/related class/, "Can only move to a related class";
ok(my $diff_taste = OtherFilm->move($btaste, "Bad Taste"), "move()");
ok(defined $diff_taste && $diff_taste->isa('OtherFilm'),
" it's a different film");
is($diff_taste->id, $btaste->id, ' with the same id()');
is($diff_taste->Rating, $btaste->Rating, ' with the same rating()');
is($diff_taste->NumExplodingSheep,
$btaste->NumExplodingSheep, ' with the same sheep');
ok(my $more_taste = OtherFilm->move($btaste, "Bad Taste"), "Move it");
ok(defined $more_taste && $more_taste->isa('OtherFilm'),
" it's a different film");
is($more_taste->id, $btaste->id, ' with the same id()');
is($more_taste->Rating, $btaste->Rating, ' with the same rating()');
is($more_taste->NumExplodingSheep,
$btaste->NumExplodingSheep, ' with the same sheep');
# Move in other direction, and change rating
ok(
my $worse =
Film->move($more_taste, { title => "Worse Taste", rating => "18" }),
"Move up"
);
ok(defined $worse && $worse->isa('Film'), " it's a different film");
is($worse->id, "Worse Taste", " with the correct title");
isnt($worse->Rating, $more_taste->Rating, " and different rating");
is($worse->Rating, 18, " (correct rating)");
# Unrelated class
eval { Actor->move($btaste, "Bad Taste") };
ok $@, $@;
|