Commit | Line | Data |
62ed3a33 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More qw/no_plan/; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | use DateTime; |
9 | use Devel::Dwarn; |
10 | |
11 | my ( $dsn, $user, $pass ) |
12 | = @ENV{ map {"DBICTEST_PG_${_}"} qw/DSN USER PASS/ }; |
13 | |
14 | plan skip_all => <<'EOM' unless $dsn && $user; |
15 | Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test |
16 | ( NOTE: This test drops and creates tables called 'artist', 'cd', |
17 | 'timestamp_primary_key_test', 'track', 'casecheck', 'array_test' and |
18 | 'sequence_test' as well as following sequences: 'pkid1_seq', 'pkid2_seq' and |
19 | 'nonpkid_seq'. as well as following schemas: 'dbic_t_schema', |
20 | 'dbic_t_schema_2', 'dbic_t_schema_3', 'dbic_t_schema_4', and 'dbic_t_schema_5') |
21 | EOM |
22 | |
23 | my $schema = DBICTest::Schema->connect( $dsn, $user, $pass ); |
24 | $schema->storage->dbh->{Warn} = 0; |
25 | |
26 | $schema->deploy( { add_drop_table => 1, add_drop_view => 1, debug => 0 } ); |
27 | |
28 | |
29 | ### A table |
30 | |
31 | my $flagpole = $schema->resultset('StorageFlagPole'); |
32 | is_deeply( $flagpole->result_source->resultset_attributes, { storage => { use_insert_returning => 0 }}, "My table resultset does NOT want to use insert returning"); |
33 | my $flagged_row; |
34 | |
35 | throws_ok(sub { $flagged_row = $flagpole->create( { name => "My name is row." } ) }, qr/no sequence found for storage_flag_pole.id/, "Without insert_returning, insert throws a no-sequence defined error because the PK is not autoinc"); |
36 | lives_ok { $flagged_row = $flagpole->create( { id => DateTime->now, name => "My name is row." } ) } "You have to pass the id" ; |
37 | |
38 | lives_ok { $flagged_row->insert } "It can be inserted after you put the id"; |
39 | |
40 | ### A view |
41 | |
42 | my $flagview = $schema->resultset('StorageFlagPole'); |
43 | is_deeply( $flagview->result_source->resultset_attributes, { storage => { use_insert_returning => 0 }}, "Upon mere instantiation my view resultset does NOT want to use insert returning"); |