From: Justin Hunter Date: Fri, 1 May 2009 06:41:34 +0000 (+0000) Subject: cleanup/fix some broken tests X-Git-Tag: v0.08103~101^2~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=866557f95aff945a895353c3235309afb22956ec;p=dbsrgits%2FDBIx-Class.git cleanup/fix some broken tests --- diff --git a/t/count/count_distinct.t b/t/count/count_distinct.t index 9e2219f..d4dd422 100644 --- a/t/count/count_distinct.t +++ b/t/count/count_distinct.t @@ -14,43 +14,44 @@ eval "use DBD::SQLite"; plan skip_all => 'needs DBD::SQLite for testing' if $@; plan tests => 13; -my $in_rs = $schema->resultset("Tag")->search({ tag => [ 'Blue', 'Shiny' ] }); +my $in_rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Shiny' ] }); +my $rs; -cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }), - '==', 4, 'Count without DISTINCT'); +$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }); +is($rs->count, 4, 'Count without DISTINCT'); -cmp_ok($schema->resultset("Tag")->count({ tag => [ 'Blue', 'Shiny' ] }, { group_by => 'tag' }), - '==', 2, 'Count with single column group_by'); +$rs = $schema->resultset('Tag')->search({ tag => [ 'Blue', 'Shiny' ] }, { group_by => 'tag' }); +is($rs->count, 2, 'Count with single column group_by'); -cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }, { group_by => [ qw/tag cd/ ]}), - '==', 4, 'Count with multiple column group_by'); +$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { group_by => [ qw/tag cd/ ]}); +is($rs->count, 4, 'Count with multiple column group_by'); -cmp_ok($schema->resultset("Tag")->count({ tag => 'Blue' }, { distinct => 1 }), - '==', 4, "Count with single column distinct"); +$rs = $schema->resultset('Tag')->search({ tag => 'Blue' }, { distinct => 1 }); +is($rs->count, 4, 'Count with single column distinct'); -cmp_ok($schema->resultset("Tag")->count({ tag => { -in => $in_rs->get_column('tag')->as_query } }), - '==', 4, "Count with IN subquery"); +$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }); +is($rs->count, 4, 'Count with IN subquery'); -cmp_ok($schema->resultset("Tag")->count({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { group_by => 'tag' }), - '==', 1, "Count with IN subquery with outside group_by"); +$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { group_by => 'tag' }); +is($rs->count, 1, 'Count with IN subquery with outside group_by'); -cmp_ok($schema->resultset("Tag")->count({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1 }), - '==', 4, "Count with IN subquery with outside distinct"); +$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1 }); +is($rs->count, 4, 'Count with IN subquery with outside distinct'); -cmp_ok($schema->resultset("Tag")->count({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1, select => 'tag' }), - '==', 1, "Count with IN subquery with outside distinct on a single column"); +$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->get_column('tag')->as_query } }, { distinct => 1, select => 'tag' }), +is($rs->count, 1, 'Count with IN subquery with outside distinct on a single column'); -cmp_ok($schema->resultset("Tag")->count({ tag => { -in => $in_rs->search({}, { group_by => 'tag' })->get_column('tag')->as_query } }), - '==', 4, "Count with IN subquery with single group_by"); +$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => 'tag' })->get_column('tag')->as_query } }); +is($rs->count, 4, 'Count with IN subquery with single group_by'); -cmp_ok($schema->resultset("Tag")->count({ tag => { -in => $in_rs->search({}, { group_by => [ qw/tag cd/ ] })->get_column('tag')->as_query } }), - '==', 4, "Count with IN subquery with multiple group_by"); +$rs = $schema->resultset('Tag')->search({ tag => { -in => $in_rs->search({}, { group_by => [ qw/tag cd/ ] })->get_column('tag')->as_query } }); +is($rs->count, 4, 'Count with IN subquery with multiple group_by'); -cmp_ok($schema->resultset("Tag")->count({ tag => \"= 'Blue'" }), - '==', 4, "Count without DISTINCT, using literal SQL"); +$rs = $schema->resultset('Tag')->search({ tag => \"= 'Blue'" }); +is($rs->count, 4, 'Count without DISTINCT, using literal SQL'); -cmp_ok($schema->resultset("Tag")->count({ tag => \" IN ('Blue', 'Shiny')" }, { group_by => 'tag' }), - '==', 2, "Count with literal SQL and single group_by"); +$rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Shiny')" }, { group_by => 'tag' }); +is($rs->count, 2, 'Count with literal SQL and single group_by'); -cmp_ok($schema->resultset("Tag")->count({ tag => \" IN ('Blue', 'Shiny')" }, { group_by => [ qw/tag cd/ ] }), - '==', 6, "Count with literal SQL and multiple group_by"); +$rs = $schema->resultset('Tag')->search({ tag => \" IN ('Blue', 'Shiny')" }, { group_by => [ qw/tag cd/ ] }); +is($rs->count, 6, 'Count with literal SQL and multiple group_by'); diff --git a/t/from_subquery.t b/t/from_subquery.t index 3fd6cb0..5dc91d0 100644 --- a/t/from_subquery.t +++ b/t/from_subquery.t @@ -27,7 +27,7 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 )", + "(SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE artist_id IN ( SELECT id FROM artist me LIMIT 1 ))", [], ); } @@ -46,7 +46,7 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me", + "(SELECT (SELECT id FROM cd me LIMIT 1) FROM artist me)", [], ); } @@ -65,7 +65,7 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me", + "(SELECT me.artistid, me.name, me.rank, me.charfield, (SELECT id FROM cd me LIMIT 1) FROM artist me)", [], ); } @@ -86,8 +86,10 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( id > ? ) ) cd2", - [ [ 'id', 20 ] ], + "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( id > ? ) ) cd2)", + [ + [ 'id', 20 ] + ], ); } @@ -104,7 +106,8 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist", [] + "(SELECT me.artistid, me.name, me.rank, me.charfield FROM artist me JOIN (SELECT me.artist as cds_artist FROM cd me) cds ON me.artistid = cds_artist)", + [] ); @@ -133,14 +136,17 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track + "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( id < ? ) ) cd3 - WHERE ( id > ? ) ) cd2", - [ [ 'id', 40 ], [ 'id', 20 ] ], + WHERE ( id > ? ) ) cd2)", + [ + [ 'id', 40 ], + [ 'id', 20 ] + ], ); } @@ -158,7 +164,7 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid)", + "(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me WHERE year = (SELECT MAX(inner.year) FROM cd inner WHERE artistid = me.artistid))", [], ); } @@ -178,7 +184,7 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( title = ? ) ) cd2", + "(SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE ( title = ? ) ) cd2)", [ [ 'title', 'Thriller' ] ], ); } diff --git a/t/search/subquery.t b/t/search/subquery.t index b18bfa6..e99192b 100644 --- a/t/search/subquery.t +++ b/t/search/subquery.t @@ -85,8 +85,10 @@ my $cdrs = $schema->resultset('CD'); my ($query, @bind) = @{$$arr}; is_same_sql_bind( $query, \@bind, - "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > 20) cd2 )", - [], + "( SELECT cd2.cdid, cd2.artist, cd2.title, cd2.year, cd2.genreid, cd2.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track FROM cd me WHERE id > ?) cd2 )", + [ + [ 'id', 20 ] + ], ); } @@ -137,10 +139,13 @@ my $cdrs = $schema->resultset('CD'); (SELECT cd3.cdid,cd3.artist,cd3.title,cd3.year,cd3.genreid,cd3.single_track FROM (SELECT me.cdid,me.artist,me.title,me.year,me.genreid,me.single_track - FROM cd me WHERE id < 40) cd3 - WHERE id > 20) cd2 + FROM cd me WHERE id < ?) cd3 + WHERE id > ?) cd2 )", - [], + [ + [ 'id', 40 ], + [ 'id', 20 ] + ], ); }