Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
e084cb2b |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
c0329273 |
7 | |
e084cb2b |
8 | use DBICTest; |
9 | |
10 | my $schema = DBICTest->init_schema( no_populate => 1 ); |
11 | |
12 | my $t11 = $schema->resultset('Track')->find_or_create({ |
13 | trackid => 1, |
14 | title => 'Track one cd one', |
15 | cd => { |
16 | year => 1, |
17 | title => 'CD one', |
18 | very_long_artist_relationship => { |
19 | name => 'Artist one', |
20 | } |
21 | } |
22 | }); |
23 | |
24 | my $t12 = $schema->resultset('Track')->find_or_create({ |
25 | trackid => 2, |
26 | title => 'Track two cd one', |
27 | cd => { |
28 | title => 'CD one', |
29 | very_long_artist_relationship => { |
30 | name => 'Artist one', |
31 | } |
32 | } |
33 | }); |
34 | |
35 | # FIXME - MC should be smart enough to infer this on its own... |
36 | $schema->resultset('Artist')->create({ name => 'Artist two' }); |
37 | |
38 | my $t2 = $schema->resultset('Track')->find_or_create({ |
39 | trackid => 3, |
40 | title => 'Track one cd one', |
41 | cd => { |
42 | year => 1, |
43 | title => 'CD one', |
44 | very_long_artist_relationship => { |
45 | name => 'Artist two', |
46 | } |
47 | } |
48 | }); |
49 | |
50 | is_deeply( |
51 | $schema->resultset('Artist')->search({}, { |
52 | prefetch => { cds => 'tracks' }, |
53 | order_by => 'tracks.title', |
54 | })->all_hri, |
55 | [ |
56 | { artistid => 1, charfield => undef, name => "Artist one", rank => 13, cds => [ |
57 | { artist => 1, cdid => 1, genreid => undef, single_track => undef, title => "CD one", year => 1, tracks => [ |
58 | { cd => 1, last_updated_at => undef, last_updated_on => undef, position => 1, title => "Track one cd one", trackid => 1 }, |
59 | { cd => 1, last_updated_at => undef, last_updated_on => undef, position => 2, title => "Track two cd one", trackid => 2 }, |
60 | ]}, |
61 | ]}, |
62 | { artistid => 2, charfield => undef, name => "Artist two", rank => 13, cds => [ |
63 | { artist => 2, cdid => 2, genreid => undef, single_track => undef, title => "CD one", year => 1, tracks => [ |
64 | { cd => 2, last_updated_at => undef, last_updated_on => undef, position => 1, title => "Track one cd one", trackid => 3 }, |
65 | ]}, |
66 | ]}, |
67 | ], |
68 | 'Expected state of database after several find_or_create rounds' |
69 | ); |
70 | |
71 | |
72 | done_testing; |
73 | |