From: Peter Rabbitson Date: Tue, 2 Mar 2010 10:13:54 +0000 (+0000) Subject: Test belongs_to accessor in-memory tie X-Git-Tag: v0.08121~93 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74608195a71925c878f2baa4c7844ece016461da;p=dbsrgits%2FDBIx-Class.git Test belongs_to accessor in-memory tie --- diff --git a/t/multi_create/in_memory.t b/t/multi_create/in_memory.t index e5c888b..922acbe 100644 --- a/t/multi_create/in_memory.t +++ b/t/multi_create/in_memory.t @@ -6,8 +6,6 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; -plan tests => 12; - my $schema = DBICTest->init_schema(); # Test various new() invocations - this is all about backcompat, making @@ -46,6 +44,23 @@ my $schema = DBICTest->init_schema(); } { + my $new_cd = $schema->resultset('CD')->new ({ 'title' => 'Leave Loudly While Singing Off Key', 'year' => 1982}); + my $new_artist = $schema->resultset("Artist")->new ({ 'name' => 'Depeche Mode 2: Insertion Boogaloo' }); + $new_cd->artist ($new_artist); + + eval { + $new_cd->insert; + }; + is ($@, '', 'CD insertion survives by inserting artist'); + ok($new_cd->in_storage, 'new_related_cd inserted'); + ok($new_artist->in_storage, 'artist inserted'); + + my $retrieved_cd = $schema->resultset('CD')->find ({ 'title' => 'Leave Loudly While Singing Off Key'}); + ok ($retrieved_cd, 'CD found in db'); + is ($retrieved_cd->artist->name, 'Depeche Mode 2: Insertion Boogaloo', 'Correct artist attached to cd'); +} + +{ my $new_cd = $schema->resultset("CD")->new_result({}); my $new_related_artist = $new_cd->new_related('artist', { 'name' => 'Marillion',}); lives_ok ( @@ -61,3 +76,5 @@ my $schema = DBICTest->init_schema(); ok($new_related_artist->in_storage, 'related artist inserted'); ok($new_cd->in_storage, 'cd inserted'); } + +done_testing;