X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fhri.t;h=c3549d8247a3f7eea3f3b28a7f8aa698d40316ac;hb=592ff7c47c6aa82b37925b5b7a6fc25d1e7f0f36;hp=1d32dd6f4fbd112b33063f7f24c115f4c2edd4f2;hpb=e8b32a6d045b4d04ba023d48be1c8e32065fcec6;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/hri.t b/t/inflate/hri.t index 1d32dd6..c3549d8 100644 --- a/t/inflate/hri.t +++ b/t/inflate/hri.t @@ -1,7 +1,7 @@ use strict; -use warnings; +use warnings; -use Test::More qw(no_plan); +use Test::More; use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); @@ -9,26 +9,42 @@ my $schema = DBICTest->init_schema(); # Under some versions of SQLite if the $rs is left hanging around it will lock # So we create a scope here cos I'm lazy { - my $rs = $schema->resultset('CD'); + my $rs = $schema->resultset('CD')->search ({}, { + order_by => 'cdid', + # use the hashref inflator class as result class + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + }); # get the defined columns my @dbic_cols = sort $rs->result_source->columns; - # use the hashref inflator class as result class - $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); - # fetch first record my $datahashref1 = $rs->first; my @hashref_cols = sort keys %$datahashref1; is_deeply( \@dbic_cols, \@hashref_cols, 'returned columns' ); -} + my $cd1 = $rs->find ({cdid => 1}); + is_deeply ( $cd1, $datahashref1, 'first/find return the same thing'); + + my $cd2 = $rs->search({ cdid => 1 })->single; + is_deeply ( $cd2, $datahashref1, 'first/search+single return the same thing'); + + $rs->result_class('DBIx::Class::Row'); + + is( $rs->result_class, 'DBIx::Class::Row', 'result_class set' ); + + is( + $rs->search->result_class, 'DBIx::Class::ResultClass::HashRefInflator', + 'result_class set using accessor does not propagate over search' + ); + +} sub check_cols_of { my ($dbic_obj, $datahashref) = @_; - + foreach my $col (keys %$datahashref) { # plain column if (not ref ($datahashref->{$col}) ) { @@ -42,14 +58,14 @@ sub check_cols_of { elsif (ref ($datahashref->{$col}) eq 'ARRAY') { my @dbic_reltable = $dbic_obj->$col; my @hashref_reltable = @{$datahashref->{$col}}; - - is (scalar @hashref_reltable, scalar @dbic_reltable, 'number of related entries'); + + is (scalar @dbic_reltable, scalar @hashref_reltable, 'number of related entries'); # for my $index (0..scalar @hashref_reltable) { for my $index (0..scalar @dbic_reltable) { my $dbic_reltable_obj = $dbic_reltable[$index]; my $hashref_reltable_entry = $hashref_reltable[$index]; - + check_cols_of($dbic_reltable_obj, $hashref_reltable_entry); } } @@ -135,3 +151,6 @@ is_deeply( [{ $artist->get_columns, cds => [] }], 'nested has_many prefetch without entries' ); + +done_testing; +