Fix serious DBD::SQLite numeric datatype mismatch regression
[dbsrgits/DBIx-Class.git] / t / delete / related.t
CommitLineData
157fdb0c 1use Test::More;
2use strict;
3use warnings;
4use lib qw(t/lib);
5use DBICTest;
6
c2704243 7plan tests => 4;
157fdb0c 8
9my $schema = DBICTest->init_schema();
10
11my $ars = $schema->resultset('Artist');
12my $cdrs = $schema->resultset('CD');
c2704243 13my $cd2pr_rs = $schema->resultset('CD_to_Producer');
157fdb0c 14
15# create some custom entries
ecef7b5e 16$ars->populate ([
17 [qw/artistid name/],
18 [qw/71 a1/],
19 [qw/72 a2/],
20 [qw/73 a3/],
21]);
c2704243 22
157fdb0c 23$cdrs->populate ([
24 [qw/cdid artist title year/],
ecef7b5e 25 [qw/70 71 delete0 2005/],
26 [qw/71 72 delete1 2005/],
27 [qw/72 72 delete2 2005/],
28 [qw/73 72 delete3 2006/],
29 [qw/74 72 delete4 2007/],
30 [qw/75 73 delete5 2008/],
157fdb0c 31]);
32
c2704243 33my $prod = $schema->resultset('Producer')->create ({ name => 'deleter' });
34my $prod_cd = $cdrs->find (70);
35my $cd2pr = $cd2pr_rs->create ({
36 producer => $prod,
37 cd => $prod_cd,
38});
39
157fdb0c 40my $total_cds = $cdrs->count;
41
42# test that delete_related w/o conditions deletes all related records only
ecef7b5e 43$ars->search ({name => 'a3' })->search_related ('cds')->delete;
157fdb0c 44is ($cdrs->count, $total_cds -= 1, 'related delete ok');
45
ecef7b5e 46my $a2_cds = $ars->search ({ name => 'a2' })->search_related ('cds');
157fdb0c 47
48# test that related deletion w/conditions deletes just the matched related records only
ecef7b5e 49$a2_cds->search ({ year => 2005 })->delete;
157fdb0c 50is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok');
51
52# test that related deletion with limit condition works
ecef7b5e 53$a2_cds->search ({}, { rows => 1})->delete;
157fdb0c 54is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok');
c2704243 55
56TODO: {
57 local $TODO = 'delete_related is based on search_related which is based on search which does not understand object arguments';
632d1e0f 58 local $SIG{__WARN__} = sub {}; # trap the non-numeric warning, remove when the TODO is removed
59
c2704243 60 my $cd2pr_count = $cd2pr_rs->count;
61 $prod_cd->delete_related('cd_to_producer', { producer => $prod } );
62 is ($cd2pr_rs->count, $cd2pr_count -= 1, 'm2m link deleted succesfully');
63}