Smarter todoification (this doesn't sound like a bad idea for CPAN in general)
[dbsrgits/DBIx-Class.git] / t / dq / grep_cache.t
CommitLineData
c1b38300 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use Test::Warn;
7use lib qw(t/lib);
8use DBICTest;
9use DBIC::SqlMakerTest;
10use Data::Query::ExprDeclare;
5556a917 11use Data::Query::ExprHelpers;
12use DBIx::Class::PerlRenderer::MangleStrings;
c1b38300 13
14my $schema = DBICTest->init_schema();
15
16my $cds = $schema->resultset('CD');
17
18my $restricted = $cds->search({}, { cache => 1, grep_cache => 1 })
19 ->search({ 'me.artist' => 1 });
20
21is($restricted->count, 3, 'Count on restricted ok');
22
23$restricted = $cds->search(
24 {},
25 { prefetch => 'artist', cache => 1, grep_cache => 1 }
26 )
27 ->search({ 'artist.name' => 'Caterwauler McCrae' });
28
29is($restricted->count, 3, 'Count on restricted ok via join');
30
5556a917 31my $title_cond = \expr { $_->me->title eq 'Foo' }->{expr};
32
33my $pred_normal = $cds->_construct_perl_predicate($title_cond);
34
35bless(
36 $schema->storage->perl_renderer,
37 'DBIx::Class::PerlRenderer::MangleStrings',
38);
39
40my $pred_mangle = $cds->_construct_perl_predicate($title_cond);
41
42foreach my $t ([ 'Foo', 1, 1 ], [ 'foo ', 0, 1 ]) {
43 my $obj = $cds->new_result({ title => $t->[0] });
44 foreach my $p ([ Normal => $pred_normal, 1 ], [ Mangle => $pred_mangle, 2 ]) {
45 is(($p->[1]->($obj) ? 1 : 0), $t->[$p->[2]], join(': ', $p->[0], $t->[0]));
46 }
47}
48
c1b38300 49done_testing;