Commit | Line | Data |
d61b2132 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
9 | my $schema = DBICTest->init_schema(); |
10 | |
11 | my $cd_rs = $schema->resultset('CD')->search ({genreid => { '!=', undef } }, { order_by => 'cdid' }); |
12 | my $track_cnt = $cd_rs->search({}, { rows => 1 })->search_related ('tracks')->count; |
13 | |
14 | my %basecols = $cd_rs->first->get_columns; |
15 | |
16 | # the current implementation of get_inflated_columns will "inflate" |
17 | # relationships by simply calling the accessor, when you have |
18 | # identically named columns and relationships (you shouldn't anyway) |
19 | # I consider this wrong, but at the same time appreciate the |
20 | # ramifications of changing this. Thus the value override and the |
21 | # TODO to go with it. Delete all of this if ever resolved. |
22 | my %todo_rel_inflation_override = ( artist => $basecols{artist} ); |
23 | TODO: { |
24 | local $TODO = 'Treating relationships as inflatable data is wrong - see comment in ' . __FILE__; |
25 | ok (! keys %todo_rel_inflation_override); |
26 | } |
27 | |
28 | my $plus_rs = $cd_rs->search ( |
29 | {}, |
30 | { join => 'tracks', distinct => 1, '+select' => { count => 'tracks.trackid' }, '+as' => 'tr_cnt' }, |
31 | ); |
32 | |
33 | is_deeply ( |
34 | { $plus_rs->first->get_columns }, |
35 | { %basecols, tr_cnt => $track_cnt }, |
36 | 'extra columns returned by get_columns', |
37 | ); |
38 | |
39 | is_deeply ( |
40 | { $plus_rs->first->get_inflated_columns, %todo_rel_inflation_override }, |
41 | { %basecols, tr_cnt => $track_cnt }, |
42 | 'extra columns returned by get_inflated_columns without inflatable columns', |
43 | ); |
44 | |
45 | SKIP: { |
46 | eval { require DateTime }; |
93cee17f |
47 | skip "Need DateTime for +select/get_inflated_columns tests", 1 if $@; |
d61b2132 |
48 | |
49 | $schema->class('CD')->inflate_column( 'year', |
50 | { inflate => sub { DateTime->new( year => shift ) }, |
51 | deflate => sub { shift->year } } |
52 | ); |
53 | |
54 | $basecols{year} = DateTime->new ( year => $basecols{year} ); |
55 | |
56 | is_deeply ( |
57 | { $plus_rs->first->get_inflated_columns, %todo_rel_inflation_override }, |
58 | { %basecols, tr_cnt => $track_cnt }, |
59 | 'extra columns returned by get_inflated_columns', |
60 | ); |
61 | } |
62 | |
63 | done_testing; |