Heray-Was-Here
Server : Apache
System : Linux vps103298.mylogin.co 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : calvet ( 273824)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /usr/share/doc/perl-DBIx-Class/t/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/perl-DBIx-Class/t/18insert_default.t
use strict;
use warnings;

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

my $schema = DBICTest->init_schema();
$schema->storage->sql_maker->quote_char('"');

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;
$schema->is_executed_sql_bind( sub {
  $obj = $rs->create ({})
}, [[
  'INSERT INTO "artist" DEFAULT VALUES'
]], 'Default-value insert correct SQL' );

ok ($obj, 'Insert defaults ( $rs->create ({}) )' );

# 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');

done_testing;

Hry