Commit | Line | Data |
867a26a0 |
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, |
9a63e1f2 |
13 | num_txns => 16, |
867a26a0 |
14 | ); |
15 | |
16 | { |
17 | my $obj = bless { |
18 | foo => 5, |
19 | }, 'Foo'; |
20 | |
9a63e1f2 |
21 | cmp_ok( $obj->{foo}, '==', 5, "FOO is 5 in the object" ); |
22 | ok( !exists $obj->{bar}, "BAR doesn't exist in the object" ); |
867a26a0 |
23 | |
24 | $db->begin_work; |
25 | |
9a63e1f2 |
26 | $db->{foo} = $obj; |
27 | $db->{foo}{bar} = 1; |
867a26a0 |
28 | |
9a63e1f2 |
29 | cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" ); |
30 | cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" ); |
867a26a0 |
31 | |
32 | $db->rollback; |
33 | |
fb451ba6 |
34 | TODO: { |
35 | local $TODO = "Adding items in transactions will be fixed soon"; |
36 | local $^W; |
867a26a0 |
37 | cmp_ok( $obj->{foo}, '==', 5 ); |
fb451ba6 |
38 | } |
867a26a0 |
39 | ok( !exists $obj->{bar}, "bar doesn't exist" ); |
fb451ba6 |
40 | TODO: { |
41 | local $TODO = "Adding items in transactions will be fixed soon"; |
867a26a0 |
42 | ok( !tied(%$obj), "And it's not tied" ); |
fb451ba6 |
43 | } |
867a26a0 |
44 | |
45 | ok( !exists $db->{foo}, "The transaction inside the DB works" ); |
46 | } |
47 | |
48 | __END__ |
49 | { |
50 | my $obj = bless { |
51 | foo => 5, |
52 | }, 'Foo'; |
53 | |
54 | cmp_ok( $obj->{foo}, '==', 5 ); |
55 | ok( !exists $obj->{bar} ); |
56 | |
57 | $db->begin_work; |
58 | |
9a63e1f2 |
59 | $db->{foo} = $obj; |
60 | $db->{foo}{bar} = 1; |
867a26a0 |
61 | |
9a63e1f2 |
62 | cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" ); |
63 | cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" ); |
867a26a0 |
64 | |
65 | $db->commit; |
66 | |
67 | cmp_ok( $obj->{foo}, '==', 5 ); |
68 | ok( !exists $obj->{bar} ); |
69 | } |