cleanup t/23dumpmore.t
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 10sqlite_common.t
CommitLineData
a78e3fed 1use strict;
8763ffda 2use Test::More;
c2849787 3use lib qw(t/lib);
fbd83464 4use dbixcsl_common_tests;
a78e3fed 5
6eval { require DBD::SQLite };
7my $class = $@ ? 'SQLite2' : 'SQLite';
8
8763ffda 9my $tester = dbixcsl_common_tests->new(
10 vendor => 'SQLite',
11 auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT',
12 dsn => "dbi:$class:dbname=./t/sqlite_test",
13 user => '',
14 password => '',
15 extra => {
16 create => [
17 # 'sqlite_' is reserved, so we use 'extra_'
18 q{
19 CREATE TABLE "extra_loader_test1" (
20 "id" NOT NULL PRIMARY KEY,
2a6dfbc9 21 "value" TEXT UNIQUE NOT NULL
8763ffda 22 )
68d650df 23 },
24 q{
25 CREATE TABLE extra_loader_test2 (
26 event_id INTEGER PRIMARY KEY
27 )
28 },
29 q{
30 CREATE TABLE extra_loader_test3 (
31 person_id INTEGER PRIMARY KEY
32 )
33 },
26da4cc3 34 # Wordy, newline-heavy SQL
68d650df 35 q{
36 CREATE TABLE extra_loader_test4 (
37 event_id INTEGER NOT NULL
38 CONSTRAINT fk_event_id
39 REFERENCES extra_loader_test2(event_id),
40 person_id INTEGER NOT NULL
41 CONSTRAINT fk_person_id
42 REFERENCES extra_loader_test3 (person_id),
43 PRIMARY KEY (event_id, person_id)
44 )
45 },
26da4cc3 46 # make sure views are picked up
47 q{
48 CREATE VIEW extra_loader_test5 AS SELECT * FROM extra_loader_test4
49 }
8763ffda 50 ],
26da4cc3 51 pre_drop_ddl => [ 'DROP VIEW extra_loader_test5' ],
68d650df 52 drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ],
bf558f72 53 count => 9,
8763ffda 54 run => sub {
55 my ($schema, $monikers, $classes) = @_;
a78e3fed 56
8763ffda 57 ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})),
58 'resultset for quoted table');
59
0fa48bf5 60 ok ((my $source = $rs->result_source), 'source');
61
62 is_deeply [ $source->columns ], [ qw/id value/ ],
8763ffda 63 'retrieved quoted column names from quoted table';
68d650df 64
3b134b29 65 ok ((exists $source->column_info('value')->{is_nullable}),
66 'is_nullable exists');
67
0fa48bf5 68 is $source->column_info('value')->{is_nullable}, 0,
3b134b29 69 'is_nullable is set correctly';
0fa48bf5 70
71 ok (($source = $schema->source($monikers->{extra_loader_test4})),
68d650df 72 'verbose table');
73
74 is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ],
75 'composite primary key';
76
68d650df 77 is ($source->relationships, 2,
78 '2 foreign key constraints found');
79
bf558f72 80 # test that columns for views are picked up
81 is $schema->resultset($monikers->{extra_loader_test5})->result_source->column_info('person_id')->{data_type}, 'INTEGER',
82 'columns for views are introspected';
8763ffda 83 },
84 },
85);
86
87$tester->run_tests();
a78e3fed 88
89END {
90 unlink './t/sqlite_test';
91}