Skip error/warn frames within CAG - saner callsite error messages this way
[dbsrgits/DBIx-Class.git] / t / 97result_class.t
CommitLineData
6c0ddbf7 1use strict;
2use warnings;
3
4use Test::More;
c5bc9ba6 5use Test::Exception;
6c0ddbf7 6use lib qw(t/lib);
7use DBICTest;
8
9my $schema = DBICTest->init_schema();
10
c5bc9ba6 11plan tests => 12;
6c0ddbf7 12
13{
14 my $cd_rc = $schema->resultset("CD")->result_class;
15
c5bc9ba6 16 throws_ok {
17 $schema->resultset("Artist")
18 ->search_rs({}, {result_class => "IWillExplode"})
19 } qr/Can't locate IWillExplode/, 'nonexistant result_class exception';
20
21# to make ensure_class_loaded happy, dies on inflate
22 eval 'package IWillExplode; sub dummy {}';
23
6c0ddbf7 24 my $artist_rs = $schema->resultset("Artist")
25 ->search_rs({}, {result_class => "IWillExplode"});
26 is($artist_rs->result_class, 'IWillExplode', 'Correct artist result_class');
c5bc9ba6 27
28 throws_ok {
29 $artist_rs->result_class('mtfnpy')
30 } qr/Can't locate mtfnpy/,
31 'nonexistant result_access exception (from accessor)';
32
33 throws_ok {
34 $artist_rs->first
35 } qr/Can't locate object method "inflate_result" via package "IWillExplode"/,
36 'IWillExplode explodes on inflate';
37
6c0ddbf7 38 my $cd_rs = $artist_rs->related_resultset('cds');
39 is($cd_rs->result_class, $cd_rc, 'Correct cd result_class');
b72d5dd3 40
41 my $cd_rs2 = $schema->resultset("Artist")->search_rs({})->related_resultset('cds');
42 is($cd_rs->result_class, $cd_rc, 'Correct cd2 result_class');
43
44 my $cd_rs3 = $schema->resultset("Artist")->search_rs({},{})->related_resultset('cds');
45 is($cd_rs->result_class, $cd_rc, 'Correct cd3 result_class');
6c0ddbf7 46
b72d5dd3 47 isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class');
6c0ddbf7 48}
49
50
51{
52 my $cd_rc = $schema->resultset("CD")->result_class;
53
54 my $artist_rs = $schema->resultset("Artist")
b72d5dd3 55 ->search_rs({}, {result_class => "IWillExplode"})->search({artistid => 1});
6c0ddbf7 56 is($artist_rs->result_class, 'IWillExplode', 'Correct artist result_class');
57
58 my $cd_rs = $artist_rs->related_resultset('cds');
59 is($cd_rs->result_class, $cd_rc, 'Correct cd result_class');
60
61 isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class');
b72d5dd3 62 isa_ok(eval{ $cd_rs->search({ cdid => 1 })->first }, $cd_rc, 'Inflated into correct cd result_class');
6c0ddbf7 63}