File: 94pk_mutation.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (62 lines) | stat: -rw-r--r-- 1,590 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use strict;
use warnings;

use Test::More;
use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

plan tests => 10;

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');
}

# 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');
}