space-compress tests making them readable - no changes
[dbsrgits/DBIx-Class.git] / t / inflate / hri_torture.t
CommitLineData
ce556881 1use strict;
2use warnings;
3
4use Test::More;
52864fbd 5use Test::Deep;
ce556881 6use lib qw(t/lib);
7use DBICTest;
8
9# More tests like this in t/prefetch/manual.t
10
11my $schema = DBICTest->init_schema(no_populate => 1, quote_names => 1);
12$schema->resultset('Artist')->create({ name => 'JMJ', cds => [{
13 title => 'Magnetic Fields',
14 year => 1981,
15 genre => { name => 'electro' },
16 tracks => [
17 { title => 'm1' },
18 { title => 'm2' },
19 { title => 'm3' },
20 { title => 'm4' },
21 ],
22} ] });
23
24
25$schema->resultset('CD')->create({
26 title => 'Equinoxe',
27 year => 1978,
28 artist => { name => 'JMJ' },
29 genre => { name => 'electro' },
30 tracks => [
31 { title => 'e1' },
32 { title => 'e2' },
33 { title => 'e3' },
34 ],
35 single_track => {
36 title => 'o1',
37 cd => {
38 title => 'Oxygene',
39 year => 1976,
40 artist => { name => 'JMJ' },
41 tracks => [
42 { title => 'o2', position => 2}, # the position should not be needed here, bug in MC
43 ],
44 },
45 },
46});
47
48for (1,2) {
49 $schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_$_" });
50}
51
52864fbd 52{
53 package DBICTest::HRI::Subclass;
54 use base 'DBIx::Class::ResultClass::HashRefInflator';
55}
56
57{
58 package DBICTest::HRI::Around;
59 use base 'DBIx::Class::ResultClass::HashRefInflator';
60
61 sub inflate_result { shift->next::method(@_) }
62}
ce556881 63
52864fbd 64for my $rs (
65 $schema->resultset('CD')->search_rs({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }),
66 $schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Subclass' }),
67 $schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Around' }),
68) {
69
70cmp_deeply
71 [ $rs->search({}, {
ce556881 72 columns => {
73 year => 'me.year',
74 'single_track.cd.artist.name' => 'artist.name',
75 },
76 join => { single_track => { cd => 'artist' } },
77 order_by => [qw/me.cdid artist.artistid/],
52864fbd 78 })->all ],
ce556881 79 [
3d3e99db 80 { year => 1981, single_track => undef },
81 { year => 1976, single_track => undef },
82 { year => 1978, single_track => {
83 cd => {
84 artist => { name => "JMJ" }
ce556881 85 },
3d3e99db 86 }},
87 { year => 1977, single_track => undef },
88 { year => 1977, single_track => undef },
89
ce556881 90 ],
52864fbd 91 'plain 1:1 descending chain ' . $rs->result_class
ce556881 92;
93
52864fbd 94cmp_deeply
95 [ $rs->search({}, {
ce556881 96 columns => {
97 'artist' => 'me.artist',
98 'title' => 'me.title',
99 'year' => 'me.year',
100 'single_track.cd.artist.artistid' => 'artist.artistid',
101 'single_track.cd.artist.cds.cdid' => 'cds.cdid',
102 'single_track.cd.artist.cds.tracks.title' => 'tracks.title',
103 },
104 join => { single_track => { cd => { artist => { cds => 'tracks' } } } },
105 order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/],
52864fbd 106 })->all ],
ce556881 107 [
108 {
3d3e99db 109 artist => 1, title => "Magnetic Fields", year => 1981, single_track => undef,
ce556881 110 },
111 {
3d3e99db 112 artist => 1, title => "Oxygene", year => 1976, single_track => undef,
ce556881 113 },
114 {
3d3e99db 115 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 116 cd => {
117 artist => {
3d3e99db 118 artistid => 1, cds => {
119 cdid => 1, tracks => {
ce556881 120 title => "m1"
121 }
122 }
123 }
124 }
125 },
ce556881 126 },
127 {
3d3e99db 128 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 129 cd => {
130 artist => {
3d3e99db 131 artistid => 1, cds => {
132 cdid => 1, tracks => {
ce556881 133 title => "m2"
134 }
135 }
136 }
137 }
138 },
ce556881 139 },
140 {
3d3e99db 141 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 142 cd => {
143 artist => {
3d3e99db 144 artistid => 1, cds => {
145 cdid => 1, tracks => {
ce556881 146 title => "m3"
147 }
148 }
149 }
150 }
151 },
ce556881 152 },
153 {
3d3e99db 154 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 155 cd => {
156 artist => {
3d3e99db 157 artistid => 1, cds => {
158 cdid => 1, tracks => {
ce556881 159 title => "m4"
160 }
161 }
162 }
163 }
164 },
ce556881 165 },
166 {
3d3e99db 167 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 168 cd => {
169 artist => {
3d3e99db 170 artistid => 1, cds => {
171 cdid => 2, tracks => {
ce556881 172 title => "o2"
173 }
174 }
175 }
176 }
177 },
ce556881 178 },
179 {
3d3e99db 180 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 181 cd => {
182 artist => {
3d3e99db 183 artistid => 1, cds => {
184 cdid => 2, tracks => {
ce556881 185 title => "o1"
186 }
187 }
188 }
189 }
190 },
ce556881 191 },
192 {
3d3e99db 193 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 194 cd => {
195 artist => {
3d3e99db 196 artistid => 1, cds => {
197 cdid => 3, tracks => {
ce556881 198 title => "e1"
199 }
200 }
201 }
202 }
203 },
ce556881 204 },
205 {
3d3e99db 206 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 207 cd => {
208 artist => {
3d3e99db 209 artistid => 1, cds => {
210 cdid => 3, tracks => {
ce556881 211 title => "e2"
212 }
213 }
214 }
215 }
216 },
ce556881 217 },
218 {
3d3e99db 219 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 220 cd => {
221 artist => {
3d3e99db 222 artistid => 1, cds => {
223 cdid => 3, tracks => {
ce556881 224 title => "e3"
225 }
226 }
227 }
228 }
229 },
ce556881 230 },
231 {
3d3e99db 232 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 233 cd => {
234 artist => {
3d3e99db 235 artistid => 1, cds => {
236 cdid => 4, tracks => undef
ce556881 237 }
238 }
239 }
240 },
ce556881 241 },
242 {
3d3e99db 243 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 244 cd => {
245 artist => {
3d3e99db 246 artistid => 1, cds => {
247 cdid => 5, tracks => undef
ce556881 248 }
249 }
250 }
251 },
ce556881 252 },
253 {
3d3e99db 254 artist => 1, title => "fuzzy_1", year => 1977, single_track => undef,
ce556881 255 },
256 {
3d3e99db 257 artist => 1, title => "fuzzy_2", year => 1977, single_track => undef,
ce556881 258 }
259 ],
52864fbd 260 'non-collapsing 1:1:1:M:M chain ' . $rs->result_class,
ce556881 261;
262
52864fbd 263cmp_deeply
264 [ $rs->search({}, {
ce556881 265 columns => {
266 'artist' => 'me.artist',
267 'title' => 'me.title',
268 'year' => 'me.year',
269 'single_track.cd.artist.artistid' => 'artist.artistid',
270 'single_track.cd.artist.cds.cdid' => 'cds.cdid',
271 'single_track.cd.artist.cds.tracks.title' => 'tracks.title',
272 },
273 join => { single_track => { cd => { artist => { cds => 'tracks' } } } },
274 order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/],
859b7922 275 collapse => 1,
52864fbd 276 })->all ],
ce556881 277 [
278 {
3d3e99db 279 artist => 1, title => "Magnetic Fields", year => 1981, single_track => undef,
ce556881 280 },
281 {
3d3e99db 282 artist => 1, title => "Oxygene", year => 1976, single_track => undef,
ce556881 283 },
284 {
3d3e99db 285 artist => 1, title => "Equinoxe", year => 1978, single_track => {
ce556881 286 cd => {
287 artist => {
3d3e99db 288 artistid => 1, cds => [
ce556881 289 {
3d3e99db 290 cdid => 1, tracks => [
291 { title => "m1" },
292 { title => "m2" },
293 { title => "m3" },
294 { title => "m4" },
ce556881 295 ]
296 },
297 {
3d3e99db 298 cdid => 2, tracks => [
299 { title => "o2" },
300 { title => "o1" },
ce556881 301 ]
302 },
303 {
3d3e99db 304 cdid => 3, tracks => [
305 { title => "e1" },
306 { title => "e2" },
307 { title => "e3" },
ce556881 308 ]
309 },
310 {
3d3e99db 311 cdid => 4, tracks => [],
ce556881 312 },
313 {
3d3e99db 314 cdid => 5, tracks => [],
ce556881 315 }
316 ]
317 }
318 }
319 },
ce556881 320 },
321 {
3d3e99db 322 artist => 1, title => "fuzzy_1", year => 1977, single_track => undef,
ce556881 323 },
324 {
3d3e99db 325 artist => 1, title => "fuzzy_2", year => 1977, single_track => undef,
ce556881 326 }
327 ],
52864fbd 328 'collapsing 1:1:1:M:M chain ' . $rs->result_class,
ce556881 329;
330
52864fbd 331}
332
ce556881 333done_testing;