File: plus_select.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (65 lines) | stat: -rw-r--r-- 2,069 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

my $cd_rs = $schema->resultset('CD')->search ({genreid => { '!=', undef } }, { order_by => 'cdid' });
my $track_cnt = $cd_rs->search({}, { rows => 1 })->search_related ('tracks')->count;

my %basecols = $cd_rs->first->get_columns;

# the current implementation of get_inflated_columns will "inflate"
# relationships by simply calling the accessor, when you have
# identically named columns and relationships (you shouldn't anyway)
# I consider this wrong, but at the same time appreciate the
# ramifications of changing this. Thus the value override  and the
# TODO to go with it. Delete all of this if ever resolved.
my %todo_rel_inflation_override = ( artist => $basecols{artist} );
{
  local $TODO = 'Treating relationships as inflatable data is wrong - see comment in ' . __FILE__;
  ok (! keys %todo_rel_inflation_override);
}

my $plus_rs = $cd_rs->search (
  {},
  { join => 'tracks', distinct => 1, '+select' => { count => 'tracks.trackid' }, '+as' => 'tr_cnt' },
);

is_deeply (
  { $plus_rs->first->get_columns },
  { %basecols, tr_cnt => $track_cnt },
  'extra columns returned by get_columns',
);

is_deeply (
  { $plus_rs->first->get_inflated_columns, %todo_rel_inflation_override },
  { %basecols, tr_cnt => $track_cnt },
  'extra columns returned by get_inflated_columns without inflatable columns',
);

SKIP: {
  skip (
    "+select/get_inflated_columns tests need " . DBIx::Class::Optional::Dependencies->req_missing_for ('test_dt'),
    1
  ) unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_dt');

  $schema->class('CD')->inflate_column( 'year',
    { inflate => sub { DateTime->new( year => shift ) },
      deflate => sub { shift->year } }
  );

  $basecols{year} = DateTime->new ( year => $basecols{year} );

  is_deeply (
    { $plus_rs->first->get_inflated_columns, %todo_rel_inflation_override },
    { %basecols, tr_cnt => $track_cnt },
    'extra columns returned by get_inflated_columns',
  );
}

done_testing;