X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F101populate_rs.t;h=c1f497ff5febb77961ae2644c630dbdd80c43496;hb=dc87edb5845de612331948bce2445a3246663e96;hp=3a2bc4f4640eec132263eafa5e8d74a565d653a3;hpb=79fa498280663b837d48932d57c7c4aa63e38196;p=dbsrgits%2FDBIx-Class.git diff --git a/t/101populate_rs.t b/t/101populate_rs.t index 3a2bc4f..c1f497f 100644 --- a/t/101populate_rs.t +++ b/t/101populate_rs.t @@ -5,12 +5,12 @@ use Test::More; use lib qw(t/lib); use DBICTest; -plan tests => 43; +plan tests => 53; my $schema = DBICTest->init_schema(); my $rs = $schema->resultset('Artist'); -RETURN_RESULTSETS: { +RETURN_RESULTSETS_HAS_MANY: { my ($crap, $girl, $damn, $xxxaaa) = $rs->populate( [ { artistid => 4, name => 'Manufactured Crap', cds => [ @@ -47,7 +47,7 @@ RETURN_RESULTSETS: { ok( $girl->cds->count == 3, "got Expected Number of Cds"); } -RETURN_VOID: { +RETURN_VOID_HAS_MANY: { $rs->populate( [ { artistid => 8, name => 'Manufactured CrapB', cds => [ @@ -63,7 +63,7 @@ RETURN_VOID: { ] }, { artistid =>10, name => 'XXXX' }, - { artistid =>11, name => 'wart', cds =>{ title => 'xxxaaa' ,year => 2005 }, }, + { artistid =>11, name => 'wart', cds =>[{ title => 'xxxaaa' ,year => 2005 }], }, ] ); my $artist = $rs->find(8); @@ -148,15 +148,76 @@ RETURN_RESULTSETS_AUTOPK: { ok( $girl->cds->count == 3, "got Expected Number of Cds"); } -## Test from a belongs_to perspective, should create artist first, then CD with artistid in: -my $cd_rs = $schema->resultset('CD'); -$cd_rs->populate([ - { title => 'Some CD', - year => 1997, - artist => { name => 'Fred Bloggs'}, - }] ); -my $cd = $schema->resultset('CD')->find({title => 'Some CD'}); - -isa_ok($cd, 'DBICTest::CD', 'Created CD'); -isa_ok($cd->artist, 'DBICTest::Artist', 'Set Artist'); -is($cd->artist->name, 'Fred Bloggs', 'Set Artist to Fred'); +RETURN_RESULTSETS_BELONGS_TO: { + + ## Test from a belongs_to perspective, should create artist first, then CD with artistid in: + + my $cds = [ + { + title => 'Some CD1', + year => '1997', + artist => { name => 'Fred BloggsA'}, + }, + { + title => 'Some CD2', + year => '1997', + artist => { name => 'Fred BloggsB'}, + }, + ]; + + my $cd_rs = $schema->resultset('CD'); + + my @ret = $cd_rs->populate($cds); + + my $cdA = $schema->resultset('CD')->find({title => 'Some CD1'}); + + isa_ok($cdA, 'DBICTest::CD', 'Created CD'); + isa_ok($cdA->artist, 'DBICTest::Artist', 'Set Artist'); + is($cdA->artist->name, 'Fred BloggsA', 'Set Artist to FredA'); + + my $cdB = $schema->resultset('CD')->find({title => 'Some CD2'}); + + isa_ok($cdB, 'DBICTest::CD', 'Created CD'); + isa_ok($cdB->artist, 'DBICTest::Artist', 'Set Artist'); + is($cdB->artist->name, 'Fred BloggsB', 'Set Artist to FredB'); +} + +RETURN_VOID_BELONGS_TO: { + + ## Test from a belongs_to perspective, should create artist first, then CD with artistid in: + + my $cds = [ + { + title => 'Some CD3', + year => '1997', + artist => { name => 'Fred BloggsC'}, + }, + { + title => 'Some CD4', + year => '1997', + artist => { name => 'Fred BloggsD'}, + }, + ]; + + my $cd_rs = $schema->resultset('CD'); + + ok( $cd_rs, 'Got Good CD Resultset'); + + $cd_rs->populate($cds); + + my $cdA = $schema->resultset('CD')->find({title => 'Some CD3'}); + + isa_ok($cdA, 'DBICTest::CD', 'Created CD'); + isa_ok($cdA->artist, 'DBICTest::Artist', 'Set Artist'); + is($cdA->artist->name, 'Fred BloggsC', 'Set Artist to FredC'); + + my $cdB = $schema->resultset('CD')->find({title => 'Some CD4'}); + + isa_ok($cdB, 'DBICTest::CD', 'Created CD'); + isa_ok($cdB->artist, 'DBICTest::Artist', 'Set Artist'); + is($cdB->artist->name, 'Fred BloggsD', 'Set Artist to FredD'); +} + + + +