Introduce GOVERNANCE document and empty RESOLUTIONS file.
[dbsrgits/DBIx-Class.git] / t / relationship / proxy.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use DBICTest;
10
11 my $schema = DBICTest->init_schema();
12
13 my $cd = $schema->resultset('CD')->find(2);
14 is($cd->notes, $cd->liner_notes->notes, 'notes proxy ok');
15 is($cd->artist_name, $cd->artist->name, 'artist_name proxy ok');
16
17 my $track = $cd->tracks->first;
18 is($track->cd_title, $track->cd->title, 'cd_title proxy ok');
19 is($track->cd_title, $cd->title, 'cd_title proxy II ok');
20 is($track->year, $cd->year, 'year proxy ok');
21
22 my $tag = $schema->resultset('Tag')->first;
23 is($tag->year, $tag->cd->year, 'year proxy II ok');
24 is($tag->cd_title, $tag->cd->title, 'cd_title proxy III ok');
25
26 my $bookmark = $schema->resultset('Bookmark')->create ({
27   link => { url => 'http://cpan.org', title => 'CPAN' },
28 });
29 my $link = $bookmark->link;
30 ok($bookmark->link_id == $link->id, 'link_id proxy ok');
31 is($bookmark->link_url, $link->url, 'link_url proxy ok');
32 is($bookmark->link_title, $link->title, 'link_title proxy ok');
33
34 my $cd_source_class = $schema->class('CD');
35 throws_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';
42 throws_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
50 done_testing;