X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F101populate_rs.t;h=5686c3ec4f04a6531acdee0799f1d9bcd1063945;hb=0d2033c32e2efba74edab1cd83814fe8ec1f7a33;hp=8a0eea431c1bff303dc734f9ba342cb17803e3c2;hpb=8d005ad9929e4bf227919cb6374e2a9e9689324f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/101populate_rs.t b/t/101populate_rs.t index 8a0eea4..5686c3e 100644 --- a/t/101populate_rs.t +++ b/t/101populate_rs.t @@ -12,6 +12,8 @@ use strict; use warnings; use Test::More; +use Test::Warn; +use Test::Exception; use lib qw(t/lib); use DBICTest; @@ -37,10 +39,10 @@ ok( $cd_rs, 'Got Good CD Resultset'); SCHEMA_POPULATE1: { - ## Test to make sure that the old $schema->populate is using the new method - ## for $resultset->populate when in void context and with sub objects. + # throw a monkey wrench + my $post_jnap_monkeywrench = $schema->resultset('Artist')->find(1)->update({ name => undef }); - $schema->populate('Artist', [ + warnings_exist { $schema->populate('Artist', [ [qw/name cds/], ["001First Artist", [ @@ -55,13 +57,13 @@ SCHEMA_POPULATE1: { [undef, [ {title=>"004Title1", year=>2010} ]], - ]); + ]) } qr/\QFast-path populate() of non-uniquely identifiable rows with related data is not possible/; isa_ok $schema, 'DBIx::Class::Schema'; - my ($undef, $artist1, $artist2, $artist3 ) = $schema->resultset('Artist')->search({ + my ( $preexisting_undef, $artist1, $artist2, $artist3, $undef ) = $schema->resultset('Artist')->search({ name=>["001First Artist","002Second Artist","003Third Artist", undef]}, - {order_by=>'name ASC'})->all; + {order_by => { -asc => 'artistid' }})->all; isa_ok $artist1, 'DBICTest::Artist'; isa_ok $artist2, 'DBICTest::Artist'; @@ -78,6 +80,8 @@ SCHEMA_POPULATE1: { ok $artist3->cds->count eq 1, "Got Right number of CDs for Artist3"; ok $undef->cds->count eq 1, "Got Right number of CDs for Artist4"; + $post_jnap_monkeywrench->delete; + ARTIST1CDS: { my ($cd1, $cd2, $cd3) = $artist1->cds->search(undef, {order_by=>'year ASC'}); @@ -475,7 +479,9 @@ VOID_CONTEXT: { }, ]; - $cd_rs->populate($cds); + warnings_exist { + $cd_rs->populate($cds) + } qr/\QFast-path populate() of belongs_to relationship data is not possible/; my ($cdA, $cdB) = $cd_rs->search( {title=>[sort map {$_->{title}} @$cds]}, @@ -515,7 +521,9 @@ VOID_CONTEXT: { }, ]; - $cd_rs->populate($cds); + warnings_exist { + $cd_rs->populate($cds); + } qr/\QFast-path populate() of belongs_to relationship data is not possible/; my ($cdA, $cdB, $cdC) = $cd_rs->search( {title=>[sort map {$_->{title}} @$cds]}, @@ -697,6 +705,26 @@ ARRAYREF_OF_ARRAYREF_STYLE: { } } -ok(eval { $art_rs->populate([]); 1 }, "Empty populate runs but does nothing"); +EMPTY_POPULATE: { + foreach( + [ empty => [] ], + [ columns_only => [ [qw(name rank charfield)] ] ], + ) { + my ($desc, $arg) = @{$_}; + + $schema->is_executed_sql_bind( sub { + + my $rs = $art_rs; + lives_ok { $rs->populate($arg); 1 } "$desc populate in void context lives"; + + my @r = $art_rs->populate($arg); + is_deeply( \@r, [], "$desc populate in list context returns empty list" ); + + my $r = $art_rs->populate($arg); + is( $r, undef, "$desc populate in scalar context returns undef" ); + + }, [], "$desc populate executed no statements" ); + } +} done_testing;