Make sure the taint test does some DB-level ops
[dbsrgits/DBIx-Class.git] / t / multi_create / diamond.t
CommitLineData
195ce039 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8
9sub mc_diag { diag (@_) if $ENV{DBIC_MULTICREATE_DEBUG} };
10
11my $schema = DBICTest->init_schema();
12
13mc_diag (<<'DG');
14* Try a diamond multicreate
15
16Artist -> has_many -> Artwork_to_Artist -> belongs_to
17 /
18 belongs_to <- CD <- belongs_to <- Artwork <-/
19 \
20 \-> Artist2
21
22DG
23
24lives_ok (sub {
25 $schema->resultset ('Artist')->create ({
26 name => 'The wooled wolf',
27 artwork_to_artist => [{
28 artwork => {
29 cd => {
30 title => 'Wool explosive',
31 year => 1999,
32 artist => { name => 'The black exploding sheep' },
33 }
34 }
35 }],
36 });
37
38 my $art2 = $schema->resultset ('Artist')->find ({ name => 'The black exploding sheep' });
39 ok ($art2, 'Second artist exists');
40
41 my $cd = $art2->cds->single;
42 is ($cd->title, 'Wool explosive', 'correctly created CD');
43
44 is_deeply (
45 [ $cd->artwork->artists->get_column ('name')->all ],
46 [ 'The wooled wolf' ],
47 'Artist correctly attached to artwork',
48 );
49
50}, 'Diamond chain creation ok');
51
52done_testing;