test snippetstore translator requirement, improve debugging, fix app
[catagits/catbook-code.git] / t / snippet_store / basic.t
1 use strict;
2 use warnings;
3 use Test::More qw(no_plan);
4 use Test::Exception;
5
6 use_ok "LolCatalyst::Lite::SnippetStore";
7
8 dies_ok {
9   LolCatalyst::Lite::SnippetStore->new;
10 } 'Create without translator object fails';
11
12 my $store = LolCatalyst::Lite::SnippetStore->new(translator => 'DUMMY');
13
14 my $num_snips = 3;
15
16 ok(
17   (my @snip = map $store->create({ text => "snippet $_" }), 1 .. $num_snips),
18   'Creates ok'
19 );
20
21 cmp_ok(scalar(@snip), '==', $num_snips, "$num_snips created");
22
23 is_deeply(\@snip, [ $store->all ], 'deep snippet check');
24
25 foreach my $snip (@snip) {
26   my $id = $snip->{id};
27   is($snip->{text}, $store->find($id)->{text}, "find by id $id ok");
28 }