rename _relnames_and_methods to _relnames_and_method in RelBuilder
[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,
21 "value" VARCHAR(100)
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 },
34 # Wordy, newline-heavy SQL to stress the regexes
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 },
8763ffda 46 ],
68d650df 47 drop => [ qw/extra_loader_test1 extra_loader_test2 extra_loader_test3 extra_loader_test4 / ],
48 count => 5,
8763ffda 49 run => sub {
50 my ($schema, $monikers, $classes) = @_;
a78e3fed 51
8763ffda 52 ok ((my $rs = $schema->resultset($monikers->{extra_loader_test1})),
53 'resultset for quoted table');
54
55 is_deeply [ $rs->result_source->columns ], [ qw/id value/ ],
56 'retrieved quoted column names from quoted table';
68d650df 57
58 ok ((my $source = $schema->source($monikers->{extra_loader_test4})),
59 'verbose table');
60
61 is_deeply [ $source->primary_columns ], [ qw/event_id person_id/ ],
62 'composite primary key';
63
68d650df 64 is ($source->relationships, 2,
65 '2 foreign key constraints found');
66
8763ffda 67 },
68 },
69);
70
71$tester->run_tests();
a78e3fed 72
73END {
74 unlink './t/sqlite_test';
75}