File: 07-has-a.t

package info (click to toggle)
libdata-objectdriver-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 784 kB
  • sloc: perl: 3,795; sql: 64; makefile: 7
file content (70 lines) | stat: -rw-r--r-- 1,416 bytes parent folder | download | duplicates (3)
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
# $Id: 05-deflate.t 1170 2006-03-24 05:29:48Z btrott $

use strict;

use lib 't/lib';
use lib 't/lib/cached';

use Test::More;
use Test::Exception;
use Scalar::Util;
use DodTestUtil;
BEGIN {
    DodTestUtil->check_driver;

    unless (eval { require Cache::Memory }) {
        plan skip_all => 'Tests require Cache::Memory';
    }
}

plan tests => 7;

use Recipe;
use Ingredient;

setup_dbs({
    global => [ qw( recipes ingredients) ],
});

Ingredient->has_a( {
        class  => 'Recipe',
        column => 'recipe_id',
        parent_method => 'ingredients',
        method => 'recipe',
    },
);

## setup  a few datas
my $recipe = Recipe->new;
$recipe->title('Cake');
$recipe->save;

my $ingredient = Ingredient->new;
$ingredient->recipe_id($recipe->recipe_id);
$ingredient->name('Egg');
$ingredient->quantity(5);
$ingredient->save;

my $i3 = Ingredient->new;
$i3->recipe_id($recipe->recipe_id);
$i3->name('Milk');
$i3->quantity(1);
$i3->save;

my @i = $recipe->ingredients;
is scalar @i, 2, "2 ingredients back using 'method'";
map { isa_ok $_, "Ingredient"; } @i;

my $iter = $recipe->ingredients;
isa_ok $iter, "CODE", "iterator is also available";
while (my $i = $iter->()) {
    isa_ok $i, "Ingredient", "next";
}

my $r = $ingredient->recipe;
is $r->recipe_id, $recipe->recipe_id, "recipe id back using 'parent_method'";

END {
    disconnect_all(qw/Recipe Ingredient/);
    teardown_dbs(qw( global ));
}