Commit | Line | Data |
b1e43108 |
1 | package dbixcsl_mssql_extra_tests; |
2 | |
80a212f5 |
3 | use strict; |
4 | use warnings; |
b1e43108 |
5 | use Test::More; |
d073740e |
6 | use Test::Exception; |
b1e43108 |
7 | |
d073740e |
8 | # for cleanup in END |
80a212f5 |
9 | my $storage; |
d073740e |
10 | |
b1e43108 |
11 | sub extra { +{ |
12 | create => [ |
80a212f5 |
13 | q{ |
14 | CREATE TABLE [mssql_loader_test1.dot] ( |
b1e43108 |
15 | id INT IDENTITY NOT NULL PRIMARY KEY, |
16 | dat VARCHAR(8) |
17 | ) |
18 | }, |
80a212f5 |
19 | q{ |
20 | CREATE TABLE mssql_loader_test3 ( |
d073740e |
21 | id INT IDENTITY NOT NULL PRIMARY KEY |
22 | ) |
23 | }, |
80a212f5 |
24 | q{ |
25 | CREATE VIEW mssql_loader_test4 AS |
26 | SELECT * FROM mssql_loader_test3 |
d073740e |
27 | }, |
28 | ], |
29 | drop => [ |
80a212f5 |
30 | "[mssql_loader_test1.dot]", |
31 | "mssql_loader_test3" |
b1e43108 |
32 | ], |
80a212f5 |
33 | count => 8, |
b1e43108 |
34 | run => sub { |
35 | my ($schema, $monikers, $classes) = @_; |
36 | |
d89bca78 |
37 | # Test that the table above (with '.' in name) gets loaded correctly. |
7cb9244f |
38 | ok((my $rs = eval { |
80a212f5 |
39 | $schema->resultset($monikers->{'[mssql_loader_test1.dot]'}) }), |
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 | |
80a212f5 |
47 | is eval { $$from }, "[mssql_loader_test1.dot]", |
5c6fb0a1 |
48 | '->table with dot in name has correct name'; |
49 | |
d89bca78 |
50 | # Test that identity columns do not have 'identity' in the data_type, and do |
51 | # have is_auto_increment. |
80a212f5 |
52 | my $identity_col_info = $schema->resultset($monikers->{loader_test10}) |
d89bca78 |
53 | ->result_source->column_info('id10'); |
54 | |
55 | is $identity_col_info->{data_type}, 'int', |
56 | q{'INT IDENTITY' column has data_type => 'int'}; |
57 | |
58 | is $identity_col_info->{is_auto_increment}, 1, |
59 | q{'INT IDENTITY' column has is_auto_increment => 1}; |
d073740e |
60 | |
61 | # Test that a bad view (where underlying table is gone) is ignored. |
80a212f5 |
62 | $storage = $schema->storage; |
63 | |
64 | my $dbh = $storage->dbh; |
65 | $dbh->do("DROP TABLE mssql_loader_test3"); |
d073740e |
66 | |
67 | my @warnings; |
68 | { |
69 | local $SIG{__WARN__} = sub { push @warnings, $_[0] }; |
70 | $schema->rescan; |
71 | } |
80a212f5 |
72 | ok ((grep /^Bad table or view 'mssql_loader_test4'/, @warnings), |
d073740e |
73 | 'bad view ignored'); |
74 | |
75 | throws_ok { |
80a212f5 |
76 | $schema->resultset($monikers->{mssql_loader_test4}) |
d073740e |
77 | } qr/Can't find source/, |
78 | 'no source registered for bad view'; |
b1e43108 |
79 | }, |
80 | }} |
81 | |
80a212f5 |
82 | # Clean up the bad view |
d073740e |
83 | END { |
84 | local $@; |
85 | eval { |
80a212f5 |
86 | my $dbh = $storage->dbh; |
87 | $dbh->do($_) for ( |
88 | "CREATE TABLE mssql_loader_test3 (id INT IDENTITY NOT NULL PRIMARY KEY)", |
89 | "DROP VIEW mssql_loader_test4", |
90 | "DROP TABLE mssql_loader_test3", |
d073740e |
91 | ); |
92 | }; |
93 | } |
94 | |
b1e43108 |
95 | 1; |