enable some formerly optional rel tests, add is_nullable extra test for SQLite
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10sqlite_common.t
index 7208977..2996738 100644 (file)
@@ -1,22 +1,79 @@
 use strict;
-use lib qw( ./t );
-use dbixcl_common_tests;
+use Test::More;
+use lib qw(t/lib);
+use dbixcsl_common_tests;
 
 eval { require DBD::SQLite };
 my $class = $@ ? 'SQLite2' : 'SQLite';
 
-{
-    my $tester = dbixcl_common_tests->new(
-        vendor          => 'SQLite',
-        auto_inc_pk     => 'INTEGER NOT NULL PRIMARY KEY',
-        dsn             => "dbi:$class:dbname=./t/sqlite_test",
-        user            => '',
-        password        => '',
-        multi_fk_broken => 1,
-    );
-
-    $tester->run_tests();
-}
+my $tester = dbixcsl_common_tests->new(
+    vendor          => 'SQLite',
+    auto_inc_pk     => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',
+    dsn             => "dbi:$class:dbname=./t/sqlite_test",
+    user            => '',
+    password        => '',
+    extra           => {
+        create => [
+            # 'sqlite_' is reserved, so we use 'extra_'
+            q{
+                CREATE TABLE "extra_loader_test1" (
+                    "id" NOT NULL PRIMARY KEY,
+                    "value" VARCHAR(100) NOT NULL
+                )
+            },
+            q{
+                CREATE TABLE extra_loader_test2 (
+                    event_id INTEGER PRIMARY KEY
+                )
+            },
+            q{
+                CREATE TABLE extra_loader_test3 (
+                    person_id INTEGER PRIMARY KEY
+                )
+            },
+            # Wordy, newline-heavy SQL to stress the regexes
+            q{
+                CREATE TABLE extra_loader_test4 (
+                    event_id INTEGER NOT NULL
+                        CONSTRAINT fk_event_id
+                        REFERENCES extra_loader_test2(event_id),
+                    person_id INTEGER NOT NULL
+                        CONSTRAINT fk_person_id
+                        REFERENCES extra_loader_test3 (person_id),
+                    PRIMARY KEY (event_id, person_id)
+                )
+            },
+        ],
+        drop  => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ],
+        count => 7,
+        run   => sub {
+            my ($schema, $monikers, $classes) = @_;
+
+            ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})),
+                'resultset for quoted table');
+
+            ok ((my $source = $rs->result_source), 'source');
+
+            is_deeply [ $source->columns ], [ qw/id value/ ],
+                'retrieved quoted column names from quoted table';
+
+            is $source->column_info('value')->{is_nullable}, 0,
+                'is_nullable detection';
+
+            ok (($source = $schema->source($monikers->{extra_loader_test4})),
+                'verbose table');
+
+            is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ],
+                'composite primary key';
+
+            is ($source->relationships, 2,
+                '2 foreign key constraints found');
+
+        },
+    },
+);
+
+$tester->run_tests();
 
 END {
     unlink './t/sqlite_test';