Massive cleanup of DateTime test dependencies, other interim
[dbsrgits/DBIx-Class.git] / t / resultset / plus_select.t
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   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');
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
65 done_testing;