Release 0.02
[dbsrgits/DBIx-Class-ResultSource-MultipleTableInheritance.git] / t / 02view_def.t
1 use strict;
2 use warnings;
3 use lib 't/lib';
4 use File::Temp;
5 use Test::More tests => 5;
6 use Test::Exception;
7 use LoadTest;
8
9 BEGIN {
10     $ENV{DBIC_TRACE} = 0;
11 }
12
13 my ( $dsn, $user, $pass )
14     = @ENV{ map {"DBICTEST_PG_${_}"} qw/DSN USER PASS/ };
15
16 plan skip_all => <<'EOM' unless $dsn && $user;
17 Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test
18 ( NOTE: This test drops and creates some tables.')
19 EOM
20
21 dies_ok { LoadTest->source('Foo')->view_definition }
22 "Can't generate view def without connected schema";
23
24 my $schema = LoadTest->connect( $dsn, $user, $pass );
25 $schema->storage->ensure_connected;
26 $schema->storage->dbh->{Warn} = 0;
27
28 my $dir = "t/sql";    # tempdir(CLEANUP => 0);
29
30 lives_ok { $schema->create_ddl_dir( ['PostgreSQL'], 0.1, $dir ) }
31 "It's OK to create_ddl_dir";
32 lives_ok {
33     $schema->deploy( { add_drop_table => 1, add_drop_view => 1, } );
34 }
35 "It's also OK to deploy the schema";
36
37 isa_ok(
38     $schema->source('Bar'),
39     'DBIx::Class::ResultSource::View',
40     "My MTI class also"
41 );
42
43 my $sqlt_object = $schema->{sqlt};
44
45 is_deeply(
46     [ map { $_->name } $sqlt_object->get_views ],
47     [   qw/
48             foo
49             bar
50             /
51     ],
52     "SQLT view order triumphantly matches our order."
53 );
54