Data-ObjectDriver
view release on metacpan or search on metacpan
t/42-callbacks-multi-pk.t view on Meta::CPAN
# $Id: 41-callbacks.t 1037 2005-11-25 14:51:09Z ykerherve $
use strict;
use warnings;
use lib 't/lib';
use lib 't/lib/partitioned';
use Test::More;
use DodTestUtil;
BEGIN { DodTestUtil->check_driver }
plan tests => 13;
setup_dbs({
global => [ qw( recipes ) ],
cluster1 => [ qw( ingredients ) ],
cluster2 => [ qw( ingredients ) ],
});
use Recipe;
use Ingredient;
## test pre_save
{
my $title = "Crême brûlée à la pistache";
my $name = "Eggs";
my $quantity = 10;
my $recipe = Recipe->new;
$recipe->title($title);
$recipe->save;
my $ingredient = Ingredient->new;
$ingredient->recipe_id($recipe->recipe_id);
$ingredient->name($name);
$ingredient->quantity($quantity);
## it makes no sense to test if have the wrong init. cond.
isa_ok $ingredient->primary_key_tuple, 'ARRAY';
ok($recipe->partition_id, 'Recipe assigned to a cluster');
my $ran_callback = 0;
my $test_pre_save = sub {
is scalar(@_), 2, 'callback received correct number of parameters';
my ($saving) = @_;
## This is not the original object, so we can't test it that way.
isa_ok $saving, 'Ingredient', 'callback received correct kind of object';
cmp_ok $saving->name, 'eq', $name, $name;
cmp_ok $saving->quantity, '==', $quantity, 'quantity';
ok !defined($saving->id), 'callback received object with right data';
## Change rating to test immutability of original.
$saving->quantity($quantity * 2);
$ran_callback++;
return;
};
( run in 0.512 second using v1.01-cache-2.11-cpan-39bf76dae61 )