Commit | Line | Data |
256c505c |
1 | use Test::More; |
2 | |
06d90c6b |
3 | plan tests => 8; |
256c505c |
4 | |
5 | use lib qw(t/lib); |
6 | |
7 | use_ok('DBICTest'); |
8 | |
9 | # has_a test |
10 | my $cd = DBICTest::CD->retrieve(4); |
11 | my ($artist) = $cd->search_related('artist'); |
12 | is($artist->name, 'Random Boy Band', 'has_a search_related ok'); |
13 | |
14 | # has_many test with an order_by clause defined |
15 | $artist = DBICTest::Artist->retrieve(1); |
16 | is( ($artist->search_related('cds'))[1]->title, 'Spoonful of bees', 'has_many search_related with order_by ok' ); |
17 | |
18 | # search_related with additional abstract query |
19 | my @cds = $artist->search_related('cds', { title => { like => '%of%' } } ); |
20 | is( $cds[1]->title, 'Forkful of bees', 'search_related with abstract query ok' ); |
21 | |
22 | # creating a related object |
23 | $artist->create_related( 'cds', { |
24 | title => 'Big Flop', |
25 | year => 2005, |
26 | } ); |
27 | is( ($artist->search_related('cds'))[3]->title, 'Big Flop', 'create_related ok' ); |
28 | |
06d90c6b |
29 | # count_related |
30 | is( $artist->count_related('cds'), 4, 'count_related ok' ); |
31 | |
0e5c2582 |
32 | SKIP: { |
33 | |
d2ff6175 |
34 | #skip "Relationship with invalid cols not yet checked", 1; |
0e5c2582 |
35 | |
256c505c |
36 | # try to add a bogus relationship using the wrong cols |
37 | eval { |
38 | $artist->add_relationship( |
39 | tracks => 'DBICTest::Track', |
40 | { 'foreign.cd' => 'self.cdid' } |
41 | ); |
42 | }; |
d2ff6175 |
43 | like($@, qr/Unknown column/, 'failed when creating a rel with invalid key, ok'); |
256c505c |
44 | |
0e5c2582 |
45 | } # End SKIP block |
46 | |
256c505c |
47 | # another bogus relationship using no join condition |
48 | eval { |
49 | $artist->add_relationship( tracks => 'DBICTest::Track' ); |
50 | }; |
1c6ae274 |
51 | like($@, qr/join condition/, 'failed when creating a rel without join condition, ok'); |