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