First go at supporting the populate syntax for resultset objects. Got non void conte...
[dbsrgits/DBIx-Class-Historic.git] / t / 101populate_rs.t
CommitLineData
81ab7888 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8plan tests => 18;
9
10my $schema = DBICTest->init_schema();
11my $rs = $schema->resultset('Artist');
12
71d496fe 13RETURN_RESULTSETS: {
14
15 my ($crap, $girl) = $rs->populate( [
16 { artistid => 4, name => 'Manufactured Crap', cds => [
17 { title => 'My First CD', year => 2006 },
18 { title => 'Yet More Tweeny-Pop crap', year => 2007 },
19 ]
20 },
21 { artistid => 5, name => 'Angsty-Whiny Girl', cds => [
22 { title => 'My parents sold me to a record company' ,year => 2005 },
23 { title => 'Why Am I So Ugly?', year => 2006 },
24 { title => 'I Got Surgery and am now Popular', year => 2007 }
25
26 ]
27 },
28 { name => 'Like I Give a Damn' }
29
30 ] );
31
32 isa_ok( $crap, 'DBICTest::Artist', "Got 'Artist'");
33 isa_ok( $girl, 'DBICTest::Artist', "Got 'Artist'");
34
35 ok( $crap->name eq 'Manufactured Crap', "Got Correct name for result object");
36 ok( $girl->name eq 'Angsty-Whiny Girl', "Got Correct name for result object");
37
38 use Data::Dump qw/dump/;
39
40 ok( $crap->cds->count == 2, "got Expected Number of Cds");
41 ok( $girl->cds->count == 3, "got Expected Number of Cds");
42}
43
44RETURN_VOID: {
45
46 $rs->populate( [
47 { artistid => 4, name => 'Manufactured Crap', cds => [
48 { title => 'My First CD', year => 2006 },
49 { title => 'Yet More Tweeny-Pop crap', year => 2007 },
50 ]
51 },
52 { artistid => 5, name => 'Angsty-Whiny Girl', cds => [
53 { title => 'My parents sold me to a record company' ,year => 2005 },
54 { title => 'Why Am I So Ugly?', year => 2006 },
55 { title => 'I Got Surgery and am now Popular', year => 2007 }
56
57 ]
58 },
59 { name => 'Like I Give a Damn' }
60
61 ] );
62
63 my $artist = $rs->find(4);
64
65 ok($artist, 'Found artist');
66 is($artist->name, 'Manufactured Crap');
67 is($artist->cds->count, 2, 'Has CDs');
68
69 my @cds = $artist->cds;
70
71 is($cds[0]->title, 'My First CD', 'A CD');
72 is($cds[0]->year, 2006, 'Published in 2006');
73
74 is($cds[1]->title, 'Yet More Tweeny-Pop crap', 'Another crap CD');
75 is($cds[1]->year, 2007, 'Published in 2007');
76
77 $artist = $rs->find(5);
78 ok($artist, 'Found artist');
79 is($artist->name, 'Angsty-Whiny Girl');
80 is($artist->cds->count, 3, 'Has CDs');
81
82 @cds = $artist->cds;
83
84
85 is($cds[0]->title, 'My parents sold me to a record company', 'A CD');
86 is($cds[0]->year, 2005, 'Published in 2005');
87
88 is($cds[1]->title, 'Why Am I So Ugly?', 'A Coaster');
89 is($cds[1]->year, 2006, 'Published in 2006');
90
91 is($cds[2]->title, 'I Got Surgery and am now Popular', 'Selling un-attainable dreams');
92 is($cds[2]->year, 2007, 'Published in 2007');
93
94 $artist = $rs->search({name => 'Like I Give A Damn'})->single;
95 ok($artist);
96
97 is($artist->cds->count, 0, 'No CDs');
98}
81ab7888 99