X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F97result_class.t;h=faff994c09f0f587673f85c638e226fb24b019c1;hb=b775fa8e88ff5a798e4b4a198b782c76edd93f6b;hp=ab0863dc6f044577a705b6ce16b7554f73ed1784;hpb=8273e845426f0187b4ad6c4a1b42286fa09a648f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/97result_class.t b/t/97result_class.t index ab0863d..faff994 100644 --- a/t/97result_class.t +++ b/t/97result_class.t @@ -2,14 +2,13 @@ use strict; use warnings; use Test::More; +use Test::Warn; use Test::Exception; use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 12; - { my $cd_rc = $schema->resultset("CD")->result_class; @@ -32,7 +31,7 @@ plan tests => 12; throws_ok { $artist_rs->first - } qr/Can't locate object method "inflate_result" via package "IWillExplode"/, + } qr/\QInflator IWillExplode does not provide an inflate_result() method/, 'IWillExplode explodes on inflate'; my $cd_rs = $artist_rs->related_resultset('cds'); @@ -61,3 +60,41 @@ plan tests => 12; isa_ok(eval{ $cd_rs->find(1) }, $cd_rc, 'Inflated into correct cd result_class'); isa_ok(eval{ $cd_rs->search({ cdid => 1 })->first }, $cd_rc, 'Inflated into correct cd result_class'); } + +{ + my $rs = $schema->resultset('Artist')->search( + { 'cds.title' => 'Spoonful of bees' }, + { prefetch => 'cds', result_class => 'DBIx::Class::ResultClass::HashRefInflator' }, + ); + + is ($rs->result_class, 'DBIx::Class::ResultClass::HashRefInflator', 'starting with correct resultclass'); + + $rs->result_class('DBICTest::Artist'); + is ($rs->result_class, 'DBICTest::Artist', 'resultclass changed'); + + my $art = $rs->next; + is (ref $art, 'DBICTest::Artist', 'Correcty blessed output'); + + throws_ok + { $rs->result_class('IWillExplode') } + qr/\QChanging the result_class of a ResultSet instance with an active cursor is not supported/, + 'Throws on result class change in progress' + ; + + my $cds = $art->cds; + + warnings_exist + { $cds->result_class('IWillExplode') } + qr/\QChanging the result_class of a ResultSet instance with cached results is a noop/, + 'Warning on noop result_class change' + ; + + is ($cds->result_class, 'IWillExplode', 'class changed anyway'); + + # even though the original was HRI (at $rs definition time above) + # we lost the control over the *prefetched* object result class + # when we handed the root object creation to ::Row::inflate_result + is( ref $cds->next, 'DBICTest::CD', 'Correctly inflated prefetched result'); +} + +done_testing;