From: Jess Robinson Date: Wed, 1 Aug 2012 22:16:07 +0000 (+0100) Subject: New test for recent prefetch/undef bug X-Git-Tag: v0.08199~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a48693f42edb71a1a06fdc08944a379fd98e6999;p=dbsrgits%2FDBIx-Class.git New test for recent prefetch/undef bug --- diff --git a/t/lib/PrefetchBug.pm b/t/lib/PrefetchBug.pm new file mode 100644 index 0000000..278bf5b --- /dev/null +++ b/t/lib/PrefetchBug.pm @@ -0,0 +1,11 @@ +package + PrefetchBug; + +use strict; +use warnings; + +use base qw/DBIx::Class::Schema/; + +__PACKAGE__->load_classes(); + +1; diff --git a/t/lib/PrefetchBug/Left.pm b/t/lib/PrefetchBug/Left.pm new file mode 100644 index 0000000..34d362b --- /dev/null +++ b/t/lib/PrefetchBug/Left.pm @@ -0,0 +1,20 @@ +package PrefetchBug::Left; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table('prefetchbug_left'); +__PACKAGE__->add_columns( + id => { data_type => 'integer', is_auto_increment => 1 }, +); + +__PACKAGE__->set_primary_key('id'); + +__PACKAGE__->has_many( + prefetch_leftright => 'PrefetchBug::LeftRight', + 'left_id' +); + +1; diff --git a/t/lib/PrefetchBug/LeftRight.pm b/t/lib/PrefetchBug/LeftRight.pm new file mode 100644 index 0000000..cf76ec0 --- /dev/null +++ b/t/lib/PrefetchBug/LeftRight.pm @@ -0,0 +1,24 @@ +package + PrefetchBug::LeftRight; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table('left_right'); +__PACKAGE__->add_columns( + left_id => { data_type => 'integer' }, + right_id => { data_type => 'integer' }, + value => {}); + +__PACKAGE__->set_primary_key('left_id', 'right_id'); +__PACKAGE__->belongs_to(left => 'PrefetchBug::Left', 'left_id'); +__PACKAGE__->belongs_to( + right => 'PrefetchBug::Right', + 'right_id', +# {join_type => 'left'} +); + + +1; diff --git a/t/lib/PrefetchBug/Right.pm b/t/lib/PrefetchBug/Right.pm new file mode 100644 index 0000000..3576bad --- /dev/null +++ b/t/lib/PrefetchBug/Right.pm @@ -0,0 +1,14 @@ +package + PrefetchBug::Right; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +__PACKAGE__->table('prefetch_right'); +__PACKAGE__->add_columns(qw/ id name category description propagates locked/); +__PACKAGE__->set_primary_key('id'); + +__PACKAGE__->has_many('prefetch_leftright', 'PrefetchBug::LeftRight', 'right_id'); +1; diff --git a/t/prefetch/undef_prefetch_bug.t b/t/prefetch/undef_prefetch_bug.t new file mode 100644 index 0000000..8f9ee07 --- /dev/null +++ b/t/prefetch/undef_prefetch_bug.t @@ -0,0 +1,36 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; +use PrefetchBug; + +BEGIN { + require DBIx::Class; + plan skip_all => 'Test needs ' . + DBIx::Class::Optional::Dependencies->req_missing_for('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for('deploy'); +} + + my $schema + = PrefetchBug->connect( DBICTest->_database (quote_char => '"') ); + ok( $schema, 'Connected to PrefetchBug schema OK' ); + +#################### DEPLOY + + $schema->deploy( { add_drop_table => 1 } ); + +# Test simple has_many prefetch: + +my $leftc = $schema->resultset('Left')->create({}); +my $rightc = $schema->resultset('Right')->create({ id => 60, name => 'Johnny', category => 'something', description=> 'blah', propagates => 0, locked => 1 }); +$rightc->create_related('prefetch_leftright', { left => $leftc, value => 'lr' }); + +# start with fresh whatsit +my $left = $schema->resultset('Left')->find({ id => $leftc->id }); + +my @left_rights = $left->search_related('prefetch_leftright', {}, { prefetch => 'right' }); +ok(defined $left_rights[0]->right, 'Prefetched Right side correctly'); + +done_testing;