10 my $schema = DBICTest->init_schema();
13 my $cd_rc = $schema->resultset("CD")->result_class;
16 $schema->resultset("Artist")
17 ->search_rs({}, {result_class => "IWillExplode"})
18 } qr/Can't locate IWillExplode/, 'nonexistant result_class exception';
20 # to make ensure_class_loaded happy, dies on inflate
21 eval 'package IWillExplode; sub dummy {}';
23 my $artist_rs = $schema->resultset("Artist")
24 ->search_rs({}, {result_class => "IWillExplode"});
25 is($artist_rs->result_class, 'IWillExplode', 'Correct artist result_class');
28 $artist_rs->result_class('mtfnpy')
29 } qr/Can't locate mtfnpy/,
30 'nonexistant result_access exception (from accessor)';
34 } qr/\QInflator IWillExplode does not provide an inflate_result() method/,
35 'IWillExplode explodes on inflate';
37 my $cd_rs = $artist_rs->related_resultset('cds');
38 is($cd_rs->result_class, $cd_rc, 'Correct cd result_class');
40 my $cd_rs2 = $schema->resultset("Artist")->search_rs({})->related_resultset('cds');
41 is($cd_rs->result_class, $cd_rc, 'Correct cd2 result_class');
43 my $cd_rs3 = $schema->resultset("Artist")->search_rs({},{})->related_resultset('cds');
44 is($cd_rs->result_class, $cd_rc, 'Correct cd3 result_class');
46 isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class');
51 my $cd_rc = $schema->resultset("CD")->result_class;
53 my $artist_rs = $schema->resultset("Artist")
54 ->search_rs({}, {result_class => "IWillExplode"})->search({artistid => 1});
55 is($artist_rs->result_class, 'IWillExplode', 'Correct artist result_class');
57 my $cd_rs = $artist_rs->related_resultset('cds');
58 is($cd_rs->result_class, $cd_rc, 'Correct cd result_class');
60 isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class');
61 isa_ok(eval{ $cd_rs->search({ cdid => 1 })->first }, $cd_rc, 'Inflated into correct cd result_class');
65 my $rs = $schema->resultset('Artist')->search(
66 { 'cds.title' => 'Spoonful of bees' },
67 { prefetch => 'cds', result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
70 is ($rs->result_class, 'DBIx::Class::ResultClass::HashRefInflator', 'starting with correct resultclass');
72 $rs->result_class('DBICTest::Artist');
73 is ($rs->result_class, 'DBICTest::Artist', 'resultclass changed');
76 is (ref $art, 'DBICTest::Artist', 'Correcty blessed output');
79 { $rs->result_class('IWillExplode') }
80 qr/\QChanging the result_class of a ResultSet instance with an active cursor is not supported/,
81 'Throws on result class change in progress'
87 { $cds->result_class('IWillExplode') }
88 qr/\QChanging the result_class of a ResultSet instance with cached results is a noop/,
89 'Warning on noop result_class change'
92 is ($cds->result_class, 'IWillExplode', 'class changed anyway');
94 # even though the original was HRI (at $rs definition time above)
95 # we lost the control over the *prefetched* object result class
96 # when we handed the root object creation to ::Row::inflate_result
97 is( ref $cds->next, 'DBICTest::CD', 'Correctly inflated prefetched result');