X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100populate.t;h=8bb0fdc6671e1a21e7e78adcb9bd6c26b8fa5484;hb=84f7e8a1c6303091d753572648e37d3bd7270181;hp=ada70d9723158da4cf17b3ece1a13fa8a3769907;hpb=1295943f3917a0c475b3fa999ee2038ae9e9fb56;p=dbsrgits%2FDBIx-Class.git diff --git a/t/100populate.t b/t/100populate.t index ada70d9..8bb0fdc 100644 --- a/t/100populate.t +++ b/t/100populate.t @@ -5,6 +5,7 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; +use Path::Class::File (); my $schema = DBICTest->init_schema(); @@ -114,25 +115,46 @@ is($link7->id, 7, 'Link 7 id'); is($link7->url, undef, 'Link 7 url'); is($link7->title, 'gtitle', 'Link 7 title'); -# test _execute_array_empty (insert_bulk with all literal sql) -my $rs = $schema->resultset('Artist'); -$rs->delete; -$rs->populate([ +# populate with literals +{ + my $rs = $schema->resultset('Link'); + $rs->delete; + + # test _execute_array_empty (insert_bulk with all literal sql) + + $rs->populate([ (+{ - name => \"'DT'", - rank => \500, - charfield => \"'mtfnpy'", + url => \"'cpan.org'", + title => \"'The ''best of'' cpan'", }) x 5 -]); + ]); -is((grep { - $_->name eq 'DT' && - $_->rank == 500 && - $_->charfield eq 'mtfnpy' -} $rs->all), 5, 'populate with all literal SQL'); + is((grep { + $_->url eq 'cpan.org' && + $_->title eq "The 'best of' cpan", + } $rs->all), 5, 'populate with all literal SQL'); -$rs->delete; + $rs->delete; + + # test mixed binds with literal sql + + $rs->populate([ + (+{ + url => \"'cpan.org'", + title => "The 'best of' cpan", + }) x 5 + ]); + is((grep { + $_->url eq 'cpan.org' && + $_->title eq "The 'best of' cpan", + } $rs->all), 5, 'populate with all literal SQL'); + + $rs->delete; +} + +my $rs = $schema->resultset('Artist'); +$rs->delete; throws_ok { $rs->populate([ { @@ -196,4 +218,101 @@ throws_ok { ]); } qr/inconsistent/, 'literal sql must be the same in all slices'; +# the stringification has nothing to do with the artist name +# this is solely for testing consistency +my $fn = Path::Class::File->new ('somedir/somefilename.tmp'); +my $fn2 = Path::Class::File->new ('somedir/someotherfilename.tmp'); + +lives_ok { + $rs->populate([ + { + name => 'supplied before stringifying object', + }, + { + name => $fn, + } + ]); +} 'stringifying objects pass through'; + +# ... and vice-versa. + +lives_ok { + $rs->populate([ + { + name => $fn2, + }, + { + name => 'supplied after stringifying object', + }, + ]); +} 'stringifying objects pass through'; + +for ( + $fn, + $fn2, + 'supplied after stringifying object', + 'supplied before stringifying object' +) { + my $row = $rs->find ({name => $_}); + ok ($row, "Stringification test row '$_' properly inserted"); +} + +$rs->delete; + +# test stringification with ->create rather than Storage::insert_bulk as well + +lives_ok { + my @dummy = $rs->populate([ + { + name => 'supplied before stringifying object', + }, + { + name => $fn, + } + ]); +} 'stringifying objects pass through'; + +# ... and vice-versa. + +lives_ok { + my @dummy = $rs->populate([ + { + name => $fn2, + }, + { + name => 'supplied after stringifying object', + }, + ]); +} 'stringifying objects pass through'; + +for ( + $fn, + $fn2, + 'supplied after stringifying object', + 'supplied before stringifying object' +) { + my $row = $rs->find ({name => $_}); + ok ($row, "Stringification test row '$_' properly inserted"); +} + +lives_ok { + $schema->resultset('TwoKeys')->populate([{ + artist => 1, + cd => 5, + fourkeys_to_twokeys => [{ + f_foo => 1, + f_bar => 1, + f_hello => 1, + f_goodbye => 1, + autopilot => 'a', + },{ + f_foo => 2, + f_bar => 2, + f_hello => 2, + f_goodbye => 2, + autopilot => 'b', + }] + }]) +} 'multicol-PK has_many populate works'; + done_testing;