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