Commit | Line | Data |
b1e43108 |
1 | package dbixcsl_mssql_extra_tests; |
2 | |
3 | use Test::More; |
4 | |
7cb9244f |
5 | my $vendor = 'mssql'; |
6 | |
7 | sub vendor { |
8 | shift; |
9 | $vendor = shift; |
10 | } |
11 | |
b1e43108 |
12 | sub 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', |
1f625792 |
24 | num NUMERIC DEFAULT 10.89, |
25 | anint INT DEFAULT 6, |
5c6fb0a1 |
26 | ts DATETIME DEFAULT getdate() |
27 | ) |
28 | }, |
b1e43108 |
29 | ], |
5c6fb0a1 |
30 | drop => [ "[${vendor}_loader_test1.dot]", "${vendor}_loader_test2" ], |
1f625792 |
31 | count => 13, |
b1e43108 |
32 | run => sub { |
33 | my ($schema, $monikers, $classes) = @_; |
34 | |
d89bca78 |
35 | # Test that the table above (with '.' in name) gets loaded correctly. |
7cb9244f |
36 | my $vendor_titlecased = "\u\L$vendor"; |
37 | |
38 | ok((my $rs = eval { |
39 | $schema->resultset("${vendor_titlecased}LoaderTest1Dot") }), |
5c6fb0a1 |
40 | 'got a resultset for table with dot in name'); |
b1e43108 |
41 | |
42 | ok((my $from = eval { $rs->result_source->from }), |
5c6fb0a1 |
43 | 'got an $rsrc->from for table with dot in name'); |
b1e43108 |
44 | |
5c6fb0a1 |
45 | is ref($from), 'SCALAR', '->table with dot in name is a scalar ref'; |
b1e43108 |
46 | |
7cb9244f |
47 | is eval { $$from }, "[${vendor}_loader_test1.dot]", |
5c6fb0a1 |
48 | '->table with dot in name has correct name'; |
49 | |
50 | # Test that column defaults are set correctly |
51 | ok(($rs = eval { |
52 | $schema->resultset("${vendor_titlecased}LoaderTest2") }), |
53 | 'got a resultset for table with column with default value'); |
54 | |
55 | my $rsrc = $rs->result_source; |
56 | |
57 | is eval { $rsrc->column_info('dat')->{default_value} }, 'foo', |
1f625792 |
58 | 'correct default_value for column with literal string default'; |
59 | |
60 | is eval { $rsrc->column_info('anint')->{default_value} }, 6, |
61 | 'correct default_value for column with literal integer default'; |
62 | |
63 | cmp_ok eval { $rsrc->column_info('num')->{default_value} }, |
64 | '==', 10.89, |
65 | 'correct default_value for column with literal numeric default'; |
5c6fb0a1 |
66 | |
67 | ok((my $function_default = |
68 | eval { $rsrc->column_info('ts')->{default_value} }), |
69 | 'got default_value for column with function default'); |
70 | |
71 | is ref($function_default), 'SCALAR', |
72 | 'default_value for function default is a SCALAR ref'; |
73 | |
74 | is eval { $$function_default }, 'getdate()', |
75 | 'default_value for function default is correct'; |
d89bca78 |
76 | |
77 | # Test that identity columns do not have 'identity' in the data_type, and do |
78 | # have is_auto_increment. |
79 | my $identity_col_info = $schema->resultset('LoaderTest10') |
80 | ->result_source->column_info('id10'); |
81 | |
82 | is $identity_col_info->{data_type}, 'int', |
83 | q{'INT IDENTITY' column has data_type => 'int'}; |
84 | |
85 | is $identity_col_info->{is_auto_increment}, 1, |
86 | q{'INT IDENTITY' column has is_auto_increment => 1}; |
b1e43108 |
87 | }, |
88 | }} |
89 | |
90 | 1; |