Commit | Line | Data |
8adac9d4 |
1 | use Test::More; |
2 | |
3 | plan tests => 4; |
4 | |
5 | use lib qw(t/lib); |
6 | |
7 | use_ok('DBICTest'); |
8 | |
9 | # add some rows inside a transaction and commit it |
7c4b64e8 |
10 | # XXX: Is storage->dbh the only way to get a dbh? |
11 | DBICTest::Artist->storage->dbh->{AutoCommit} = 0; |
8adac9d4 |
12 | for (10..15) { |
13 | DBICTest::Artist->create( { |
14 | artistid => $_, |
15 | name => "artist number $_", |
16 | } ); |
17 | } |
18 | DBICTest::Artist->dbi_commit; |
656796f2 |
19 | my ($artist) = DBICTest::Artist->find(15); |
8adac9d4 |
20 | is($artist->name, 'artist number 15', "Commit ok"); |
21 | |
22 | # repeat the test using AutoCommit = 1 to force the commit |
7c4b64e8 |
23 | DBICTest::Artist->storage->dbh->{AutoCommit} = 0; |
8adac9d4 |
24 | for (16..20) { |
25 | DBICTest::Artist->create( { |
26 | artistid => $_, |
27 | name => "artist number $_", |
28 | } ); |
29 | } |
7c4b64e8 |
30 | DBICTest::Artist->storage->dbh->{AutoCommit} = 1; |
656796f2 |
31 | ($artist) = DBICTest::Artist->find(20); |
8adac9d4 |
32 | is($artist->name, 'artist number 20', "Commit using AutoCommit ok"); |
33 | |
34 | # add some rows inside a transaction and roll it back |
7c4b64e8 |
35 | DBICTest::Artist->storage->dbh->{AutoCommit} = 0; |
8adac9d4 |
36 | for (21..30) { |
37 | DBICTest::Artist->create( { |
38 | artistid => $_, |
39 | name => "artist number $_", |
40 | } ); |
41 | } |
42 | DBICTest::Artist->dbi_rollback; |
43 | ($artist) = DBICTest::Artist->search( artistid => 25 ); |
44 | is($artist, undef, "Rollback ok"); |
45 | |