Massive cleanup of DateTime test dependencies, other interim
[dbsrgits/DBIx-Class.git] / t / resultset / plus_select.t
CommitLineData
d61b2132 1use strict;
2use warnings;
3
4use Test::More;
5
6use lib qw(t/lib);
7use DBICTest;
8
9my $schema = DBICTest->init_schema();
10
11my $cd_rs = $schema->resultset('CD')->search ({genreid => { '!=', undef } }, { order_by => 'cdid' });
12my $track_cnt = $cd_rs->search({}, { rows => 1 })->search_related ('tracks')->count;
13
14my %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.
22my %todo_rel_inflation_override = ( artist => $basecols{artist} );
23TODO: {
24 local $TODO = 'Treating relationships as inflatable data is wrong - see comment in ' . __FILE__;
25 ok (! keys %todo_rel_inflation_override);
26}
27
28my $plus_rs = $cd_rs->search (
29 {},
30 { join => 'tracks', distinct => 1, '+select' => { count => 'tracks.trackid' }, '+as' => 'tr_cnt' },
31);
32
33is_deeply (
34 { $plus_rs->first->get_columns },
35 { %basecols, tr_cnt => $track_cnt },
36 'extra columns returned by get_columns',
37);
38
39is_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
45SKIP: {
68de9438 46 skip (
47 "+select/get_inflated_columns tests need " . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt'),
48 1
49 ) unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt');
d61b2132 50
51 $schema->class('CD')->inflate_column( 'year',
52 { inflate => sub { DateTime->new( year => shift ) },
53 deflate => sub { shift->year } }
54 );
55
56 $basecols{year} = DateTime->new ( year => $basecols{year} );
57
58 is_deeply (
59 { $plus_rs->first->get_inflated_columns, %todo_rel_inflation_override },
60 { %basecols, tr_cnt => $track_cnt },
61 'extra columns returned by get_inflated_columns',
62 );
63}
64
65done_testing;