From: Arthur Axel 'fREW' Schmidt Date: Fri, 24 Aug 2012 02:34:58 +0000 (-0500) Subject: rewrite test to use existing schema X-Git-Tag: v0.08200~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=277b225f56728d9c3b1371017e8ca1d464f3c6eb;hp=6adcb2116d18e48e5723ec9e7dc0f844e75ed99c;p=dbsrgits%2FDBIx-Class.git rewrite test to use existing schema --- diff --git a/Changes b/Changes index 4e546c5..831f204 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for DBIx::Class + * Fixes + - Change one of the new tests for the previous release to not require + SQL::Translator + 0.08199 2012-08-22 (UTC) same as devrel diff --git a/t/prefetch/bugs.t b/t/prefetch/bugs.t index a53692c..0e7f9e1 100644 --- a/t/prefetch/bugs.t +++ b/t/prefetch/bugs.t @@ -3,54 +3,27 @@ use strict; use Test::More; -@INC{qw(Test::Schema::Foo Test::Schema::Baz)} = (1) x 2; +use lib qw(t/lib); +use DBICTest; -package Test::Schema::Foo; -use parent 'DBIx::Class'; -__PACKAGE__->load_components(qw(Core)); -__PACKAGE__->table('foo'); -__PACKAGE__->add_columns(qw(id bar_id)); -__PACKAGE__->set_primary_key('id'); -__PACKAGE__->belongs_to( - baz => 'Test::Schema::Baz', - { 'foreign.id' => 'self.bar_id' } +my $schema = DBICTest->init_schema( + no_populate => 1, ); -package Test::Schema::Baz; -use parent 'DBIx::Class'; -__PACKAGE__->load_components(qw(Core)); -__PACKAGE__->table('baz'); -__PACKAGE__->add_columns(qw(id quux)); -__PACKAGE__->set_primary_key('id'); -__PACKAGE__->has_many( - foos => 'Test::Schema::Foo' => { 'foreign.bar_id' => 'self.id' } ); - -package Test::Schema; -use parent 'DBIx::Class::Schema'; -__PACKAGE__->register_source( - $_ => "Test::Schema::$_"->result_source_instance ) - for qw(Foo Baz); - -package main; - -my $schema = Test::Schema->connect( 'dbi:SQLite:dbname=:memory:', '', '' ); -$schema->deploy; - -my $foo_rs = $schema->resultset('Foo'); -# create a condition that guarantees all values have 0 in them, -# which makes the inflation process skip the row because of: -# next unless first { defined $_ } values %{$me_pref->[0]}; -# all values need to be zero to ensure that the arbitrary order in -# which values() returns the results doesn't break the test -$foo_rs->create( { id => 0, baz => { id => 0, quux => 0 } } ); - -my $baz_rs = $schema->resultset('Baz'); -ok( $baz_rs->search( {}, { prefetch => 'foos' } )->first->foos->first ); - -$foo_rs->delete; -$baz_rs->delete; - -$foo_rs->create( { id => 1, baz => { id => 1, quux => 1 } } ); -ok( $baz_rs->search( {}, { prefetch => 'foos' } )->first->foos->first ); - -done_testing(); +$schema->resultset('CD')->create({ + cdid => 0, + artist => { + artistid => 0, + name => 0, + rank => 0, + charfield => 0, + }, + title => 0, + year => 0, + genreid => 0, + single_track => 0, +}); + +ok( $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->first->artist, 'artist loads even if all columns are 0'); + +done_testing;