Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / 748informix.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
cb551b07 2use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_rdbms_informix';
3
835cdc8d 4use strict;
5use warnings;
6
7use Test::More;
8use Test::Exception;
c0329273 9
835cdc8d 10use DBICTest;
11
12my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_INFORMIX_${_}" } qw/DSN USER PASS/};
13
9fb04139 14my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {
15 auto_savepoint => 1
16});
835cdc8d 17
18my $dbh = $schema->storage->dbh;
19
20eval { $dbh->do("DROP TABLE artist") };
835cdc8d 21$dbh->do("CREATE TABLE artist (artistid SERIAL, name VARCHAR(255), charfield CHAR(10), rank INTEGER DEFAULT 13);");
d3774d9b 22eval { $dbh->do("DROP TABLE cd") };
23$dbh->do(<<EOS);
24CREATE TABLE cd (
25 cdid int PRIMARY KEY,
26 artist int,
27 title varchar(255),
28 year varchar(4),
29 genreid int,
30 single_track int
31)
32EOS
33eval { $dbh->do("DROP TABLE track") };
34$dbh->do(<<EOS);
35CREATE TABLE track (
36 trackid int,
37 cd int REFERENCES cd(cdid),
38 position int,
39 title varchar(255),
40 last_updated_on date,
41 last_updated_at date,
42 small_dt date
43)
44EOS
835cdc8d 45
46my $ars = $schema->resultset('Artist');
47is ( $ars->count, 0, 'No rows at first' );
48
49# test primary key handling
50my $new = $ars->create({ name => 'foo' });
51ok($new->artistid, "Auto-PK worked");
52
53# test explicit key spec
54$new = $ars->create ({ name => 'bar', artistid => 66 });
55is($new->artistid, 66, 'Explicit PK worked');
56$new->discard_changes;
57is($new->artistid, 66, 'Explicit PK assigned');
58
59# test populate
60lives_ok (sub {
61 my @pop;
62 for (1..2) {
63 push @pop, { name => "Artist_$_" };
64 }
65 $ars->populate (\@pop);
66});
67
68# test populate with explicit key
69lives_ok (sub {
70 my @pop;
71 for (1..2) {
72 push @pop, { name => "Artist_expkey_$_", artistid => 100 + $_ };
73 }
74 $ars->populate (\@pop);
75});
76
77# count what we did so far
78is ($ars->count, 6, 'Simple count works');
79
80# test LIMIT support
81my $lim = $ars->search( {},
82 {
83 rows => 3,
84 offset => 4,
85 order_by => 'artistid'
86 }
87);
88is( $lim->count, 2, 'ROWS+OFFSET count ok' );
89is( $lim->all, 2, 'Number of ->all objects matches count' );
90
91# test iterator
92$lim->reset;
93is( $lim->next->artistid, 101, "iterator->next ok" );
94is( $lim->next->artistid, 102, "iterator->next ok" );
95is( $lim->next, undef, "next past end of resultset ok" );
96
9fb04139 97# test savepoints
b9889595 98throws_ok {
9fb04139 99 $schema->txn_do(sub {
100 eval {
101 $schema->txn_do(sub {
102 $ars->create({ name => 'in_savepoint' });
103 die "rolling back savepoint";
104 });
105 };
106 ok ((not $ars->search({ name => 'in_savepoint' })->first),
107 'savepoint rolled back');
108 $ars->create({ name => 'in_outer_txn' });
109 die "rolling back outer txn";
110 });
b9889595 111} qr/rolling back outer txn/,
9fb04139 112 'correct exception for rollback';
113
114ok ((not $ars->search({ name => 'in_outer_txn' })->first),
115 'outer txn rolled back');
835cdc8d 116
d3774d9b 117######## test with_deferred_fk_checks
118lives_ok {
119 $schema->storage->with_deferred_fk_checks(sub {
120 $schema->resultset('Track')->create({
121 trackid => 999, cd => 999, position => 1, title => 'deferred FK track'
122 });
123 $schema->resultset('CD')->create({
124 artist => 1, cdid => 999, year => '2003', title => 'deferred FK cd'
125 });
126 });
127} 'with_deferred_fk_checks code survived';
128
129is eval { $schema->resultset('Track')->find(999)->title }, 'deferred FK track',
8273e845 130 'code in with_deferred_fk_checks worked';
d3774d9b 131
132throws_ok {
133 $schema->resultset('Track')->create({
134 trackid => 1, cd => 9999, position => 1, title => 'Track1'
135 });
136} qr/constraint/i, 'with_deferred_fk_checks is off';
137
835cdc8d 138done_testing;
139
140# clean up our mess
141END {
65d35121 142 my $dbh = eval { $schema->storage->_dbh };
143 $dbh->do("DROP TABLE artist") if $dbh;
144 undef $schema;
835cdc8d 145}