File: belongs_to_including_pks.t

package info (click to toggle)
libdbix-class-resultset-recursiveupdate-perl 0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,060 kB
  • sloc: perl: 5,130; sql: 640; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,751 bytes parent folder | download | duplicates (4)
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
63
64
65
use strict;
use warnings;
use Test::More;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

diag
    'Update foreign key with an updated primary key (similar to "Create foreign key col obj including PK" in 96multi_create.t)';
eval {
    my $new_cd_hashref = {
        cdid   => 30,
        title  => 'Boogie Woogie',
        year   => '2007',
        artist => { artistid => 1 }
    };

    my $cd = $schema->resultset("CD")->find(1);
    is( $cd->artist->id, 1, 'rel okay' );

    my $new_cd = $schema->resultset("CD")->recursive_update($new_cd_hashref);
    is( $new_cd->artist->id, 1, 'new id retained okay' );
};

eval {
    my $updated_cd = $schema->resultset("CD")->recursive_update(
        {   cdid   => 30,
            title  => 'Boogie Wiggle',
            year   => '2007',
            artist => { artistid => 2 }
        }
    );
    is( $updated_cd->artist->id, 2, 'related artist changed correctly' );
};
is( $@, '', 'new cd created without clash on related artist' );


diag
    'The same as the last test, but on a relationship with accessor "single".';
eval {
    my $new_lyrics_hashref = {
        lyric_id => 1,
        track    => { trackid => 4 }
    };

    my $new_lyric = $schema->resultset("Lyrics")->recursive_update($new_lyrics_hashref);
    is( $new_lyric->track->trackid, 4, 'new id retained okay' );
};

eval {
    my $updated_lyric = $schema->resultset("Lyrics")->recursive_update(
        {
            lyric_id => 1,
            track    => { trackid => 5 }
        }
    );
    is( $updated_lyric->track->trackid, 5, 'related artist changed correctly' );
};
is( $@, '', 'new cd created without clash on related artist' );

done_testing;

# vim: set ft=perl ts=4 expandtab: