File: undef_pk.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 (39 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;
use Test::More;
use DBIx::Class::ResultSet::RecursiveUpdate;

use lib 't/lib';
use DBSchema;

my $schema = DBSchema->get_test_schema();

# OK, create podcast that belongs_to owner
my $podcast = $schema->resultset('Podcast')->create({
            title => 'Pirates of the Caribbean',
            owner => {name => 'Bob'} });

is( $podcast->title, 'Pirates of the Caribbean', 'podcast name is correct');
is( $podcast->owner->name, 'Bob', 'owner is correct' );
my $owner = $podcast->owner;

# FAIL: trying to update podcast: set owner to NULL
DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update(
    resultset => $schema->resultset('Podcast'),
    updates => {
        title => 'Pirates of the Caribbean II',
        owner => undef
    },
    object => $podcast );
$podcast->discard_changes;

# OK, title updated correctly
is( $podcast->title, 'Pirates of the Caribbean II', 'podcast name is correct');

ok( ! $podcast->owner, 'no podcast owner');

# clear db
$podcast->delete;
$owner->delete;

done_testing;