Commit | Line | Data |
7a72e5a5 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
20595c02 |
5 | use Test::Exception; |
7a72e5a5 |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
20595c02 |
8 | use DBIC::DebugObj; |
9 | use DBIC::SqlMakerTest; |
7a72e5a5 |
10 | |
11 | my $schema = DBICTest->init_schema(); |
20595c02 |
12 | $schema->storage->sql_maker->quote_char('"'); |
13 | |
7a72e5a5 |
14 | my $rs = $schema->resultset ('Artist'); |
15 | my $last_obj = $rs->search ({}, { order_by => { -desc => 'artistid' }, rows => 1})->single; |
16 | my $last_id = $last_obj ? $last_obj->artistid : 0; |
17 | |
20595c02 |
18 | |
19 | my ($sql, @bind); |
20 | my $orig_debugobj = $schema->storage->debugobj; |
21 | my $orig_debug = $schema->storage->debug; |
22 | |
23 | $schema->storage->debugobj (DBIC::DebugObj->new (\$sql, \@bind) ); |
24 | $schema->storage->debug (1); |
25 | |
7a72e5a5 |
26 | my $obj; |
20595c02 |
27 | lives_ok { $obj = $rs->create ({}) } 'Default insert successful'; |
28 | |
29 | $schema->storage->debugobj ($orig_debugobj); |
30 | $schema->storage->debug ($orig_debug); |
31 | |
32 | is_same_sql_bind ( |
33 | $sql, |
34 | \@bind, |
35 | 'INSERT INTO "artist" DEFAULT VALUES', |
36 | [], |
37 | 'Default-value insert correct SQL', |
38 | ); |
7a72e5a5 |
39 | |
40 | ok ($obj, 'Insert defaults ( $rs->create ({}) )' ); |
7a72e5a5 |
41 | |
20595c02 |
42 | # this should be picked up without calling the DB again |
43 | is ($obj->artistid, $last_id + 1, 'Autoinc PK works'); |
7a72e5a5 |
44 | |
20595c02 |
45 | # for this we need to refresh |
46 | $obj->discard_changes; |
47 | is ($obj->rank, 13, 'Default value works'); |
7a72e5a5 |
48 | |
20595c02 |
49 | done_testing; |