File: conditional_has_many.t

package info (click to toggle)
libdbix-class-resultset-recursiveupdate-perl 0.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,060 kB
  • sloc: perl: 5,130; sql: 640; makefile: 2
file content (94 lines) | stat: -rw-r--r-- 2,160 bytes parent folder | download | duplicates (4)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Exception;

use_ok 'AnotherTestDB::OnePK::Schema';

my $schema = AnotherTestDB::OnePK::Schema->connect('dbi:SQLite:dbname=:memory:');

isa_ok $schema, 'DBIx::Class::Schema';

lives_ok( sub{
	#$schema->deploy({add_drop_table => 1});
	$schema->deploy();
	$schema->populate('Item', [
		[ qw/idcol/ ],
		[ 1 ],
	]);
	$schema->populate('RelatedItem', [
		[ qw/idcol item_id/ ],
		[ 1, 1 ],
		[ 2, 1 ],
	]);
	$schema->populate('ConditionItem', [
		[ qw/idcol rel_item_id condition/ ],
		[ 1, 1, 'false' ],
		[ 2, 1, 'true' ],
		[ 3, 2, 'true' ],
		[ 4, 2, 'false' ],
	]);
}, 'creating and populating test database'
);

is($schema->resultset('Item')->find(1)->relateditems->count, 2);
is($schema->resultset('Item')->find(1)->true_relateditems->count, 2);

lives_ok(sub{
	$schema->resultset('Item')->recursive_update({
		idcol => 1,
		true_relateditems => [{ idcol => 1}],
	});
});

is($schema->resultset('Item')->find(1)->relateditems->count, 1);
is($schema->resultset('Item')->find(1)->true_relateditems->count, 1);

use_ok 'AnotherTestDB::TwoPK::Schema';

$schema = AnotherTestDB::TwoPK::Schema->connect('dbi:SQLite:dbname=:memory:');

isa_ok $schema, 'DBIx::Class::Schema';

lives_ok( sub{
	#$schema->deploy({add_drop_table => 1});
	$schema->deploy();
	$schema->populate('Item', [
		[ qw/idcol/ ],
		[ 1 ],
	]);
	$schema->populate('RelatedItem', [
		[ qw/idcol item_id/ ],
		[ 1, 1 ],
		[ 2, 1 ],
	]);
	$schema->populate('ConditionItem', [
		[ qw/idcol rel_item_id condition/ ],
		[ 1, 1, 'false' ],
		[ 2, 1, 'true' ],
		[ 3, 2, 'true' ],
		[ 4, 2, 'false' ],
	]);
}, 'creating and populating test database'
);

is($schema->resultset('Item')->find({idcol => 1})->relateditems->count, 2);
is($schema->resultset('Item')->find({idcol => 1})->true_relateditems->count, 2);

lives_ok(sub{
	$schema->resultset('Item')->recursive_update({
		idcol => 1,
		true_relateditems => [{
			idcol => 1,
			item_id => 1,
		}],
	});
});


is($schema->resultset('Item')->find({idcol => 1})->relateditems->count, 1);
is($schema->resultset('Item')->find({idcol => 1})->true_relateditems->count, 1);

done_testing;