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