r14010@rob-kinyons-powerbook58: rob | 2006-06-07 14:35:06 -0400
[dbsrgits/DBM-Deep.git] / t / 38_transaction_add_item.t
CommitLineData
867a26a0 1use strict;
2use Test::More tests => 9;
3use Test::Deep;
4use t::common qw( new_fh );
5
6use_ok( 'DBM::Deep' );
7
8my ($fh, $filename) = new_fh();
9my $db = DBM::Deep->new(
10 file => $filename,
11 locking => 1,
12 autoflush => 1,
13);
14
15{
16 my $obj = bless {
17 foo => 5,
18 }, 'Foo';
19
20 cmp_ok( $obj->{foo}, '==', 5 );
21 ok( !exists $obj->{bar} );
22
23 $db->begin_work;
24
25 $db->{foo} = $obj;
26 $db->{foo}{bar} = 1;
27
28 cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" );
29 cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" );
30
31 $db->rollback;
32
33 cmp_ok( $obj->{foo}, '==', 5 );
34 ok( !exists $obj->{bar}, "bar doesn't exist" );
35 ok( !tied(%$obj), "And it's not tied" );
36
37 ok( !exists $db->{foo}, "The transaction inside the DB works" );
38}
39
40__END__
41{
42 my $obj = bless {
43 foo => 5,
44 }, 'Foo';
45
46 cmp_ok( $obj->{foo}, '==', 5 );
47 ok( !exists $obj->{bar} );
48
49 $db->begin_work;
50
51 $db->{foo} = $obj;
52 $db->{foo}{bar} = 1;
53
54 cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" );
55 cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" );
56
57 $db->commit;
58
59 cmp_ok( $obj->{foo}, '==', 5 );
60 ok( !exists $obj->{bar} );
61}