From: Peter Rabbitson Date: Sat, 6 Jun 2009 09:32:00 +0000 (+0000) Subject: Two failing MC tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9aa34b292cf1626113e60810d52e50798f87c806;p=dbsrgits%2FDBIx-Class-Historic.git Two failing MC tests --- diff --git a/t/multi_create/existing_in_chain.t b/t/multi_create/existing_in_chain.t new file mode 100644 index 0000000..c4464a8 --- /dev/null +++ b/t/multi_create/existing_in_chain.t @@ -0,0 +1,84 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +plan 'no_plan'; + +my $schema = DBICTest->init_schema(); + +{ + my $counts; + $counts->{$_} = $schema->resultset($_)->count for qw/Track CD Genre/; + + lives_ok (sub { + my $existing_nogen_cd = $schema->resultset('CD')->search ( + { 'genre.genreid' => undef }, + { join => 'genre' }, + )->first; + + $schema->resultset('Track')->create ({ + title => 'Sugar-coated', + cd => { + title => $existing_nogen_cd->title, + genre => { + name => 'sugar genre', + } + } + }); + + is ($schema->resultset('Track')->count, $counts->{Track} + 1, '1 new track'); + is ($schema->resultset('CD')->count, $counts->{CD}, 'No new cds'); + is ($schema->resultset('Genre')->count, $counts->{Genre} + 1, '1 new genre'); + + is ($existing_nogen_cd->genre->title, 'sugar genre', 'Correct genre assigned to CD'); + }); +} + +{ + my $counts; + $counts->{$_} = $schema->resultset($_)->count for qw/Artist CD Producer/; + + lives_ok (sub { + my $artist = $schema->resultset('Artist')->first; + my $producer = $schema->resultset('Producer')->create ({ name => 'the queen of england' }); + + $schema->resultset('CD')->create ({ + artist => $artist, + title => 'queen1', + year => 2007, + cd_to_producer => [ + { + producer => { + name => $producer->name, + producer_to_cd => [ + { + cd => { + title => 'queen2', + year => 2008, + artist => $artist, + }, + }, + ], + }, + }, + ], + }); + + is ($schema->resultset('Artist')->count, $counts->{Artist}, 'No new artists'); + is ($schema->resultset('Producer')->count, $counts->{Producer} + 1, '1 new producers'); + is ($schema->resultset('CD')->count, $counts->{CD} + 2, '2 new cds'); + + is ($producer->cds->count, 2, 'CDs assigned to correct producer'); + is_deeply ( + [ $producer->cds->search ({}, { order_by => 'title' })->get_column('title')->all], + [ qw/queen1 queen2/ ], + 'Correct cd names', + ); + }); +} + +1; diff --git a/t/multi_create/multilev_might_have_PKeqFK.t b/t/multi_create/multilev_might_have_PKeqFK.t index 702ffba..4d94871 100644 --- a/t/multi_create/multilev_might_have_PKeqFK.t +++ b/t/multi_create/multilev_might_have_PKeqFK.t @@ -8,7 +8,7 @@ use DBICTest; sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} }; -plan tests => 8; +plan tests => 13; my $schema = DBICTest->init_schema(); @@ -25,9 +25,8 @@ CD -> might have -> Artwork DG lives_ok (sub { - my $someartist = $schema->resultset('Artist')->first; my $cd = $schema->resultset('CD')->create ({ - artist => $someartist, + artist => { name => 'the cincinnati kid' }, title => 'Music to code by until the cows come home', year => 2008, artwork => { @@ -40,6 +39,7 @@ lives_ok (sub { isa_ok ($cd, 'DBICTest::CD', 'Main CD object created'); is ($cd->title, 'Music to code by until the cows come home', 'Correct CD title'); + is ($cd->artist->name, 'the cincinnati kid', 'Correct artist created for CD'); my $art_obj = $cd->artwork; ok ($art_obj->has_column_loaded ('cd_id'), 'PK/FK present on artwork object'); @@ -62,4 +62,44 @@ lives_ok (sub { ); }, 'multilevel might-have with a PK == FK in the might_have/has_many table ok'); + +mc_diag (<<'DG'); +* Try the same as above in a different direction + +Artist -> has_many -> Artwork_to_Artist -> belongs_to + / + belongs_to <- CD <- belongs_to <- Artwork <-/ + \ + \-> Artist2 + +DG + +lives_ok (sub { + $schema->resultset ('Artist')->create ({ + name => 'The wooled wolf', + artist_to_artwork => [{ + artwork => { + cd => { + title => 'Wool explosive', + year => 1999, + artist => { name => 'The black exploding sheep' }, + } + } + }], + }); + + my $art2 = $schema->resultset ('Artist')->find ({ name => 'The black exploding sheep' }); + ok ($art2, 'Second artist exists'); + + my $cd = $art2->cds->single; + is ($cd->title, 'Wool explosive', 'correctly created CD'); + + is_deeply ( + [ $cd->artwork->artists->get_column ('name')->all ], + [ 'The wooled wolf' ], + 'Artist correctly attached to artwork', + ); + +}, 'Diamond chain creation ok'); + 1;