Passes all the tests but..
[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         ] );
31         
32         isa_ok( $crap, 'DBICTest::Artist', "Got 'Artist'");
33         isa_ok( $damn, 'DBICTest::Artist', "Got 'Artist'");
34         isa_ok( $girl, 'DBICTest::Artist', "Got 'Artist'");     
35         
36         ok( $crap->name eq 'Manufactured Crap', "Got Correct name for result object");
37         ok( $girl->name eq 'Angsty-Whiny Girl', "Got Correct name for result object");
38         
39         use Data::Dump qw/dump/;
40         
41         ok( $crap->cds->count == 2, "got Expected Number of Cds");
42         ok( $girl->cds->count == 3, "got Expected Number of Cds");
43 }
44
45 RETURN_VOID: {
46
47         $rs->populate( [
48           { artistid => 7, name => 'Manufactured CrapB', cds => [ 
49                   { title => 'My First CDB', year => 2006 },
50                   { title => 'Yet More Tweeny-Pop crapB', year => 2007 },
51                 ] 
52           },
53           { artistid => 8, name => 'Angsty-Whiny GirlB', cds => [
54                   { title => 'My parents sold me to a record companyB' ,year => 2005 },
55                   { title => 'Why Am I So Ugly?B', year => 2006 },
56                   { title => 'I Got Surgery and am now PopularB', year => 2007 }
57
58                 ]
59           },
60           {artistid=>9,  name => 'XXXX' }
61
62         ] );
63         
64         my $artist = $rs->find(7);
65
66         ok($artist, 'Found artist');
67         is($artist->name, 'Manufactured CrapB');
68         is($artist->cds->count, 2, 'Has CDs');
69
70         my @cds = $artist->cds;
71
72         is($cds[0]->title, 'My First CDB', 'A CD');
73         is($cds[0]->year,  2006, 'Published in 2006');
74
75         is($cds[1]->title, 'Yet More Tweeny-Pop crapB', 'Another crap CD');
76         is($cds[1]->year,  2007, 'Published in 2007');
77
78         $artist = $rs->find(8);
79         ok($artist, 'Found artist');
80         is($artist->name, 'Angsty-Whiny GirlB');
81         is($artist->cds->count, 3, 'Has CDs');
82
83         @cds = $artist->cds;
84
85
86         is($cds[0]->title, 'My parents sold me to a record companyB', 'A CD');
87         is($cds[0]->year,  2005, 'Published in 2005');
88
89         is($cds[1]->title, 'Why Am I So Ugly?B', 'A Coaster');
90         is($cds[1]->year,  2006, 'Published in 2006');
91
92         is($cds[2]->title, 'I Got Surgery and am now PopularB', 'Selling un-attainable dreams');
93         is($cds[2]->year,  2007, 'Published in 2007');
94
95         $artist = $rs->search({name => 'XXXX'})->single;
96         ok($artist, "Got Expected Artist Result");
97
98         is($artist->cds->count, 0, 'No CDs');
99
100 }
101