File: 53delete_related.t

package info (click to toggle)
libdbix-class-perl 0.08010-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 2,052 kB
  • ctags: 1,064
  • sloc: perl: 10,536; sql: 225; makefile: 45
file content (30 lines) | stat: -rwxr-xr-x 1,081 bytes parent folder | download | duplicates (2)
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 Test::More;
use strict;
use warnings;
use lib qw(t/lib);
use DBICTest;

plan tests => 7;

my $schema = DBICTest->init_schema();
my $total_cds = $schema->resultset('CD')->count;
cmp_ok($total_cds, '>', 0, 'need cd records');

# test that delete_related w/o conditions deletes all related records only
my $artist = $schema->resultset("Artist")->find(3);
my $artist_cds = $artist->cds->count;
cmp_ok($artist_cds, '<', $total_cds, 'need more cds than just related cds');

ok($artist->delete_related('cds'));
cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist_cds), 'too many cds were deleted');

$total_cds -= $artist_cds;

# test that delete_related w/conditions deletes just the matched related records only
my $artist2 = $schema->resultset("Artist")->find(2);
my $artist2_cds = $artist2->search_related('cds')->count;
cmp_ok($artist2_cds, '<', $total_cds, 'need more cds than related cds');

ok($artist2->delete_related('cds', {title => {like => '%'}}));
cmp_ok($schema->resultset('CD')->count, '==', ($total_cds - $artist2_cds), 'too many cds were deleted');