Commit | Line | Data |
c1b38300 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use Test::Warn; |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | use DBIC::SqlMakerTest; |
10 | use Data::Query::ExprDeclare; |
5556a917 |
11 | use Data::Query::ExprHelpers; |
12 | use DBIx::Class::PerlRenderer::MangleStrings; |
c1b38300 |
13 | |
14 | my $schema = DBICTest->init_schema(); |
15 | |
16 | my $cds = $schema->resultset('CD'); |
17 | |
18 | my $restricted = $cds->search({}, { cache => 1, grep_cache => 1 }) |
19 | ->search({ 'me.artist' => 1 }); |
20 | |
21 | is($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 | |
29 | is($restricted->count, 3, 'Count on restricted ok via join'); |
30 | |
5556a917 |
31 | my $title_cond = \expr { $_->me->title eq 'Foo' }->{expr}; |
32 | |
33 | my $pred_normal = $cds->_construct_perl_predicate($title_cond); |
34 | |
35 | bless( |
36 | $schema->storage->perl_renderer, |
37 | 'DBIx::Class::PerlRenderer::MangleStrings', |
38 | ); |
39 | |
40 | my $pred_mangle = $cds->_construct_perl_predicate($title_cond); |
41 | |
42 | foreach 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 |
49 | done_testing; |