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