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