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