File Coverage

blib/lib/KiokuDB/Test/Fixture/Overwrite.pm
Criterion Covered Total %
statement 74 77 96.1
branch 0 2 0.0
condition n/a
subroutine 18 19 94.7
pod 0 6 0.0
total 92 104 88.4


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuDB::Test::Fixture::Overwrite;
4 2     2   1501 use Moose;
  2         8  
  2         13  
5              
6 2     2   9374 use Test::More;
  2         4  
  2         16  
7 2     2   518 use Test::Exception;
  2         4  
  2         15  
8              
9 2     2   376 use Scalar::Util qw(refaddr);
  2         4  
  2         206  
10              
11 2     2   16 use KiokuDB::Test::Person;
  2         4  
  2         33  
12 2     2   11 use KiokuDB::Test::Employee;
  2         2  
  2         33  
13 2     2   7 use KiokuDB::Test::Company;
  2         6  
  2         53  
14              
15             {
16             package KiokuDB::Test::BLOB;
17 2     2   7 use Moose;
  2         2  
  2         16  
18              
19             with qw(KiokuDB::Role::ID::Content);
20              
21             sub kiokudb_object_id {
22 99     99 0 193 my $self = shift;
23 99         2857 $self->data;
24             }
25              
26             has data => (
27             isa => "Str",
28             is => "ro",
29             required => 1,
30             );
31             }
32              
33             sub p {
34 0     0 0 0 my @args = @_;
35 0 0       0 unshift @args, "name" if @args % 2;
36 0         0 KiokuDB::Test::Person->new(@args);
37             }
38              
39             with qw(KiokuDB::Test::Fixture) => { excludes => [qw/populate sort/] };
40              
41 10     10 0 23 sub sort { -100 }
42              
43             sub create {
44             return (
45 33     33 0 1047 KiokuDB::Test::Person->new(
46             name => "blah",
47             ),
48             KiokuDB::Test::BLOB->new(
49             data => "lalala",
50             ),
51             );
52             }
53              
54             sub populate {
55 33     33 0 65 my $self = shift;
56              
57             {
58 33         37 my $s = $self->new_scope;
  33         96  
59              
60 33         139 my ( $p, $b ) = $self->create;
61              
62 33         14584 isa_ok( $p, "KiokuDB::Test::Person" );
63 33         13069 isa_ok( $b, "KiokuDB::Test::BLOB" );
64              
65 33         11203 $self->store_ok( person => $p, $b );
66              
67 33         342 $self->live_objects_are($p, $b);
68             }
69              
70 33         595 $self->no_live_objects;
71             }
72              
73             sub verify {
74 33     33 0 76 my $self = shift;
75              
76             {
77 33         41 my $s = $self->new_scope;
  33         137  
78              
79 33         177 my $p = $self->lookup_ok("person");
80              
81 33         167 isa_ok( $p, "KiokuDB::Test::Person" );
82              
83 33         13952 is( $p->name, "blah", "name attr" );
84              
85 33         11737 $p->name("new name");
86              
87             lives_ok {
88 33     33   1792 $self->directory->store($p);
89 33         243 } "update";
90             }
91              
92 33         1015 $self->no_live_objects;
93              
94             {
95 33         42 my $s = $self->new_scope;
  33         162  
96              
97 33         179 my $b = $self->lookup_ok("lalala");
98              
99 33         222 isa_ok( $b, "KiokuDB::Test::BLOB" );
100              
101 33         13350 is( $b->data, "lalala", "data attr" );
102              
103 33         11459 my $entry = $self->directory->live_objects->object_to_entry($b);
104              
105             lives_ok {
106 33     33   1693 $self->directory->store($b);
107 33         278 } "update (noop)";
108              
109 33         13098 my $new_entry = $self->directory->live_objects->object_to_entry($b);
110              
111 33         209 is( refaddr($new_entry), refaddr($entry), "entry refaddr unchanged" );
112             }
113              
114 33         231 $self->no_live_objects;
115              
116             dies_ok {
117 33     33   941 my $s = $self->new_scope;
118             $self->txn_do(sub {
119 33         1056 $self->directory->store( person => KiokuDB::Test::Person->new( name => "duplicate" ) );
120 33         254 });
121 33         285 } "can't insert duplicate";
122              
123 33         16345 $self->no_live_objects;
124              
125             lives_ok {
126 33     33   1045 my $s = $self->new_scope;
127             $self->txn_do(sub {
128 33         1038 my $id = $self->directory->store( KiokuDB::Test::BLOB->new( data => "lalala" ) );
129 33         257 });
130 33         286 } "not an error to insert a duplicate of a content addressed object";
131              
132 33         13929 $self->no_live_objects;
133              
134             lives_ok {
135 33     33   913 my $s = $self->new_scope;
136              
137 33         176 my $b = $self->lookup_ok("lalala");
138              
139             $self->txn_do(sub {
140 33         1128 my $id = $self->directory->store( KiokuDB::Test::BLOB->new( data => "lalala" ) );
141 33         340 });
142 33         286 } "not an error to insert a duplicate of a live content addressed object";
143              
144 33         13045 $self->no_live_objects;
145             }
146              
147             __PACKAGE__
148              
149             __END__
150