File: 18insert_default.t

package info (click to toggle)
libdbix-class-perl 0.08123-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,520 kB
  • ctags: 1,695
  • sloc: perl: 19,821; sql: 353; makefile: 10
file content (31 lines) | stat: -rw-r--r-- 734 bytes parent folder | download
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
use strict;
use warnings;

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

my $tests = 3;
plan tests => $tests;

my $schema = DBICTest->init_schema();
my $rs = $schema->resultset ('Artist');
my $last_obj = $rs->search ({}, { order_by => { -desc => 'artistid' }, rows => 1})->single;
my $last_id = $last_obj ? $last_obj->artistid : 0;

my $obj;
eval { $obj = $rs->create ({}) };
my $err = $@;

ok ($obj, 'Insert defaults ( $rs->create ({}) )' );
SKIP: {
  skip "Default insert failed: $err", $tests-1 if $err;

  # this should be picked up without calling the DB again
  is ($obj->artistid, $last_id + 1, 'Autoinc PK works');

  # for this we need to refresh
  $obj->discard_changes;
  is ($obj->rank, 13, 'Default value works');
}