From: Daniel Westermann-Clark Date: Tue, 17 Oct 2006 07:40:56 +0000 (+0000) Subject: Add (currently failing) tests for single relationship accessors with objects and... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc1b7747844a1afc6760aac03776a99dcd333bee;p=dbsrgits%2FDBIx-Class-Historic.git Add (currently failing) tests for single relationship accessors with objects and for PK mutation --- diff --git a/t/93single_accessor_object.t b/t/93single_accessor_object.t new file mode 100644 index 0000000..6423c03 --- /dev/null +++ b/t/93single_accessor_object.t @@ -0,0 +1,42 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +plan tests => 7; + +# Test various uses of passing an object to find, create, and update on a single +# rel accessor +{ + my $artist = $schema->resultset("Artist")->find(1); + + my $cd = $schema->resultset("CD")->find_or_create({ + artist => $artist, + title => "Object on a might_have", + year => 2006, + }); + ok(defined $cd, 'created a CD'); + is($cd->get_column('artist'), $artist->id, 'artist matches CD'); + + my $liner_notes = $schema->resultset("LinerNotes")->find_or_create({ + liner_id => $cd, + notes => "Creating using an object on a might_have is helpful.", + }); + ok(defined $liner_notes, 'created liner notes'); + is($liner_notes->liner_id, $cd->cdid, 'liner notes matches CD'); + is($liner_notes->notes, "Creating using an object on a might_have is helpful.", 'liner notes are correct'); + + my $track = $cd->tracks->find_or_create({ + position => 1, + title => 'Single Accessor' + }); + is($track->get_column('cd'), $cd->cdid, 'track matches CD before update'); + + my $another_cd = $schema->resultset("CD")->find(5); + $track->update({ disc => $another_cd }); + is($track->cdid, $another_cd->cdid, 'track matches another CD after update'); +} diff --git a/t/94pk_mutation.t b/t/94pk_mutation.t new file mode 100644 index 0000000..4623332 --- /dev/null +++ b/t/94pk_mutation.t @@ -0,0 +1,35 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +plan tests => 5; + +my $old_artistid = 1; +my $new_artistid = $schema->resultset("Artist")->get_column('artistid')->max + 1; + +# Update the PK +{ + my $artist = $schema->resultset("Artist")->find($old_artistid); + ok(defined $artist, 'found an artist with the new PK'); + + $artist->update({ artistid => $new_artistid }); + is($artist->artistid, $new_artistid, 'artist ID matches'); +} + +# Look for the old PK +{ + my $artist = $schema->resultset("Artist")->find($old_artistid); + ok(!defined $artist, 'no artist found with the old PK'); +} + +# Look for the new PK +{ + my $artist = $schema->resultset("Artist")->find($new_artistid); + ok(defined $artist, 'found an artist with the new PK'); + is($artist->artistid, $new_artistid, 'artist ID matches'); +}