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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
# $Id$
use strict;
use lib 't/lib';
use lib 't/lib/cached';
use Test::More;
use Test::Exception;
use DodTestUtil;
BEGIN {
DodTestUtil->check_driver;
unless (eval { require Cache::Memory }) {
plan skip_all => 'Tests require Cache::Memory';
}
}
plan tests => 29;
use Wine;
use Recipe;
use Ingredient;
setup_dbs({
global => [ qw( wines recipes ingredients) ],
});
sub test_basic_cloning {
my $method = shift;
my $old ='Cul de Veau à la Sauge'; # tastes good !
my $new ='At first my tests ran on Recipe, sorry (Yann)';
my $w = Wine->new;
$w->name($old);
ok $w->save;
my $id = $w->id;
ok $id, 'Saved Wine has an id';
my $clone = $w->$method();
ok defined $clone, 'Successfully cloned';
isnt $w, $clone, 'Clone is not reference to the original';
is $w->name, $clone->name, 'Clone has the same name';
$clone->name($new);
isnt $w->name, $clone->name, 'Changing clone does not affect the original';
my $clone2 = $w->clone;
isnt $w, $clone2, 'Second clone is not a reference to the original';
isnt $clone, $clone2, 'Second clone is not a reference to the first clone';
}
test_basic_cloning('clone');
test_basic_cloning('clone_all');
# clone pk behavior
{
my $w = Wine->new;
$w->name('Cul de Veau à la Sauge');
ok $w->save;
ok $w->id, 'Saved original wine received an id';
my $clone = $w->clone;
ok !defined $clone->id, 'Basic clone has no id';
ok $clone->save, 'Basic clone could be saved';
is $clone->name, 'Cul de Veau à la Sauge';
is $clone->is_changed('name'), '', "This is documentation ;-)";
$clone->refresh;
is $clone->name, 'Cul de Veau à la Sauge';
ok defined $clone->id, 'Basic clone has an id after saving';
isnt $w->id, $clone->id, q(Basic clone's id differs from original's id);
}
# clone_all pk behavior
{
my $w = Wine->new;
$w->name('Cul de Veau à la Sauge');
ok $w->save;
ok $w->id, 'Saved original wine received an id';
my $clone = $w->clone_all;
ok defined $clone->id, 'Full clone has an id';
is $w->id, $clone->id, q(Full clone's id matches original's id);
}
END {
disconnect_all(qw/Wine Recipe Ingredient/);
teardown_dbs(qw( global ));
}
|