r14186@rob-kinyons-powerbook58: rob | 2006-06-14 11:44:48 -0400
[dbsrgits/DBM-Deep.git] / t / 38_transaction_add_item.t
1 use strict;
2 use Test::More tests => 9;
3 use Test::Deep;
4 use t::common qw( new_fh );
5
6 use_ok( 'DBM::Deep' );
7
8 my ($fh, $filename) = new_fh();
9 my $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 TODO: {
34     local $TODO = "Adding items in transactions will be fixed soon";
35     local $^W;
36     cmp_ok( $obj->{foo}, '==', 5 );
37 }
38     ok( !exists $obj->{bar}, "bar doesn't exist" );
39 TODO: {
40     local $TODO = "Adding items in transactions will be fixed soon";
41     ok( !tied(%$obj), "And it's not tied" );
42 }
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 }