From: Peter Rabbitson Date: Fri, 22 Jan 2010 10:19:40 +0000 (+0000) Subject: Chaining POC test X-Git-Tag: v0.08119~20^2~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3a55f069eca6624d5b3229cf354139cbfd6fa9fa;p=dbsrgits%2FDBIx-Class.git Chaining POC test --- diff --git a/t/search/select_chains.t b/t/search/select_chains.t new file mode 100644 index 0000000..6771d3b --- /dev/null +++ b/t/search/select_chains.t @@ -0,0 +1,60 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use lib qw(t/lib); +use DBIC::SqlMakerTest; +use DBICTest; + + +my $schema = DBICTest->init_schema(); + +my @chain = ( + { + columns => [ 'cdid' ], + '+select' => [ { lower => 'title' }, 'genreid' ], + '+as' => [ qw/title_lc genreid/ ], + } => 'SELECT me.cdid, LOWER( title ), me.genreid FROM cd me', + + { + '+columns' => [ { max_year => { max => 'me.year' }}, ], + '+select' => [ { count => 'me.cdid' }, ], + '+as' => [ 'cnt' ], + } => 'SELECT me.cdid, MAX( me.year ), LOWER( title ), me.genreid, COUNT( me.cdid ) FROM cd me', + + { + select => [ { min => 'me.cdid' }, ], + as => [ 'min_id' ], + } => 'SELECT MIN( me.cdid ) FROM cd me', + + { + '+columns' => [ { cnt => { count => 'cdid' } } ], + } => 'SELECT COUNT ( cdid ), MIN( me.cdid ) FROM cd me', + + { + columns => [ 'year' ], + } => 'SELECT me.year FROM cd me', +); + +my $rs = $schema->resultset('CD'); + +my $testno = 1; +while (@chain) { + my $attrs = shift @chain; + my $sql = shift @chain; + + $rs = $rs->search ({}, $attrs); + + is_same_sql_bind ( + $rs->as_query, + "x( $sql )", # the x-es are here until SQLA is fixed + [], + "Test $testno of SELECT assembly ok", + ); + + $testno++; +} + +done_testing; \ No newline at end of file