Commit | Line | Data |
c0329273 |
1 | BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } |
2 | |
577ef680 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
7 | use Test::Exception; |
c0329273 |
8 | |
577ef680 |
9 | use DBICTest; |
10 | |
11 | plan tests => 4; |
12 | |
13 | my $schema = DBICTest->init_schema(); |
14 | |
15 | lives_ok ( sub { |
16 | |
17 | my $prod_rs = $schema->resultset ('Producer'); |
18 | my $prod_count = $prod_rs->count; |
19 | |
20 | my $cd = $schema->resultset('CD')->first; |
21 | $cd->add_to_producers ({name => 'new m2m producer'}); |
22 | |
23 | is ($prod_rs->count, $prod_count + 1, 'New producer created'); |
24 | ok ($cd->producers->find ({name => 'new m2m producer'}), 'Producer created with correct name'); |
25 | |
26 | my $cd2 = $schema->resultset('CD')->search ( { cdid => { '!=', $cd->cdid } }, {rows => 1} )->single; # retrieve a cd different from the first |
27 | $cd2->add_to_producers ({name => 'new m2m producer'}); # attach to an existing producer |
a6866b9b |
28 | ok ($cd2->producers->find ({name => 'new m2m producer'}), 'Existing producer attached to existing cd'); |
577ef680 |
29 | |
30 | }, 'Test far-end find_or_create over many_to_many'); |
31 | |
32 | 1; |