Quote table name when inserting DEFAULT VALUES
[dbsrgits/DBIx-Class.git] / t / 18insert_default.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Exception;
6 use lib qw(t/lib);
7 use DBICTest;
8 use DBIC::DebugObj;
9 use DBIC::SqlMakerTest;
10
11 my $schema = DBICTest->init_schema();
12 $schema->storage->sql_maker->quote_char('"');
13
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
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
26 my $obj;
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 );
39
40 ok ($obj, 'Insert defaults ( $rs->create ({}) )' );
41
42 # this should be picked up without calling the DB again
43 is ($obj->artistid, $last_id + 1, 'Autoinc PK works');
44
45 # for this we need to refresh
46 $obj->discard_changes;
47 is ($obj->rank, 13, 'Default value works');
48
49 done_testing;