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