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