Only normalize conditions during resolution time, instead on every ->search
[dbsrgits/DBIx-Class.git] / t / 18insert_default.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use DBICTest;
9
10 my $schema = DBICTest->init_schema();
11 $schema->storage->sql_maker->quote_char('"');
12
13 my $rs = $schema->resultset ('Artist');
14 my $last_obj = $rs->search ({}, { order_by => { -desc => 'artistid' }, rows => 1})->single;
15 my $last_id = $last_obj ? $last_obj->artistid : 0;
16
17 my $obj;
18 $schema->is_executed_sql_bind( sub {
19   $obj = $rs->create ({})
20 }, [[
21   'INSERT INTO "artist" DEFAULT VALUES'
22 ]], 'Default-value insert correct SQL' );
23
24 ok ($obj, 'Insert defaults ( $rs->create ({}) )' );
25
26 # this should be picked up without calling the DB again
27 is ($obj->artistid, $last_id + 1, 'Autoinc PK works');
28
29 # for this we need to refresh
30 $obj->discard_changes;
31 is ($obj->rank, 13, 'Default value works');
32
33 done_testing;