]> Dogcows Code - chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate/blob - t/96multi_create.t
add test script for mysql
[chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate] / t / 96multi_create.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use Test::Exception;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 my $schema = DBICTest->init_schema();
9
10 diag '* simple create + parent (the stuff $rs belongs_to)';
11 eval {
12 my $cd = $schema->resultset('CD')->recursive_update(
13 { artist => { name => 'Fred Bloggs' },
14 title => 'Some CD',
15 year => 1996
16 }
17 );
18
19 isa_ok( $cd, 'DBICTest::CD', 'Created CD object' );
20 isa_ok( $cd->artist, 'DBICTest::Artist', 'Created related Artist' );
21 is( $cd->artist->name, 'Fred Bloggs', 'Artist created correctly' );
22 };
23 diag $@ if $@;
24
25 diag
26 '* same as above but the child and parent have no values, except for an explicit parent pk';
27 eval {
28 my $bm_rs = $schema->resultset('Bookmark');
29 my $bookmark = $bm_rs->recursive_update( { link => { id => 66, }, } );
30
31 isa_ok( $bookmark, 'DBICTest::Bookmark', 'Created Bookrmark object' );
32 isa_ok( $bookmark->link, 'DBICTest::Link', 'Created related Link' );
33 is( $bm_rs->search(
34 { 'link.title' => $bookmark->link->title },
35 { join => 'link' },
36 )->count,
37 1,
38 'Bookmark and link made it to the DB',
39 );
40 };
41 diag $@ if $@;
42
43 diag '* Create m2m while originating in the linker table';
44 eval {
45 my $artist = $schema->resultset('Artist')->first;
46 my $c2p = $schema->resultset('CD_to_Producer')->recursive_update(
47 { cd => {
48 artist => $artist,
49 title => 'Bad investment',
50 year => 2008,
51 tracks => [
52 { pos => 1, title => 'Just buy' },
53 { pos => 2, title => 'Why did we do it' },
54 { pos => 3, title => 'Burn baby burn' },
55 ],
56 },
57 producer => { name => 'Lehman Bros.', },
58 }
59 );
60
61 isa_ok( $c2p, 'DBICTest::CD_to_Producer', 'Linker object created' );
62 my $prod =
63 $schema->resultset('Producer')->find( { name => 'Lehman Bros.' } );
64 isa_ok( $prod, 'DBICTest::Producer', 'Producer row found' );
65 is( $prod->cds->count, 1, 'Producer has one production' );
66 my $cd = $prod->cds->first;
67 is( $cd->title, 'Bad investment', 'CD created correctly' );
68 is( $cd->tracks->count, 3, 'CD has 3 tracks' );
69
70 };
71 diag $@ if $@;
72
73 diag(<<'DG');
74 * Create over > 1 levels of might_have with multiple has_many and multiple m2m
75 but starting at a has_many level
76
77 CD -> has_many -> Tracks -> might have -> Single -> has_many -> Tracks
78 \
79 \-> has_many \
80 --> CD2Producer
81 /-> has_many /
82 /
83 Producer
84 DG
85
86 eval {
87 my $artist = $schema->resultset('Artist')->first;
88 my $cd = $schema->resultset('CD')->recursive_update(
89 { artist => $artist,
90 title => 'Music to code by at night',
91 year => 2008,
92 tracks => [
93 { pos => 1, # some day me might test this with Ordered
94 title => 'Off by one again',
95 },
96 { pos => 2,
97 title => 'The dereferencer',
98 cd_single => {
99 artist => $artist,
100 year => 2008,
101 title => 'Was that a null (Single)',
102 tracks => [
103 { title => 'The dereferencer', pos => 1 },
104 { title => 'The dereferencer II', pos => 2 },
105 ],
106 cd_to_producer => [
107 { producer => { name => 'K&R', } },
108 { producer => { name => 'Don Knuth', } },
109 ]
110 },
111 },
112 ],
113 }
114 );
115
116 isa_ok( $cd, 'DBICTest::CD', 'Main CD object created' );
117 is( $cd->title, 'Music to code by at night', 'Correct CD title' );
118 is( $cd->tracks->count, 2, 'Two tracks on main CD' );
119
120 my ( $t1, $t2 ) = $cd->tracks->all;
121 is( $t1->title, 'Off by one again', 'Correct 1st track name' );
122 is( $t1->cd_single, undef, 'No single for 1st track' );
123 is( $t2->title, 'The dereferencer', 'Correct 2nd track name' );
124 isa_ok( $t2->cd_single, 'DBICTest::CD',
125 'Created a single for 2nd track' );
126
127 my $single = $t2->cd_single;
128 is( $single->tracks->count, 2, 'Two tracks on single CD' );
129 is( $single->tracks->find( { position => 1 } )->title,
130 'The dereferencer',
131 'Correct 1st track title'
132 );
133 is( $single->tracks->find( { position => 2 } )->title,
134 'The dereferencer II',
135 'Correct 2nd track title'
136 );
137
138 is( $single->cd_to_producer->count,
139 2, 'Two producers created for the single cd' );
140 is_deeply(
141 [ sort map { $_->producer->name } ( $single->cd_to_producer->all ) ],
142 [ 'Don Knuth', 'K&R' ],
143 'Producers named correctly',
144 );
145 };
146 diag $@ if $@;
147
148 diag(<<'DG');
149 * Same as above but starting at the might_have directly
150
151 Track -> might have -> Single -> has_many -> Tracks
152 \
153 \-> has_many \
154 --> CD2Producer
155 /-> has_many /
156 /
157 Producer
158 DG
159
160 eval {
161 my $cd = $schema->resultset('CD')->first;
162 my $track = $schema->resultset('Track')->recursive_update(
163 { cd => $cd,
164 pos => 77, # some day me might test this with Ordered
165 title => 'Multicreate rocks',
166 cd_single => {
167 artist => $cd->artist,
168 year => 2008,
169 title => 'Disemboweling MultiCreate',
170 tracks => [
171 { title => 'Why does mst write this way', pos => 1 },
172 { title => 'Chainsaw celebration', pos => 2 },
173 { title => 'Purl cleans up', pos => 3 },
174 ],
175 cd_to_producer => [
176 { producer => { name => 'mst', } },
177 { producer => { name => 'castaway', } },
178 { producer => { name => 'theorbtwo', } },
179 ]
180 },
181 }
182 );
183
184 isa_ok( $track, 'DBICTest::Track', 'Main Track object created' );
185 is( $track->title, 'Multicreate rocks', 'Correct Track title' );
186
187 my $single = $track->cd_single;
188 isa_ok( $single, 'DBICTest::CD', 'Created a single with the track' );
189 is( $single->tracks->count, 3, '3 tracks on single CD' );
190 is( $single->tracks->find( { position => 1 } )->title,
191 'Why does mst write this way',
192 'Correct 1st track title'
193 );
194 is( $single->tracks->find( { position => 2 } )->title,
195 'Chainsaw celebration',
196 'Correct 2nd track title'
197 );
198 is( $single->tracks->find( { position => 3 } )->title,
199 'Purl cleans up',
200 'Correct 3rd track title'
201 );
202
203 is( $single->cd_to_producer->count,
204 3, '3 producers created for the single cd' );
205 is_deeply(
206 [ sort map { $_->producer->name } ( $single->cd_to_producer->all ) ],
207 [ 'castaway', 'mst', 'theorbtwo' ],
208 'Producers named correctly',
209 );
210 };
211 diag $@ if $@;
212
213 diag
214 '* Test might_have again but with a PK == FK in the middle (obviously not specified)';
215 eval {
216 my $artist = $schema->resultset('Artist')->first;
217 my $cd = $schema->resultset('CD')->recursive_update(
218 { artist => $artist,
219 title => 'Music to code by at twilight',
220 year => 2008,
221 artwork => {
222 images => [
223 { name => 'recursive descent' },
224 { name => 'tail packing' },
225 ],
226 },
227 }
228 );
229
230 isa_ok( $cd, 'DBICTest::CD', 'Main CD object created' );
231 is( $cd->title, 'Music to code by at twilight', 'Correct CD title' );
232 isa_ok( $cd->artwork, 'DBICTest::Artwork', 'Artwork created' );
233
234 # this test might look weird, but it failed at one point, keep it there
235 my $art_obj = $cd->artwork;
236 ok( $art_obj->has_column_loaded('cd_id'),
237 'PK/FK present on artwork object'
238 );
239 is( $art_obj->images->count, 2,
240 'Correct artwork image count via the new object' );
241 is_deeply(
242 [ sort $art_obj->images->get_column('name')->all ],
243 [ 'recursive descent', 'tail packing' ],
244 'Images named correctly in objects',
245 );
246
247 my $artwork = $schema->resultset('Artwork')->search(
248 { 'cd.title' => 'Music to code by at twilight' },
249 { join => 'cd' },
250 )->single;
251
252 is( $artwork->images->count, 2,
253 'Correct artwork image count via a new search' );
254
255 is_deeply(
256 [ sort $artwork->images->get_column('name')->all ],
257 [ 'recursive descent', 'tail packing' ],
258 'Images named correctly after search',
259 );
260 };
261 diag $@ if $@;
262
263 diag
264 '* Test might_have again but with just a PK and FK (neither specified) in the mid-table';
265 eval {
266 my $cd = $schema->resultset('CD')->first;
267 my $track = $schema->resultset('Track')->recursive_update(
268 { cd => $cd,
269 pos => 66,
270 title => 'Black',
271 lyrics => {
272 lyric_versions => [
273 { text => 'The color black' },
274 { text => 'The colour black' },
275 ],
276 },
277 }
278 );
279
280 isa_ok( $track, 'DBICTest::Track', 'Main track object created' );
281 is( $track->title, 'Black', 'Correct track title' );
282 isa_ok( $track->lyrics, 'DBICTest::Lyrics', 'Lyrics created' );
283
284 # this test might look weird, but it was failing at one point, keep it there
285 my $lyric_obj = $track->lyrics;
286 ok( $lyric_obj->has_column_loaded('lyric_id'),
287 'PK present on lyric object' );
288 ok( $lyric_obj->has_column_loaded('track_id'),
289 'FK present on lyric object' );
290 is( $lyric_obj->lyric_versions->count,
291 2, 'Correct lyric versions count via the new object' );
292 is_deeply(
293 [ sort $lyric_obj->lyric_versions->get_column('text')->all ],
294 [ 'The color black', 'The colour black' ],
295 'Lyrics text in objects matches',
296 );
297
298 my $lyric =
299 $schema->resultset('Lyrics')
300 ->search( { 'track.title' => 'Black' }, { join => 'track' }, )
301 ->single;
302
303 is( $lyric->lyric_versions->count,
304 2, 'Correct lyric versions count via a new search' );
305
306 is_deeply(
307 [ sort $lyric->lyric_versions->get_column('text')->all ],
308 [ 'The color black', 'The colour black' ],
309 'Lyrics text via search matches',
310 );
311 };
312 diag $@ if $@;
313
314 diag(<<'DG');
315 * Test a multilevel might-have with a PK == FK in the might_have/has_many table
316
317 CD -> might have -> Artwork
318 \
319 \-> has_many \
320 --> Artwork_to_Artist
321 /-> has_many /
322 /
323 Artist
324 DG
325
326 eval {
327 my $someartist = $schema->resultset('Artist')->first;
328 my $cd = $schema->resultset('CD')->recursive_update(
329 { artist => $someartist,
330 title => 'Music to code by until the cows come home',
331 year => 2008,
332 artwork => {
333 artwork_to_artist => [
334 { artist => { name => 'cowboy joe' } },
335 { artist => { name => 'billy the kid' } },
336 ],
337 },
338 }
339 );
340
341 isa_ok( $cd, 'DBICTest::CD', 'Main CD object created' );
342 is( $cd->title,
343 'Music to code by until the cows come home',
344 'Correct CD title'
345 );
346
347 my $art_obj = $cd->artwork;
348 ok( $art_obj->has_column_loaded('cd_id'),
349 'PK/FK present on artwork object'
350 );
351 is( $art_obj->artists->count, 2,
352 'Correct artwork creator count via the new object' );
353 is_deeply(
354 [ sort $art_obj->artists->get_column('name')->all ],
355 [ 'billy the kid', 'cowboy joe' ],
356 'Artists named correctly when queried via object',
357 );
358
359 my $artwork = $schema->resultset('Artwork')->search(
360 { 'cd.title' => 'Music to code by until the cows come home' },
361 { join => 'cd' },
362 )->single;
363 is( $artwork->artists->count, 2,
364 'Correct artwork creator count via a new search' );
365 is_deeply(
366 [ sort $artwork->artists->get_column('name')->all ],
367 [ 'billy the kid', 'cowboy joe' ],
368 'Artists named correctly queried via a new search',
369 );
370 };
371 diag $@ if $@;
372
373 diag '* Nested find_or_create';
374 eval {
375 my $newartist2 = $schema->resultset('Artist')->recursive_update(
376 { name => 'Fred 3',
377 cds => [
378 { title => 'Noah Act',
379 year => 2007,
380 },
381 ],
382 }
383 );
384 is( $newartist2->name, 'Fred 3',
385 'Created new artist with cds via find_or_create' );
386 };
387 diag $@ if $@;
388
389 diag '* Multiple same level has_many create';
390 eval {
391 my $artist2 = $schema->resultset('Artist')->recursive_update(
392 { name => 'Fred 4',
393 cds => [
394 { title => 'Music to code by',
395 year => 2007,
396 },
397 ],
398 cds_unordered => [
399 { title => 'Music to code by 1',
400
401 # original title => 'Music to code by',
402 year => 2007,
403 },
404 ]
405 }
406 );
407
408 is( $artist2->in_storage, 1, 'artist with duplicate rels inserted okay' );
409 };
410 diag $@ if $@;
411
412 diag '* First create_related pass';
413 eval {
414 my $artist = $schema->resultset('Artist')->first;
415
416 my $cd_result = $schema->resultset('CD')->recursive_update(
417 {
418
419 artist => $artist->artistid,
420 title => 'TestOneCD1',
421 year => 2007,
422 tracks => [
423
424 { pos => 111,
425 title => 'TrackOne',
426 },
427 { pos => 112,
428 title => 'TrackTwo',
429 }
430 ],
431
432 }
433 );
434
435 ok( $cd_result && ref $cd_result eq 'DBICTest::CD', "Got Good CD Class" );
436 ok( $cd_result->title eq "TestOneCD1", "Got Expected Title" );
437
438 my $tracks = $cd_result->tracks;
439
440 ok( $tracks->isa("DBIx::Class::ResultSet"),
441 "Got Expected Tracks ResultSet"
442 );
443
444 foreach my $track ( $tracks->all ) {
445 ok( $track && ref $track eq 'DBICTest::Track',
446 'Got Expected Track Class' );
447 }
448 };
449 diag $@ if $@;
450
451 diag '* second create_related with same arguments';
452 eval {
453 my $artist = $schema->resultset('Artist')->first;
454
455 my $cd_result = $schema->resultset('CD')->recursive_update(
456 {
457
458 artist => $artist->artistid,
459
460 title => 'TestOneCD2',
461 year => 2007,
462 tracks => [
463
464 { pos => 111,
465 title => 'TrackOne',
466 },
467 { pos => 112,
468 title => 'TrackTwo',
469 }
470 ],
471
472 liner_notes => { notes => 'I can haz liner notes?' },
473
474 }
475 );
476
477 ok( $cd_result && ref $cd_result eq 'DBICTest::CD', "Got Good CD Class" );
478 ok( $cd_result->title eq "TestOneCD2", "Got Expected Title" );
479 ok( $cd_result->notes eq 'I can haz liner notes?', 'Liner notes' );
480
481 my $tracks = $cd_result->tracks;
482
483 ok( $tracks->isa("DBIx::Class::ResultSet"),
484 "Got Expected Tracks ResultSet"
485 );
486
487 foreach my $track ( $tracks->all ) {
488 ok( $track && ref $track eq 'DBICTest::Track',
489 'Got Expected Track Class' );
490 }
491 };
492 diag $@ if $@;
493
494 diag '* create of parents of a record linker table';
495 eval {
496 my $cdp = $schema->resultset('CD_to_Producer')->recursive_update(
497 { cd => { artist => 1, title => 'foo', year => 2000 },
498 producer => { name => 'jorge' }
499 }
500 );
501 ok( $cdp, 'join table record created ok' );
502 };
503 diag $@ if $@;
504
505 diag
506 '* Create foreign key col obj including PK (See test 20 in 66relationships.t)';
507 eval {
508 my $new_cd_hashref = {
509 cdid => 27,
510 title => 'Boogie Woogie',
511 year => '2007',
512 artist => { artistid => 17, name => 'king luke' }
513 };
514
515 my $cd = $schema->resultset("CD")->find(1);
516
517 is( $cd->artist->id, 1, 'rel okay' );
518
519 my $new_cd = $schema->resultset("CD")->recursive_update($new_cd_hashref);
520 is( $new_cd->artist->id, 17, 'new id retained okay' );
521 };
522 diag $@ if $@;
523
524 eval {
525 $schema->resultset("CD")->recursive_update(
526 { cdid => 28,
527 title => 'Boogie Wiggle',
528 year => '2007',
529 artist => { artistid => 18, name => 'larry' }
530 }
531 );
532 };
533 is( $@, '', 'new cd created without clash on related artist' );
534
535 diag '* Test multi create over many_to_many';
536 eval {
537 $schema->resultset('CD')->recursive_update(
538 { artist => {
539 name => 'larry', # should already exist
540 },
541 title => 'Warble Marble',
542 year => '2009',
543 cd_to_producer => [ { producer => { name => 'Cowboy Neal' } }, ],
544 }
545 );
546
547 my $m2m_cd =
548 $schema->resultset('CD')->search( { title => 'Warble Marble' } );
549 is( $m2m_cd->count, 1, 'One CD row created via M2M create' );
550 is( $m2m_cd->first->producers->count,
551 1, 'CD row created with one producer' );
552 is( $m2m_cd->first->producers->first->name,
553 'Cowboy Neal', 'Correct producer row created' );
554 };
555
556 diag '* And the insane multicreate';
557
558 # (should work, despite the fact that no one will probably use it this way)
559
560 # first count how many rows do we initially have
561 my $counts;
562 $counts->{$_} = $schema->resultset($_)->count
563 for qw/Artist CD Genre Producer Tag/;
564
565 # do the crazy create
566 eval {
567 my $greatest_collections =
568 $schema->resultset('Genre')
569 ->create( { name => '"Greatest" collections' } );
570 my $greatest_collections2 =
571 $schema->resultset('Genre')
572 ->create( { name => '"Greatest" collections2' } );
573
574 $schema->resultset('CD')->recursive_update(
575 { artist => { name => 'james', },
576 title => 'Greatest hits 1',
577 year => '2012',
578 genre => $greatest_collections,
579 tags => [ { tag => 'A' }, { tag => 'B' }, ],
580 cd_to_producer => [
581 { producer => {
582 name => 'bob',
583 producer_to_cd => [
584 { cd => {
585 artist => {
586 name => 'lars',
587 cds => [
588 { title => 'Greatest hits 2',
589 year => 2012,
590 genre =>
591 $greatest_collections,
592 tags => [
593 { tag => 'A' },
594 { tag => 'B' },
595 ],
596
597 # This cd is created via artist so it doesn't know about producers
598 cd_to_producer => [
599
600 # if we specify 'bob' here things bomb
601 # as the producer attached to Greatest Hits 1 is
602 # already created, but not yet inserted.
603 # Maybe this can be fixed, but things are hairy
604 # enough already.
605 #
606 #{ producer => { name => 'bob' } },
607 { producer => {
608 name => 'paul'
609 }
610 },
611 { producer => {
612 name =>
613 'flemming',
614 producer_to_cd =>
615 [
616 { cd => {
617 artist =>
618 {
619 name =>
620 'kirk',
621 cds =>
622 [
623 { title =>
624 'Greatest hits 3',
625 year =>
626 2012,
627 genre =>
628 $greatest_collections,
629 tags =>
630 [
631 { tag =>
632 'A'
633 }
634 ,
635 { tag =>
636 'B'
637 }
638 ,
639 ]
640 ,
641 }
642 ,
643 { title =>
644 'Greatest hits 4',
645 year =>
646 2012,
647 genre =>
648 $greatest_collections2,
649 tags =>
650 [
651 { tag =>
652 'A'
653 }
654 ,
655 { tag =>
656 'B'
657 }
658 ,
659 ]
660 ,
661 }
662 ,
663 ]
664 ,
665 },
666 title =>
667 'Greatest hits 5',
668 year =>
669 2013,
670 genre =>
671 $greatest_collections2,
672 }
673 },
674 ],
675 }
676 },
677 ],
678 },
679 ],
680 },
681 title => 'Greatest hits 6',
682 year => 2012,
683 genre => $greatest_collections,
684 tags => [
685 { tag => 'A' },
686 { tag => 'B' },
687 ],
688 },
689 },
690 { cd => {
691 artist => {
692 name => 'lars',
693
694 # in recursive_update this creates a new artist - since no id provided
695 # in original create -
696 # should already exist
697 # even though the artist 'name' is not uniquely constrained
698 # find_or_create will arguably DWIM
699 },
700 title => 'Greatest hits 7',
701 year => 2013,
702 },
703 },
704 ],
705 },
706 },
707 ],
708 }
709 );
710
711 is( $schema->resultset('Artist')->count,
712 $counts->{Artist} + 4,
713 '4 new artists created'
714 );
715 is( $schema->resultset('Genre')->count,
716 $counts->{Genre} + 2,
717 '2 additional genres created'
718 );
719 is( $schema->resultset('Producer')->count,
720 $counts->{Producer} + 3,
721 '3 new producer'
722 );
723 is( $schema->resultset('CD')->count, $counts->{CD} + 7, '7 new CDs' );
724 is( $schema->resultset('Tag')->count, $counts->{Tag} + 10,
725 '10 new Tags' );
726
727 my $cd_rs =
728 $schema->resultset('CD')
729 ->search( { title => { -like => 'Greatest hits %' } },
730 { order_by => 'title' } );
731 is( $cd_rs->count, 7, '7 greatest hits created' );
732
733 my $cds_2012 = $cd_rs->search( { year => 2012 } );
734 is( $cds_2012->count, 5, '5 CDs created in 2012' );
735
736 is( $cds_2012->search(
737 { 'tags.tag' => { -in => [qw/A B/] } },
738 { join => 'tags', group_by => 'me.cdid' }
739 ),
740 5,
741 'All 10 tags were pairwise distributed between 5 year-2012 CDs'
742 );
743
744 my $paul_prod = $cd_rs->search( { 'producer.name' => 'paul' },
745 { join => { cd_to_producer => 'producer' } } );
746 is( $paul_prod->count, 1, 'Paul had 1 production' );
747 my $pauls_cd = $paul_prod->single;
748 is( $pauls_cd->cd_to_producer->count, 2, 'Paul had one co-producer' );
749 is( $pauls_cd->search_related(
750 'cd_to_producer',
751 { 'producer.name' => 'flemming' },
752 { join => 'producer' }
753 )->count,
754 1,
755 'The second producer is flemming',
756 );
757
758 my $kirk_cds =
759 $cd_rs->search( { 'artist.name' => 'kirk' }, { join => 'artist' } );
760 is( $kirk_cds, 3, 'Kirk had 3 CDs' );
761 is( $kirk_cds->search(
762 { 'cd_to_producer.cd' => { '!=', undef } },
763 { join => 'cd_to_producer' },
764 ),
765 1,
766 'Kirk had a producer only on one cd',
767 );
768
769 my $lars_cds =
770 $cd_rs->search( { 'artist.name' => 'lars' }, { join => 'artist' } );
771 is( $lars_cds->count, 3, 'Lars had 3 CDs' );
772 is( $lars_cds->search(
773 { 'cd_to_producer.cd' => undef },
774 { join => 'cd_to_producer' },
775 ),
776 0,
777 'Lars always had a producer',
778 );
779 is( $lars_cds->search_related(
780 'cd_to_producer',
781 { 'producer.name' => 'flemming' },
782 { join => 'producer' }
783 )->count,
784 1,
785 'Lars produced 1 CD with flemming',
786 );
787 is( $lars_cds->search_related(
788 'cd_to_producer',
789 { 'producer.name' => 'bob' },
790 { join => 'producer' }
791 )->count,
792 2,
793 'Lars produced 2 CDs with bob',
794 );
795
796 my $bob_prod = $cd_rs->search( { 'producer.name' => 'bob' },
797 { join => { cd_to_producer => 'producer' } } );
798 is( $bob_prod->count, 3, 'Bob produced a total of 3 CDs' );
799
800 is( $bob_prod->search( { 'artist.name' => 'james' },
801 { join => 'artist' } )->count,
802 1,
803 "Bob produced james' only CD",
804 );
805 };
806 diag $@ if $@;
807
808 ## Test for the might_have is allowed empty bug (should check and see if this
809 ## needs patching upstream to DBIC
810
811 use DBIx::Class::ResultSet::RecursiveUpdate;
812
813 my $might_have = {
814 artwork => undef,
815 liner_notes => undef,
816 tracks => [ { title => 'hello', pos => '100' } ],
817 single_track_row => undef,
818 };
819
820 ok my $might_have_cd_rs = $schema->resultset('CD'), 'got a good resultset';
821 ok my $might_have_cd_row = $might_have_cd_rs->first, 'got cd to test';
822
823 my $track = $schema->resultset('Track')->next;
824 $might_have_cd_row->single_track_row($track);
825 $might_have_cd_row->update;
826
827 DBIx::Class::ResultSet::RecursiveUpdate::Functions::recursive_update(
828 resultset => $might_have_cd_rs,
829 updates => $might_have,
830 object => $might_have_cd_row,
831 );
832
833 is( $might_have_cd_row->single_track, undef, 'Might have deleted' );
834
835 1;
836
837 done_testing();
This page took 0.076334 seconds and 5 git commands to generate.