comment saving
[scpubgit/Commentry.git] / t / comment_store.t
1 use strictures 1;
2 use Test::More;
3 use File::Path;
4 use aliased 'App::Commentry::CommentStore';
5 use aliased 'App::Commentry::Comment';
6
7 my $store = CommentStore->new(base_dir => 't/var/exstore');
8
9 is_deeply(
10   [ $store->get({ path => 'not/there' })->flatten ],
11   [], 'Nonexistent set is empty'
12 );
13
14 is_deeply(
15   [ $store->get({ path => 'one/two/three' })->flatten ],
16   [ map Comment->new({ title => "Title $_", body => "Body $_" }), 1, 2 ],
17   'Existing set loads ok'
18 );
19
20 my $create = { title => 'Created title', body => 'Created body' };
21
22 is_deeply(
23   $store->get({ path => 'create/new' })->add($create),
24   my $new = Comment->new($create),
25   'Create new ok'
26 );
27
28 $store->clear_cache;
29
30 is_deeply(
31   [ $store->get({ path => 'create/new' })->flatten ],
32   [ $new ],
33   'Reload ok'
34 );
35
36 rmtree('t/var/exstore/create');
37
38 done_testing;