Commit | Line | Data |
70350518 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
a47e1233 |
8 | my $schema = DBICTest->init_schema(); |
2bb7b40b |
9 | |
5d62876f |
10 | plan tests => 10; |
2bb7b40b |
11 | |
58d387fe |
12 | my $cd; |
2bb7b40b |
13 | my $rs = $cd = $schema->resultset("CD")->search({}); |
14 | |
15 | my $rs_title = $rs->get_column('title'); |
16 | my $rs_year = $rs->get_column('year'); |
17 | |
18 | is($rs_title->next, 'Spoonful of bees', "next okay"); |
19 | |
5d62876f |
20 | is_deeply( [ sort $rs_year->func('DISTINCT') ], [ 1997, 1998, 1999, 2001 ], "wantarray context okay"); |
21 | |
2bb7b40b |
22 | my @all = $rs_title->all; |
23 | cmp_ok(scalar @all, '==', 5, "five titles returned"); |
24 | |
25 | cmp_ok($rs_year->max, '==', 2001, "max okay for year"); |
26 | is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title"); |
27 | |
28 | cmp_ok($rs_year->sum, '==', 9996, "three artists returned"); |
29 | |
ae515736 |
30 | my $psrs = $schema->resultset('CD')->search({}, |
31 | { |
32 | '+select' => \'COUNT(*)', |
33 | '+as' => 'count' |
34 | } |
35 | ); |
36 | ok(defined($psrs->get_column('count')), '+select/+as count'); |
37 | |
38 | $psrs = $schema->resultset('CD')->search({}, |
39 | { |
40 | '+select' => [ \'COUNT(*)', 'title' ], |
41 | '+as' => [ 'count', 'addedtitle' ] |
42 | } |
43 | ); |
44 | ok(defined($psrs->get_column('count')), '+select/+as arrayref count'); |
45 | ok(defined($psrs->get_column('addedtitle')), '+select/+as title'); |
46 | |
3f6cc7e4 |
47 | { |
48 | my $rs = $schema->resultset("CD")->search({}, { prefetch => 'artist' }); |
49 | my $rsc = $rs->get_column('year'); |
50 | is( $rsc->{_parent_resultset}->{attrs}->{prefetch}, undef, 'prefetch wiped' ); |
51 | } |