From: Peter Rabbitson Date: Wed, 27 Jan 2010 11:08:04 +0000 (+0000) Subject: Merge some cleanups from the prefetch branch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c9d29bb255e00c9c734edfc9634b3ff24ad621ba;p=dbsrgits%2FDBIx-Class-Historic.git Merge some cleanups from the prefetch branch --- diff --git a/t/26dumper.t b/t/26dumper.t index e392df9..a238085 100644 --- a/t/26dumper.t +++ b/t/26dumper.t @@ -1,6 +1,5 @@ use strict; use Test::More; -use IO::File; use Data::Dumper; $Data::Dumper::Sortkeys = 1; diff --git a/t/76joins.t b/t/76joins.t index ba87a0a..0d5512e 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -10,8 +10,6 @@ my $schema = DBICTest->init_schema(); my $orig_debug = $schema->storage->debug; -use IO::File; - BEGIN { eval "use DBD::SQLite"; plan $@ diff --git a/t/76select.t b/t/76select.t index d7c2b4a..2ca47e6 100644 --- a/t/76select.t +++ b/t/76select.t @@ -89,13 +89,13 @@ lives_ok(sub { }, 'columns 2nd rscolumn present'); lives_ok(sub { - $rs->first->artist->get_column('name') -}, 'columns 3rd rscolumn present'); + $rs->first->artist->get_column('name') +}, 'columns 3rd rscolumn present'); $rs = $schema->resultset('CD')->search({}, - { + { 'join' => 'artist', '+columns' => ['cdid', 'title', 'artist.name'], } @@ -109,7 +109,7 @@ is_same_sql_bind ( ); lives_ok(sub { - $rs->first->get_column('cdid') + $rs->first->get_column('cdid') }, 'columns 1st rscolumn present'); lives_ok(sub { @@ -153,36 +153,17 @@ my $sub_rs = $rs->search ({}, } ); -is_deeply ( +is_deeply( $sub_rs->single, { - artist => 1, + artist => 1, track_position => 2, - tracks => - { - trackid => 17, - title => 'Apiary', - }, + tracks => { + trackid => 17, + title => 'Apiary', + }, }, 'columns/select/as fold properly on sub-searches', ); -TODO: { - local $TODO = "Multi-collapsing still doesn't work right - HRI should be getting an arrayref, not an individual hash"; - is_deeply ( - $sub_rs->single, - { - artist => 1, - track_position => 2, - tracks => [ - { - trackid => 17, - title => 'Apiary', - }, - ], - }, - 'columns/select/as fold properly on sub-searches', - ); -} - done_testing; diff --git a/t/inflate/file_column.t b/t/inflate/file_column.t index a9a75f0..639b12d 100644 --- a/t/inflate/file_column.t +++ b/t/inflate/file_column.t @@ -4,7 +4,6 @@ use warnings; use Test::More; use lib qw(t/lib); use DBICTest; -use IO::File; use File::Compare; use Path::Class qw/file/; diff --git a/t/inflate/hri.t b/t/inflate/hri.t index 69fa4ff..fab040e 100644 --- a/t/inflate/hri.t +++ b/t/inflate/hri.t @@ -30,7 +30,7 @@ my $schema = DBICTest->init_schema(); sub check_cols_of { my ($dbic_obj, $datahashref) = @_; - + foreach my $col (keys %$datahashref) { # plain column if (not ref ($datahashref->{$col}) ) { @@ -44,14 +44,14 @@ sub check_cols_of { elsif (ref ($datahashref->{$col}) eq 'ARRAY') { my @dbic_reltable = $dbic_obj->$col; my @hashref_reltable = @{$datahashref->{$col}}; - + 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); } } @@ -139,3 +139,4 @@ is_deeply( ); done_testing; + diff --git a/t/prefetch/diamond.t b/t/prefetch/diamond.t index fe30ac8..0de8009 100644 --- a/t/prefetch/diamond.t +++ b/t/prefetch/diamond.t @@ -96,12 +96,12 @@ foreach my $cd_path (keys %$cd_paths) { } } -plan tests => (scalar (keys %tests) * 3); - foreach my $name (keys %tests) { foreach my $artwork ($tests{$name}->all()) { is($artwork->id, 1, $name . ', correct artwork'); is($artwork->cd->artist->artistid, 1, $name . ', correct artist_id over cd'); is($artwork->artwork_to_artist->first->artist->artistid, 2, $name . ', correct artist_id over A2A'); } -} \ No newline at end of file +} + +done_testing; diff --git a/t/prefetch/standard.t b/t/prefetch/standard.t index 7980da3..66479b0 100644 --- a/t/prefetch/standard.t +++ b/t/prefetch/standard.t @@ -5,7 +5,6 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; -use IO::File; my $schema = DBICTest->init_schema(); my $orig_debug = $schema->storage->debug; diff --git a/t/prefetch/with_limit.t b/t/prefetch/with_limit.t index 1dd0829..b8c13a3 100644 --- a/t/prefetch/with_limit.t +++ b/t/prefetch/with_limit.t @@ -8,8 +8,6 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; -plan tests => 9; - my $schema = DBICTest->init_schema(); @@ -25,6 +23,8 @@ my $no_prefetch = $schema->resultset('Artist')->search( my $use_prefetch = $no_prefetch->search( {}, { + select => ['me.artistid', 'me.name'], + as => ['artistid', 'name'], prefetch => 'cds', order_by => { -desc => 'name' }, } @@ -90,3 +90,4 @@ is($artist->cds->count, 1, "count on search limiting prefetched has_many"); my $artist2 = $use_prefetch->search({'cds.title' => { '!=' => $artist_many_cds->cds->first->title } })->slice (0,0)->next; is($artist2->cds->count, 2, "count on search limiting prefetched has_many"); +done_testing; diff --git a/t/sqlahacks/quotes/quotes.t b/t/sqlahacks/quotes/quotes.t index 8750d5a..398aa04 100644 --- a/t/sqlahacks/quotes/quotes.t +++ b/t/sqlahacks/quotes/quotes.t @@ -2,7 +2,6 @@ use strict; use warnings; use Test::More; -use IO::File; use lib qw(t/lib); use DBIC::SqlMakerTest; diff --git a/t/sqlahacks/quotes/quotes_newstyle.t b/t/sqlahacks/quotes/quotes_newstyle.t index 3e7595a..ccf1445 100644 --- a/t/sqlahacks/quotes/quotes_newstyle.t +++ b/t/sqlahacks/quotes/quotes_newstyle.t @@ -2,7 +2,6 @@ use strict; use warnings; use Test::More; -use IO::File; use lib qw(t/lib); use DBIC::SqlMakerTest; diff --git a/t/storage/debug.t b/t/storage/debug.t index bb55aba..480ad6e 100644 --- a/t/storage/debug.t +++ b/t/storage/debug.t @@ -6,25 +6,19 @@ use lib qw(t/lib); use DBICTest; use DBIC::DebugObj; use DBIC::SqlMakerTest; +use Path::Class qw/file/; my $schema = DBICTest->init_schema(); -plan tests => 7; ok ( $schema->storage->debug(1), 'debug' ); -ok ( defined( - $schema->storage->debugfh( - IO::File->new('t/var/sql.log', 'w') - ) - ), - 'debugfh' - ); +$schema->storage->debugfh(file('t/var/sql.log')->openw); $schema->storage->debugfh->autoflush(1); my $rs = $schema->resultset('CD')->search({}); $rs->count(); -my $log = new IO::File('t/var/sql.log', 'r') or die($!); +my $log = file('t/var/sql.log')->openr; my $line = <$log>; $log->close(); ok($line =~ /^SELECT COUNT/, 'Log success'); @@ -33,7 +27,7 @@ $schema->storage->debugfh(undef); $ENV{'DBIC_TRACE'} = '=t/var/foo.log'; $rs = $schema->resultset('CD')->search({}); $rs->count(); -$log = new IO::File('t/var/foo.log', 'r') or die($!); +$log = file('t/var/foo.log')->openr; $line = <$log>; $log->close(); ok($line =~ /^SELECT COUNT/, 'Log success'); @@ -70,4 +64,4 @@ open(STDERR, '>&STDERRCOPY'); ); } -1; +done_testing;