1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
12 my $schema = DBICTest->init_schema();
15 my $cd_rc = $schema->resultset("CD")->result_class;
18 $schema->resultset("Artist")
19 ->search_rs({}, {result_class => "IWillExplode"})
20 } qr/Can't locate IWillExplode/, 'nonexistant result_class exception';
22 # to make ensure_class_loaded happy, dies on inflate
23 eval 'package IWillExplode; sub dummy {}';
25 my $artist_rs = $schema->resultset("Artist")
26 ->search_rs({}, {result_class => "IWillExplode"});
27 is($artist_rs->result_class, 'IWillExplode', 'Correct artist result_class');
30 $artist_rs->result_class('mtfnpy')
31 } qr/Can't locate mtfnpy/,
32 'nonexistant result_access exception (from accessor)';
36 } qr/\QInflator IWillExplode does not provide an inflate_result() method/,
37 'IWillExplode explodes on inflate';
39 my $cd_rs = $artist_rs->related_resultset('cds');
40 is($cd_rs->result_class, $cd_rc, 'Correct cd result_class');
42 my $cd_rs2 = $schema->resultset("Artist")->search_rs({})->related_resultset('cds');
43 is($cd_rs->result_class, $cd_rc, 'Correct cd2 result_class');
45 my $cd_rs3 = $schema->resultset("Artist")->search_rs({},{})->related_resultset('cds');
46 is($cd_rs->result_class, $cd_rc, 'Correct cd3 result_class');
48 isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class');
53 my $cd_rc = $schema->resultset("CD")->result_class;
55 my $artist_rs = $schema->resultset("Artist")
56 ->search_rs({}, {result_class => "IWillExplode"})->search({artistid => 1});
57 is($artist_rs->result_class, 'IWillExplode', 'Correct artist result_class');
59 my $cd_rs = $artist_rs->related_resultset('cds');
60 is($cd_rs->result_class, $cd_rc, 'Correct cd result_class');
62 isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class');
63 isa_ok(eval{ $cd_rs->search({ cdid => 1 })->first }, $cd_rc, 'Inflated into correct cd result_class');
67 my $rs = $schema->resultset('Artist')->search(
68 { 'cds.title' => 'Spoonful of bees' },
69 { prefetch => 'cds', result_class => 'DBIx::Class::ResultClass::HashRefInflator' },
72 is ($rs->result_class, 'DBIx::Class::ResultClass::HashRefInflator', 'starting with correct resultclass');
74 $rs->result_class('DBICTest::Artist');
75 is ($rs->result_class, 'DBICTest::Artist', 'resultclass changed');
78 is (ref $art, 'DBICTest::Artist', 'Correcty blessed output');
81 { $rs->result_class('IWillExplode') }
82 qr/\QChanging the result_class of a ResultSet instance with an active cursor is not supported/,
83 'Throws on result class change in progress'
89 { $cds->result_class('IWillExplode') }
90 qr/\QChanging the result_class of a ResultSet instance with cached results is a noop/,
91 'Warning on noop result_class change'
94 is ($cds->result_class, 'IWillExplode', 'class changed anyway');
96 # even though the original was HRI (at $rs definition time above)
97 # we lost the control over the *prefetched* object result class
98 # when we handed the root object creation to ::Row::inflate_result
99 is( ref $cds->next, 'DBICTest::CD', 'Correctly inflated prefetched result');