File: Refresh.pm

package info (click to toggle)
libkiokudb-perl 0.57-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,396 kB
  • sloc: perl: 13,314; makefile: 12
file content (105 lines) | stat: -rw-r--r-- 2,014 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package KiokuDB::Test::Fixture::Refresh;
BEGIN {
  $KiokuDB::Test::Fixture::Refresh::AUTHORITY = 'cpan:NUFFIN';
}
$KiokuDB::Test::Fixture::Refresh::VERSION = '0.57';
use Moose;

use Test::More;
use Test::Exception;

use KiokuDB::Test::Person;

sub p {
    my @args = @_;
    unshift @args, "name" if @args % 2;
    KiokuDB::Test::Person->new(@args);
}

with qw(KiokuDB::Test::Fixture) => { -excludes => [qw/populate sort/] };

sub sort { -100 }

sub create {
    return (
        KiokuDB::Test::Person->new(
            name => "julie",
            age => 10,
        ),
    );
}

sub populate {
    my $self = shift;

    {
        my $s = $self->new_scope;

        my $obj = $self->create;

        isa_ok( $obj, "KiokuDB::Test::Person" );

        $self->store_ok( refresh_obj => $obj );

        $self->live_objects_are($obj);
    }

    $self->no_live_objects;
}

sub verify {
    my $self = shift;

    $self->txn_lives(sub {
        my $obj = $self->lookup_ok("refresh_obj");

        isa_ok( $obj, "KiokuDB::Test::Person" );

        is( $obj->name, "julie", "name" );

        my $dir = $self->directory;

        isa_ok( my $entry = $dir->live_objects->object_to_entry($obj), "KiokuDB::Entry" );

        my $updated = $entry->clone( prev => $entry );
        $updated->data->{age} = 1841;

        is( $obj->age, 10, "age attr" );

        $dir->backend->insert( $updated );

        is( $obj->age, 10, "age attr not updated even though it was written" );

        lives_ok { $dir->refresh($obj) } "no error in refresh";

        is( $obj->age, 1841, "age updated" );
    });
}
__PACKAGE__

__END__

=pod

=encoding UTF-8

=head1 NAME

KiokuDB::Test::Fixture::Refresh

=head1 VERSION

version 0.57

=head1 AUTHOR

Yuval Kogman <nothingmuch@woobling.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Yuval Kogman, Infinity Interactive.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut