r14186@rob-kinyons-powerbook58: rob | 2006-06-14 11:44:48 -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
fb451ba6 33TODO: {
34 local $TODO = "Adding items in transactions will be fixed soon";
35 local $^W;
867a26a0 36 cmp_ok( $obj->{foo}, '==', 5 );
fb451ba6 37}
867a26a0 38 ok( !exists $obj->{bar}, "bar doesn't exist" );
fb451ba6 39TODO: {
40 local $TODO = "Adding items in transactions will be fixed soon";
867a26a0 41 ok( !tied(%$obj), "And it's not tied" );
fb451ba6 42}
867a26a0 43
44 ok( !exists $db->{foo}, "The transaction inside the DB works" );
45}
46
47__END__
48{
49 my $obj = bless {
50 foo => 5,
51 }, 'Foo';
52
53 cmp_ok( $obj->{foo}, '==', 5 );
54 ok( !exists $obj->{bar} );
55
56 $db->begin_work;
57
58 $db->{foo} = $obj;
59 $db->{foo}{bar} = 1;
60
61 cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" );
62 cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" );
63
64 $db->commit;
65
66 cmp_ok( $obj->{foo}, '==', 5 );
67 ok( !exists $obj->{bar} );
68}