Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / resultset / inflatemap_abuse.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
25a942fa 3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
c0329273 8
25a942fa 9use DBICTest;
10
11# From http://lists.scsys.co.uk/pipermail/dbix-class/2013-February/011119.html
12#
13# > Right, at this point we have an "undefined situation turned into an
14# > unplanned feature", therefore 0.08242 will downgrade the exception to a
15# > single-warning-per-process. This seems like a sane middle ground for
16# > "you gave me an 'as' that worked by accident before - fix it at your
17# > convenience".
18#
19# When the things were reshuffled it became apparent implementing a warning
20# for the HRI case *only* is going to complicate the code a lot, without
21# adding much benefit at this point. So just make sure everything works the
22# way it used to and move on
23
24
25my $s = DBICTest->init_schema;
26
27my $rs_2nd_track = $s->resultset('Track')->search(
28 { 'me.position' => 2 },
29 {
30 join => { cd => 'artist' },
fb88ca2c 31 columns => [ 'me.title', { 'artist.cdtitle' => 'cd.title' }, 'artist.name' ],
32 order_by => [ 'artist.name', { -desc => 'cd.cdid' }, 'me.trackid' ],
25a942fa 33 }
34);
35
36is_deeply (
37 [ map { $_->[-1] } $rs_2nd_track->cursor->all ],
38 [ ('Caterwauler McCrae') x 3, 'Random Boy Band', 'We Are Goth' ],
39 'Artist name cartesian product correct off cursor',
40);
41
42is_deeply (
43 $rs_2nd_track->all_hri,
44 [
45 {
46 artist => { cdtitle => "Caterwaulin' Blues", name => "Caterwauler McCrae" },
47 title => "Howlin"
48 },
49 {
50 artist => { cdtitle => "Forkful of bees", name => "Caterwauler McCrae" },
51 title => "Stripy"
52 },
53 {
54 artist => { cdtitle => "Spoonful of bees", name => "Caterwauler McCrae" },
55 title => "Apiary"
56 },
57 {
58 artist => { cdtitle => "Generic Manufactured Singles", name => "Random Boy Band" },
59 title => "Boring Song"
60 },
61 {
62 artist => { cdtitle => "Come Be Depressed With Us", name => "We Are Goth" },
63 title => "Under The Weather"
64 }
65 ],
66 'HRI with invalid inflate map works'
67);
68
69throws_ok
70 { $rs_2nd_track->next }
71 qr!\QInflation into non-existent relationship 'artist' of 'Track' requested, check the inflation specification (columns/as) ending in '...artist.name'!,
72 'Correct exception on illegal ::Row inflation attempt'
73;
74
1e1cea38 75# make sure has_many column redirection does not do weird stuff when collapse is requested
76for my $pref_args (
77 { prefetch => 'cds'},
78 { collapse => 1 }
79) {
80 for my $col_and_join_args (
81 { '+columns' => { 'cd_title' => 'cds_2.title' }, join => [ 'cds', 'cds' ] },
82 { '+columns' => { 'cd_title' => 'cds.title' }, join => 'cds' },
83 { '+columns' => { 'cd_gr_name' => 'genre.name' }, join => { cds => 'genre' } },
84 ) {
85 for my $call (qw(next all first)) {
86
87 my $weird_rs = $s->resultset('Artist')->search({}, {
88 %$col_and_join_args, %$pref_args,
89 });
90
91 throws_ok
92 { $weird_rs->$call }
93 qr/\QResult collapse not possible - selection from a has_many source redirected to the main object/
94 for (1,2);
95 }
96 }
97}
98
25a942fa 99done_testing;