X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F94pk_mutation.t;h=082e5c4c53a20547c6d6b040160d21239feb02e0;hb=adcc1df0049e0093cb94c867bd2be8c9fe242a61;hp=46233327316a7131414997585855072df735fa6a;hpb=bc1b7747844a1afc6760aac03776a99dcd333bee;p=dbsrgits%2FDBIx-Class.git diff --git a/t/94pk_mutation.t b/t/94pk_mutation.t index 4623332..082e5c4 100644 --- a/t/94pk_mutation.t +++ b/t/94pk_mutation.t @@ -1,13 +1,15 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; -use warnings; +use warnings; use Test::More; -use lib qw(t/lib); + use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 5; +plan tests => 10; my $old_artistid = 1; my $new_artistid = $schema->resultset("Artist")->get_column('artistid')->max + 1; @@ -33,3 +35,30 @@ my $new_artistid = $schema->resultset("Artist")->get_column('artistid')->max + 1 ok(defined $artist, 'found an artist with the new PK'); is($artist->artistid, $new_artistid, 'artist ID matches'); } + +# Do it all over again, using a different methodology: +$old_artistid = $new_artistid; +$new_artistid++; + +# Update the PK +{ + my $artist = $schema->resultset("Artist")->find($old_artistid); + ok(defined $artist, 'found an artist with the new PK'); + + $artist->artistid($new_artistid); + $artist->update; + 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'); +}