redo AUTHOR sections to have one main CONTRIBUTORS section
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / dbixcsl_mssql_extra_tests.pm
1 package dbixcsl_mssql_extra_tests;
2
3 use Test::More;
4
5 my $vendor = 'mssql';
6
7 sub vendor {
8     shift;
9     $vendor = shift;
10 }
11
12 sub extra { +{
13     create => [
14         qq{
15             CREATE TABLE [${vendor}_loader_test1.dot] (
16                 id INT IDENTITY NOT NULL PRIMARY KEY,
17                 dat VARCHAR(8)
18             )
19         },
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         },
27     ],
28     drop   => [ "[${vendor}_loader_test1.dot]", "${vendor}_loader_test2"  ],
29     count  => 11,
30     run    => sub {
31         my ($schema, $monikers, $classes) = @_;
32
33 # Test that the table above (with '.' in name) gets loaded correctly.
34         my $vendor_titlecased = "\u\L$vendor";
35
36         ok((my $rs = eval {
37             $schema->resultset("${vendor_titlecased}LoaderTest1Dot") }),
38             'got a resultset for table with dot in name');
39
40         ok((my $from = eval { $rs->result_source->from }),
41             'got an $rsrc->from for table with dot in name');
42
43         is ref($from), 'SCALAR', '->table with dot in name is a scalar ref';
44
45         is eval { $$from }, "[${vendor}_loader_test1.dot]",
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';
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};
78     },
79 }}
80
81 1;