fix default_value for MSSQL
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / dbixcsl_mssql_extra_tests.pm
CommitLineData
b1e43108 1package dbixcsl_mssql_extra_tests;
2
3use Test::More;
4
7cb9244f 5my $vendor = 'mssql';
6
7sub vendor {
8 shift;
9 $vendor = shift;
10}
11
b1e43108 12sub extra { +{
13 create => [
14 qq{
7cb9244f 15 CREATE TABLE [${vendor}_loader_test1.dot] (
b1e43108 16 id INT IDENTITY NOT NULL PRIMARY KEY,
17 dat VARCHAR(8)
18 )
19 },
5c6fb0a1 20 qq{
21 CREATE TABLE ${vendor}_loader_test2 (
22 id INT IDENTITY NOT NULL PRIMARY KEY,
23 dat VARCHAR(100) DEFAULT 'foo',
24 ts DATETIME DEFAULT getdate()
25 )
26 },
b1e43108 27 ],
5c6fb0a1 28 drop => [ "[${vendor}_loader_test1.dot]", "${vendor}_loader_test2" ],
29 count => 11,
b1e43108 30 run => sub {
31 my ($schema, $monikers, $classes) = @_;
32
d89bca78 33# Test that the table above (with '.' in name) gets loaded correctly.
7cb9244f 34 my $vendor_titlecased = "\u\L$vendor";
35
36 ok((my $rs = eval {
37 $schema->resultset("${vendor_titlecased}LoaderTest1Dot") }),
5c6fb0a1 38 'got a resultset for table with dot in name');
b1e43108 39
40 ok((my $from = eval { $rs->result_source->from }),
5c6fb0a1 41 'got an $rsrc->from for table with dot in name');
b1e43108 42
5c6fb0a1 43 is ref($from), 'SCALAR', '->table with dot in name is a scalar ref';
b1e43108 44
7cb9244f 45 is eval { $$from }, "[${vendor}_loader_test1.dot]",
5c6fb0a1 46 '->table with dot in name has correct name';
47
48# Test that column defaults are set correctly
49 ok(($rs = eval {
50 $schema->resultset("${vendor_titlecased}LoaderTest2") }),
51 'got a resultset for table with column with default value');
52
53 my $rsrc = $rs->result_source;
54
55 is eval { $rsrc->column_info('dat')->{default_value} }, 'foo',
56 'correct default_value for column with literal default';
57
58 ok((my $function_default =
59 eval { $rsrc->column_info('ts')->{default_value} }),
60 'got default_value for column with function default');
61
62 is ref($function_default), 'SCALAR',
63 'default_value for function default is a SCALAR ref';
64
65 is eval { $$function_default }, 'getdate()',
66 'default_value for function default is correct';
d89bca78 67
68# Test that identity columns do not have 'identity' in the data_type, and do
69# have is_auto_increment.
70 my $identity_col_info = $schema->resultset('LoaderTest10')
71 ->result_source->column_info('id10');
72
73 is $identity_col_info->{data_type}, 'int',
74 q{'INT IDENTITY' column has data_type => 'int'};
75
76 is $identity_col_info->{is_auto_increment}, 1,
77 q{'INT IDENTITY' column has is_auto_increment => 1};
b1e43108 78 },
79}}
80
811;