1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
10 my $schema = DBICTest->init_schema();
14 my $artist = $schema->resultset ('Artist')->first;
16 my $genre = $schema->resultset ('Genre')
17 ->create ({ name => 'par excellence' });
19 is ($genre->search_related( 'model_cd' )->count, 0, 'No cds yet');
22 $genre->update_or_create_related ('model_cd', {
25 title => 'the best thing since sliced bread',
28 # verify cd was inserted ok
29 is ($genre->search_related( 'model_cd' )->count, 1, 'One cd');
30 my $cd = $genre->find_related ('model_cd', {});
32 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
34 artist => $artist->id,
36 title => 'the best thing since sliced bread',
38 'CD created correctly',
41 # expect a year update on the only related row
42 # (non-qunique column + unique column as disambiguator)
43 $genre->update_or_create_related ('model_cd', {
45 title => 'the best thing since sliced bread',
48 # re-fetch the cd, verify update
49 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
50 $cd = $genre->find_related ('model_cd', {});
52 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
54 artist => $artist->id,
56 title => 'the best thing since sliced bread',
58 'CD year column updated correctly',
62 # expect an update of the only related row
63 # (update a unique column)
64 $genre->update_or_create_related ('model_cd', {
65 title => 'the best thing since vertical toasters',
68 # re-fetch the cd, verify update
69 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
70 $cd = $genre->find_related ('model_cd', {});
72 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
74 artist => $artist->id,
76 title => 'the best thing since vertical toasters',
78 'CD title column updated correctly',
82 # expect a year update on the only related row
83 # (non-unique column only)
84 $genre->update_or_create_related ('model_cd', {
88 # re-fetch the cd, verify update
89 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
90 $cd = $genre->find_related ('model_cd', {});
92 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
94 artist => $artist->id,
96 title => 'the best thing since vertical toasters',
98 'CD year column updated correctly without a disambiguator',