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 | |
20ea4813 |
10 | plan tests => 11; |
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'); |
20ea4813 |
17 | my $max_year = $rs->get_column(\'MAX (year)'); |
2bb7b40b |
18 | |
19 | is($rs_title->next, 'Spoonful of bees', "next okay"); |
5d62876f |
20 | is_deeply( [ sort $rs_year->func('DISTINCT') ], [ 1997, 1998, 1999, 2001 ], "wantarray context okay"); |
20ea4813 |
21 | ok ($max_year->next == $rs_year->max, q/get_column (\'FUNC') ok/); |
5d62876f |
22 | |
2bb7b40b |
23 | my @all = $rs_title->all; |
24 | cmp_ok(scalar @all, '==', 5, "five titles returned"); |
25 | |
26 | cmp_ok($rs_year->max, '==', 2001, "max okay for year"); |
27 | is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title"); |
28 | |
29 | cmp_ok($rs_year->sum, '==', 9996, "three artists returned"); |
30 | |
ae515736 |
31 | my $psrs = $schema->resultset('CD')->search({}, |
32 | { |
33 | '+select' => \'COUNT(*)', |
34 | '+as' => 'count' |
35 | } |
36 | ); |
37 | ok(defined($psrs->get_column('count')), '+select/+as count'); |
38 | |
39 | $psrs = $schema->resultset('CD')->search({}, |
40 | { |
41 | '+select' => [ \'COUNT(*)', 'title' ], |
42 | '+as' => [ 'count', 'addedtitle' ] |
43 | } |
44 | ); |
45 | ok(defined($psrs->get_column('count')), '+select/+as arrayref count'); |
46 | ok(defined($psrs->get_column('addedtitle')), '+select/+as title'); |
47 | |
3f6cc7e4 |
48 | { |
49 | my $rs = $schema->resultset("CD")->search({}, { prefetch => 'artist' }); |
50 | my $rsc = $rs->get_column('year'); |
51 | is( $rsc->{_parent_resultset}->{attrs}->{prefetch}, undef, 'prefetch wiped' ); |
52 | } |