Fix view ordering by requiring ddo declaration in result class
[dbsrgits/DBIx-Class-ResultSource-MultipleTableInheritance.git] / t / 03insert.t
CommitLineData
2c296bdb 1use strict;
2use warnings;
3use lib 't/lib';
4use Test::More qw(no_plan);
5use Test::Exception;
4eaa25b5 6use CafeInsertion;
c965b761 7use Devel::Dwarn;
2c296bdb 8
9BEGIN {
ebcd7e95 10 $ENV{DBIC_TRACE} = 0;
2c296bdb 11}
4eaa25b5 12
32098147 13my ( $dsn, $user, $pass )
14 = @ENV{ map {"DBICTEST_PG_${_}"} qw/DSN USER PASS/ };
15plan skip_all => <<'EOM' unless $dsn && $user;
16Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test
17( NOTE: This test drops and creates some tables.')
18EOM
19
4eaa25b5 20my $schema = CafeInsertion->connect( $dsn, $user, $pass );
2c296bdb 21$schema->storage->ensure_connected;
22$schema->storage->_use_insert_returning(0);
c965b761 23$schema->storage->dbh->{Warn} = 0;
ebcd7e95 24
25my $dir = "t/sql"; # tempdir(CLEANUP => 0);
26$schema->create_ddl_dir( ['PostgreSQL'], 0.1, $dir );
27$schema->deploy( { add_drop_table => 1, add_drop_view => 1 } );
28
2c296bdb 29isa_ok(
30 $schema->source('Sumatra'),
31 'DBIx::Class::ResultSource::View',
32 "My MTI class also"
33);
34
35my ( $drink, $drink1 );
36
37lives_ok {
c965b761 38 $drink = $schema->resultset('Sumatra')->create(
39 { sweetness => 4,
40 fat_free => 1,
41 aroma => 'earthy',
42 flavor => 'great'
43 }
44 );
2c296bdb 45}
46"I can call a create on a view sumatra";
47
48lives_ok {
49 $drink1 = $schema->resultset('Coffee')->create( { flavor => 'aaight', } );
50}
51"I can do it for the other view, too";
e96b2eeb 52
3365fc70 53my $sqlt_object = $schema->{sqlt};
3365fc70 54is_deeply(
55 [ map { $_->name } $sqlt_object->get_views ],
56 [ qw/
c965b761 57 coffee
3365fc70 58 sumatra
59 /
60 ],
61 "SQLT view order triumphantly matches our order."
62);
63