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