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