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