Renamed DBIx::Class::PK's retrieve() as find()
[dbsrgits/DBIx-Class.git] / t / 04db.t
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
10 # XXX: Is storage->dbh the only way to get a dbh?
11 DBICTest::Artist->storage->dbh->{AutoCommit} = 0;
12 for (10..15) {
13     DBICTest::Artist->create( { 
14         artistid => $_,
15         name => "artist number $_",
16     } );
17 }
18 DBICTest::Artist->dbi_commit;
19 my ($artist) = DBICTest::Artist->find(15);
20 is($artist->name, 'artist number 15', "Commit ok");
21
22 # repeat the test using AutoCommit = 1 to force the commit
23 DBICTest::Artist->storage->dbh->{AutoCommit} = 0;
24 for (16..20) {
25     DBICTest::Artist->create( {
26         artistid => $_,
27         name => "artist number $_",
28     } );
29 }
30 DBICTest::Artist->storage->dbh->{AutoCommit} = 1;
31 ($artist) = DBICTest::Artist->find(20);
32 is($artist->name, 'artist number 20', "Commit using AutoCommit ok");
33
34 # add some rows inside a transaction and roll it back
35 DBICTest::Artist->storage->dbh->{AutoCommit} = 0;
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