Merge 'current' into 'mssql_tweaks'
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 17mssql_dot_in_table_name.t
1 use strict;
2 use lib qw(t/lib);
3 use Test::More;
4 use DBI;
5
6 my $DUMP_DIR;
7 BEGIN { 
8     $DUMP_DIR = './t/_common_dump';
9 }
10
11 use lib $DUMP_DIR;
12 use DBIx::Class::Schema::Loader 'make_schema_at', "dump_to_dir:$DUMP_DIR";
13 use File::Path;
14
15 my $dsn      = $ENV{DBICTEST_MSSQL_ODBC_DSN}  ||
16                $ENV{DBICTEST_MSSQL_DSN}  || '';
17
18 my $user     = $ENV{DBICTEST_MSSQL_ODBC_USER} ||
19                $ENV{DBICTEST_MSSQL_USER} || '';
20
21 my $password = $ENV{DBICTEST_MSSQL_ODBC_PASS} ||
22                $ENV{DBICTEST_MSSQL_PASS} || '';
23
24 if( !$dsn || !$user ) {
25     plan skip_all =>
26 'You need to set the DBICTEST_MSSQL_ODBC_DSN (or DBICTEST_MSSQL_DSN), _USER,' .
27 ' and _PASS environment variables';
28     exit;
29 }
30
31 plan tests => 3;
32
33 my $dbh = DBI->connect($dsn, $user, $password, {
34     RaiseError => 1, PrintError => 0
35 });
36
37 eval { $dbh->do('DROP TABLE [loadertest.dot]') };
38 $dbh->do(q{
39     CREATE TABLE [loadertest.dot] (
40         id INT IDENTITY NOT NULL PRIMARY KEY,
41         dat VARCHAR(8)
42     )
43 });
44
45 rmtree $DUMP_DIR;
46
47 eval {
48     make_schema_at(
49         'TestSL::Schema', 
50         {
51             use_namespaces => 1,
52             constraint => qr/^loadertest\.dot\z/
53         },
54         [ $dsn, $user, $password, ]
55     );
56 };
57
58 ok !$@, 'table name with . parsed correctly';
59 diag $@ if $@;
60
61 #system qq{$^X -pi -e 's/"test\.dot"/\\\\"[loadertest.dot]"/' t/_common_dump/TestSL/Schema/Result/TestDot.pm};
62 #diag do { local ($/, @ARGV) = (undef, "t/_common_dump/TestSL/Schema/Result/TestDot.pm"); <> };
63 #do "t/_common_dump/TestSL/Schema/Result/TestDot.pm";
64
65 eval 'use TestSL::Schema';
66 ok !$@, 'loaded schema';
67 diag $@ if $@;
68
69 TODO: {
70     local $TODO = q{this is really a DBIC test to check if the table is usable,
71 and it doesn't work in the released version yet};
72
73     eval {
74         my $rs = TestSL::Schema->resultset('LoadertestDot');
75         my $row = $rs->create({ dat => 'foo' });
76         $row->update({ dat => 'bar' });
77         $row = $rs->find($row->id);
78         $row->delete;
79     };
80     ok !$@, 'used table from DBIC succeessfully';
81     diag $@ if $@;
82 }
83
84 rmtree $DUMP_DIR;
85
86 $dbh->do('DROP TABLE [loadertest.dot]');