File Coverage

blib/lib/KiokuDB/Test/Fixture/Refresh.pm
Criterion Covered Total %
statement 37 40 92.5
branch 0 2 0.0
condition n/a
subroutine 9 10 90.0
pod 0 5 0.0
total 46 57 80.7


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::Test::Fixture::Refresh;
4 2     2   1779 use Moose;
  2         5  
  2         15  
5              
6 2     2   12466 use Test::More;
  2         5  
  2         19  
7 2     2   639 use Test::Exception;
  2         5  
  2         16  
8              
9 2     2   1320 use KiokuDB::Test::Person;
  2         6  
  2         932  
10              
11             sub p {
12 0     0 0 0 my @args = @_;
13 0 0       0 unshift @args, "name" if @args % 2;
14 0         0 KiokuDB::Test::Person->new(@args);
15             }
16              
17             with qw(KiokuDB::Test::Fixture) => { excludes => [qw/populate sort/] };
18              
19 8     8 0 10 sub sort { -100 }
20              
21             sub create {
22             return (
23 33     33 0 1183 KiokuDB::Test::Person->new(
24             name => "julie",
25             age => 10,
26             ),
27             );
28             }
29              
30             sub populate {
31 33     33 0 83 my $self = shift;
32              
33             {
34 33         55 my $s = $self->new_scope;
  33         122  
35              
36 33         147 my $obj = $self->create;
37              
38 33         149 isa_ok( $obj, "KiokuDB::Test::Person" );
39              
40 33         13014 $self->store_ok( refresh_obj => $obj );
41              
42 33         260 $self->live_objects_are($obj);
43             }
44              
45 33         981 $self->no_live_objects;
46             }
47              
48             sub verify {
49 33     33 0 77 my $self = shift;
50              
51             $self->txn_lives(sub {
52 33     33   172 my $obj = $self->lookup_ok("refresh_obj");
53              
54 33         160 isa_ok( $obj, "KiokuDB::Test::Person" );
55              
56 33         13050 is( $obj->name, "julie", "name" );
57              
58 33         11238 my $dir = $self->directory;
59              
60 33         849 isa_ok( my $entry = $dir->live_objects->object_to_entry($obj), "KiokuDB::Entry" );
61              
62 33         11909 my $updated = $entry->clone( prev => $entry );
63 33         85939 $updated->data->{age} = 1841;
64              
65 33         903 is( $obj->age, 10, "age attr" );
66              
67 33         12243 $dir->backend->insert( $updated );
68              
69 33         893 is( $obj->age, 10, "age attr not updated even though it was written" );
70              
71 33         10584 lives_ok { $dir->refresh($obj) } "no error in refresh";
  33         1016  
72              
73 33         12717 is( $obj->age, 1841, "age updated" );
74 33         331 });
75             }
76             __PACKAGE__
77