Add support for +select and +as attributes to ResultSet
[dbsrgits/DBIx-Class.git] / t / run / 28result_set_column.tl
CommitLineData
2bb7b40b 1sub run_tests {
2my $schema = shift;
3
cec13963 4plan tests => 8;
2bb7b40b 5
6my $rs = $cd = $schema->resultset("CD")->search({});
7
8my $rs_title = $rs->get_column('title');
9my $rs_year = $rs->get_column('year');
10
11is($rs_title->next, 'Spoonful of bees', "next okay");
12
13my @all = $rs_title->all;
14cmp_ok(scalar @all, '==', 5, "five titles returned");
15
16cmp_ok($rs_year->max, '==', 2001, "max okay for year");
17is($rs_title->min, 'Caterwaulin\' Blues', "min okay for title");
18
19cmp_ok($rs_year->sum, '==', 9996, "three artists returned");
20
cec13963 21my $psrs = $schema->resultset('CD')->search({},
22 {
23 '+select' => \'COUNT(*)',
24 '+as' => 'count'
25 }
26);
27ok(defined($psrs->get_column('count')), '+select/+as count');
28
29$psrs = $schema->resultset('CD')->search({},
30 {
31 '+select' => [ \'COUNT(*)', 'title' ],
32 '+as' => [ 'count', 'addedtitle' ]
33 }
34);
35ok(defined($psrs->get_column('count')), '+select/+as arrayref count');
36ok(defined($psrs->get_column('addedtitle')), '+select/+as title');
2bb7b40b 37}
38
391;