File: m2m.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (30 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use strict;
use warnings;

use Test::More;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;

plan tests => 4;

my $schema = DBICTest->init_schema();

lives_ok ( sub {

  my $prod_rs = $schema->resultset ('Producer');
  my $prod_count = $prod_rs->count;

  my $cd = $schema->resultset('CD')->first;
  $cd->add_to_producers ({name => 'new m2m producer'});

  is ($prod_rs->count, $prod_count + 1, 'New producer created');
  ok ($cd->producers->find ({name => 'new m2m producer'}), 'Producer created with correct name');

  my $cd2 = $schema->resultset('CD')->search ( { cdid => { '!=', $cd->cdid } }, {rows => 1} )->single;  # retrieve a cd different from the first
  $cd2->add_to_producers ({name => 'new m2m producer'});                                                # attach to an existing producer
  ok ($cd2->producers->find ({name => 'new m2m producer'}), 'Existing producer attached to existing cd');

}, 'Test far-end find_or_create over many_to_many');

1;