Restore ability to handle underdefined root (t/prefetch/incomplete.t)
[dbsrgits/DBIx-Class.git] / t / 94pk_mutation.t
CommitLineData
729b29ae 1use strict;
8273e845 2use warnings;
729b29ae 3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10plan tests => 10;
11
12my $old_artistid = 1;
13my $new_artistid = $schema->resultset("Artist")->get_column('artistid')->max + 1;
14
15# Update the PK
16{
17 my $artist = $schema->resultset("Artist")->find($old_artistid);
18 ok(defined $artist, 'found an artist with the new PK');
19
20 $artist->update({ artistid => $new_artistid });
21 is($artist->artistid, $new_artistid, 'artist ID matches');
22}
23
24# Look for the old PK
25{
26 my $artist = $schema->resultset("Artist")->find($old_artistid);
27 ok(!defined $artist, 'no artist found with the old PK');
28}
29
30# Look for the new PK
31{
32 my $artist = $schema->resultset("Artist")->find($new_artistid);
33 ok(defined $artist, 'found an artist with the new PK');
34 is($artist->artistid, $new_artistid, 'artist ID matches');
35}
36
37# Do it all over again, using a different methodology:
38$old_artistid = $new_artistid;
39$new_artistid++;
40
41# Update the PK
42{
43 my $artist = $schema->resultset("Artist")->find($old_artistid);
44 ok(defined $artist, 'found an artist with the new PK');
45
46 $artist->artistid($new_artistid);
47 $artist->update;
48 is($artist->artistid, $new_artistid, 'artist ID matches');
49}
50
51# Look for the old PK
52{
53 my $artist = $schema->resultset("Artist")->find($old_artistid);
54 ok(!defined $artist, 'no artist found with the old PK');
55}
56
57# Look for the new PK
58{
59 my $artist = $schema->resultset("Artist")->find($new_artistid);
60 ok(defined $artist, 'found an artist with the new PK');
61 is($artist->artistid, $new_artistid, 'artist ID matches');
62}