fix new rel tests for older DBIC
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / lib / dbixcsl_mssql_extra_tests.pm
1 package dbixcsl_mssql_extra_tests;
2
3 use strict;
4 use warnings;
5 use Test::More;
6 use Test::Exception;
7
8 sub extra { +{
9     create => [
10         q{
11             CREATE TABLE [mssql_loader_test1.dot] (
12                 id INT IDENTITY NOT NULL PRIMARY KEY,
13                 dat VARCHAR(8)
14             )
15         },
16         q{
17             CREATE TABLE mssql_loader_test3 (
18                 id INT IDENTITY NOT NULL PRIMARY KEY
19             )
20         },
21         q{
22             CREATE VIEW mssql_loader_test4 AS
23             SELECT * FROM mssql_loader_test3
24         },
25     ],
26     pre_drop_ddl => [
27         'CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)',
28         'DROP VIEW mssql_loader_test4',
29     ],
30     drop   => [
31         '[mssql_loader_test1.dot]',
32         'mssql_loader_test3'
33     ],
34     count  => 8,
35     run    => sub {
36         my ($schema, $monikers, $classes) = @_;
37
38 # Test that the table above (with '.' in name) gets loaded correctly.
39         ok((my $rs = eval {
40             $schema->resultset($monikers->{'[mssql_loader_test1.dot]'}) }),
41             'got a resultset for table with dot in name');
42
43         ok((my $from = eval { $rs->result_source->from }),
44             'got an $rsrc->from for table with dot in name');
45
46         is ref($from), 'SCALAR', '->table with dot in name is a scalar ref';
47
48         is eval { $$from }, "[mssql_loader_test1.dot]",
49             '->table with dot in name has correct name';
50
51 # Test that identity columns do not have 'identity' in the data_type, and do
52 # have is_auto_increment.
53         my $identity_col_info = $schema->resultset($monikers->{loader_test10})
54             ->result_source->column_info('id10');
55
56         is $identity_col_info->{data_type}, 'int',
57             q{'INT IDENTITY' column has data_type => 'int'};
58
59         is $identity_col_info->{is_auto_increment}, 1,
60             q{'INT IDENTITY' column has is_auto_increment => 1};
61
62 # Test that a bad view (where underlying table is gone) is ignored.
63         my $dbh = $schema->storage->dbh;
64         $dbh->do("DROP TABLE mssql_loader_test3");
65
66         my @warnings;
67         {
68             local $SIG{__WARN__} = sub { push @warnings, $_[0] };
69             $schema->rescan;
70         }
71         ok ((grep /^Bad table or view 'mssql_loader_test4'/, @warnings),
72             'bad view ignored');
73
74         throws_ok {
75             $schema->resultset($monikers->{mssql_loader_test4})
76         } qr/Can't find source/,
77             'no source registered for bad view';
78     },
79 }}
80
81 1;