Commit | Line | Data |
70955816 |
1 | use strict; |
2 | use warnings; |
3 | use lib 't/lib'; |
4 | use Test::More qw(no_plan); |
5 | use Test::Exception; |
4eaa25b5 |
6 | use NoSequenceSalad; |
d8c2caa7 |
7 | use Devel::Dwarn; |
70955816 |
8 | |
9 | BEGIN { |
d8c2caa7 |
10 | $ENV{DBIC_TRACE} = 0; |
70955816 |
11 | } |
32098147 |
12 | my ( $dsn, $user, $pass ) |
13 | = @ENV{ map {"DBICTEST_PG_${_}"} qw/DSN USER PASS/ }; |
14 | |
15 | plan skip_all => <<'EOM' unless $dsn && $user; |
16 | Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test |
17 | ( NOTE: This test drops and creates some tables.') |
18 | EOM |
19 | |
4eaa25b5 |
20 | my $schema = NoSequenceSalad->connect( $dsn, $user, $pass ); |
70955816 |
21 | $schema->storage->ensure_connected; |
d8c2caa7 |
22 | $schema->storage->dbh->{Warn} = 0; |
70955816 |
23 | $schema->storage->_use_insert_returning(0); |
24 | |
25 | my $dir = "t/sql"; # tempdir(CLEANUP => 0); |
26 | $schema->create_ddl_dir( ['PostgreSQL'], 0.1, $dir ); |
d8c2caa7 |
27 | |
28 | lives_ok { $schema->deploy( { add_drop_table => 1, add_drop_view => 1 } ) } |
29 | "I can deploy the schema"; |
70955816 |
30 | |
31 | isa_ok( |
32 | $schema->source('Mesclun'), |
33 | 'DBIx::Class::ResultSource::View', |
34 | "My MTI class also" |
35 | ); |
36 | |
37 | my ( $bowl_of_salad, $bowl_of_salad1 ); |
38 | |
39 | lives_ok { |
40 | $bowl_of_salad = $schema->resultset('Mesclun') |
d8c2caa7 |
41 | ->create( { acidity => 4, spiciness => '10', fresh => 0, } ); |
70955816 |
42 | } |
43 | "I can call a create on a view mesclun"; |
44 | |
45 | lives_ok { |
46 | $bowl_of_salad1 = $schema->resultset('Salad')->create( { fresh => 1 } ); |
47 | } |
48 | "I can do it for the other view, too"; |
49 | |
c965b761 |
50 | my $sqlt_object = $schema->{sqlt}; |
d8c2caa7 |
51 | |
52 | #diag Dwarn $sqlt_object; |
c965b761 |
53 | is_deeply( |
54 | [ map { $_->name } $sqlt_object->get_views ], |
55 | [ qw/ |
d8c2caa7 |
56 | salad |
c965b761 |
57 | mesclun |
58 | / |
59 | ], |
60 | "SQLT view order triumphantly matches our order." |
61 | ); |