Views are automatically excluded from using insert_returning.
[dbsrgits/DBIx-Class.git] / t / 106storage_resultset_attributes.t
CommitLineData
62ed3a33 1use strict;
2use warnings;
3
4use Test::More qw/no_plan/;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8use DateTime;
9use Devel::Dwarn;
10
11my ( $dsn, $user, $pass )
12 = @ENV{ map {"DBICTEST_PG_${_}"} qw/DSN USER PASS/ };
13
14plan skip_all => <<'EOM' unless $dsn && $user;
15Set $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')
21EOM
22
23my $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
31my $flagpole = $schema->resultset('StorageFlagPole');
32is_deeply( $flagpole->result_source->resultset_attributes, { storage => { use_insert_returning => 0 }}, "My table resultset does NOT want to use insert returning");
33my $flagged_row;
34
35throws_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");
36lives_ok { $flagged_row = $flagpole->create( { id => DateTime->now, name => "My name is row." } ) } "You have to pass the id" ;
37
38lives_ok { $flagged_row->insert } "It can be inserted after you put the id";
39
40### A view
41
42my $flagview = $schema->resultset('StorageFlagPole');
43is_deeply( $flagview->result_source->resultset_attributes, { storage => { use_insert_returning => 0 }}, "Upon mere instantiation my view resultset does NOT want to use insert returning");