File: basic.t

package info (click to toggle)
libdbix-class-dynamicdefault-perl 0.04-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 1,497; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,431 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
use strict;
use warnings;
use Test::More tests => 14;
use DBICx::TestDatabase;

BEGIN { use_ok('DBIx::Class::DynamicDefault') }

use FindBin;
use lib "$FindBin::Bin/lib";

my $schema = DBICx::TestDatabase->new('TestSchema');
my $rs     = $schema->resultset('Table');
my $rs2    = $schema->resultset('Affe');

my $row = $rs->create({ fred => 'affe' });

is($row->quux, 1, 'default on create with methodname');
is($row->garply, undef, 'no default on create');
is($row->corge, 'create', 'default on create with coderef');

$row->update({ fred => 'moo' });

is($row->quux, 1, 'no default on update');
is($row->garply, $$, 'default on update with coderef');
is($row->corge, 'update2', 'default on update with methodname');

$row->garply(-42);
$row->update;

is($row->garply, -42, 'defaults don\'t get set when a value is specified explicitly on update');

$row->update;
is($row->corge, 'update3', 'no default on update without changes');

$row = $rs->create({ quux => -23, fred => 'zomtec' });

is($row->quux, -23, 'defaults don\'t get set when a value is specified explicitly on create');

$row = $rs2->create({ moo => 0, kooh => '123' });

is($row->moo, 0, 'no default on create');
is($row->kooh, '123', 'no default on create');

$row->update;

is($row->moo, 1, 'default on update without changes and always_update');
is($row->kooh, 'zomtec', 'on update default without always_update if another col is changed due to always_update');