Institute a central "load this first in testing" package
[dbsrgits/DBIx-Class.git] / t / relationship / proxy.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
97c96475 3use strict;
4use warnings;
5
6use Test::More;
7use Test::Exception;
c0329273 8
97c96475 9use DBICTest;
10
11my $schema = DBICTest->init_schema();
12
13my $cd = $schema->resultset('CD')->find(2);
14is($cd->notes, $cd->liner_notes->notes, 'notes proxy ok');
15is($cd->artist_name, $cd->artist->name, 'artist_name proxy ok');
16
17my $track = $cd->tracks->first;
18is($track->cd_title, $track->cd->title, 'cd_title proxy ok');
19is($track->cd_title, $cd->title, 'cd_title proxy II ok');
20is($track->year, $cd->year, 'year proxy ok');
21
22my $tag = $schema->resultset('Tag')->first;
23is($tag->year, $tag->cd->year, 'year proxy II ok');
24is($tag->cd_title, $tag->cd->title, 'cd_title proxy III ok');
25
26my $bookmark = $schema->resultset('Bookmark')->create ({
27 link => { url => 'http://cpan.org', title => 'CPAN' },
28});
29my $link = $bookmark->link;
30ok($bookmark->link_id == $link->id, 'link_id proxy ok');
31is($bookmark->link_url, $link->url, 'link_url proxy ok');
32is($bookmark->link_title, $link->title, 'link_title proxy ok');
33
34my $cd_source_class = $schema->class('CD');
35throws_ok {
36 $cd_source_class->add_relationship('artist_regex',
37 'DBICTest::Schema::Artist', {
38 'foreign.artistid' => 'self.artist'
39 }, { proxy => qr/\w+/ }
40 ) } qr/unable \s to \s process \s the \s \'proxy\' \s argument/ix,
41 'proxy attr with a regex ok';
42throws_ok {
43 $cd_source_class->add_relationship('artist_sub',
44 'DBICTest::Schema::Artist', {
45 'foreign.artistid' => 'self.artist'
46 }, { proxy => sub {} }
47 ) } qr/unable \s to \s process \s the \s \'proxy\' \s argument/ix,
48 'proxy attr with a sub ok';
49
50done_testing;