Column inflation tests now pass
[dbsrgits/DBIx-Class.git] / t / 06relationship.t
CommitLineData
256c505c 1use Test::More;
2
3plan tests => 7;
4
5use lib qw(t/lib);
6
7use_ok('DBICTest');
8
9# has_a test
10my $cd = DBICTest::CD->retrieve(4);
11my ($artist) = $cd->search_related('artist');
12is($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);
16is( ($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
19my @cds = $artist->search_related('cds', { title => { like => '%of%' } } );
20is( $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} );
27is( ($artist->search_related('cds'))[3]->title, 'Big Flop', 'create_related ok' );
28
0e5c2582 29SKIP: {
30
31 skip "Relationship with invalid cols not yet checked", 1;
32
256c505c 33# try to add a bogus relationship using the wrong cols
34eval {
35 $artist->add_relationship(
36 tracks => 'DBICTest::Track',
37 { 'foreign.cd' => 'self.cdid' }
38 );
39};
40like($@, qr/no such accessor/, 'failed when creating a rel with invalid key, ok');
41
0e5c2582 42} # End SKIP block
43
256c505c 44# another bogus relationship using no join condition
45eval {
46 $artist->add_relationship( tracks => 'DBICTest::Track' );
47};
1c6ae274 48like($@, qr/join condition/, 'failed when creating a rel without join condition, ok');