Commit | Line | Data |
8a3a5bc5 |
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; |
11 | |
12 | my $schema = DBICTest->init_schema(); |
13 | |
14 | my $mccrae = $schema->resultset('Artist') |
15 | ->find({ name => 'Caterwauler McCrae' }); |
16 | |
17 | my @cds = $schema->resultset('CD') |
18 | ->search(expr { $_->artist == $mccrae->artistid }); |
19 | |
20 | is(@cds, 3, 'CDs returned from expr search by artistid'); |
21 | |
22 | my @years = $schema->resultset('CD') |
23 | ->search(expr { $_->year < 2000 }) |
24 | ->get_column('year') |
25 | ->all; |
26 | |
27 | is_deeply([ sort @years ], [ 1997, 1998, 1999 ], 'Years for < search'); |
28 | |
29 | my $tag_cond = expr { $_->tag eq 'Blue' }; |
30 | |
31 | is($schema->resultset('Tag')->search($tag_cond)->count, 4, 'Simple tag cond'); |
32 | |
33 | $tag_cond &= expr { $_->cd < 4 }; |
34 | |
35 | is($schema->resultset('Tag')->search($tag_cond)->count, 3, 'Combi tag cond'); |
36 | |
37 | done_testing; |