From: Peter Rabbitson Date: Mon, 15 Sep 2014 06:11:55 +0000 (+0200) Subject: Split DBIC from SQLMaker test (deprecated in next commit) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=638cd9500bc5e3f326f8b4ae0153633db2df98ec;p=dbsrgits%2FDBIx-Class-Historic.git Split DBIC from SQLMaker test (deprecated in next commit) --- diff --git a/t/76joins.t b/t/76joins.t index 66e9fb7..d20faec 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -7,103 +7,15 @@ use DBICTest ':DiffSQL'; my $schema = DBICTest->init_schema(); -# test the abstract join => SQL generator -my $sa = DBIx::Class::SQLMaker->new; - -my @j = ( - { child => 'person' }, - [ { father => 'person' }, { 'father.person_id' => 'child.father_id' }, ], - [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ], -); -my $match = 'person child JOIN person father ON ( father.person_id = ' - . 'child.father_id ) JOIN person mother ON ( mother.person_id ' - . '= child.mother_id )' - ; -is_same_sql( - $sa->_recurse_from(@j), - $match, - 'join 1 ok' -); - -my @j2 = ( - { mother => 'person' }, - [ [ { child => 'person' }, - [ { father => 'person' }, - { 'father.person_id' => 'child.father_id' } - ] - ], - { 'mother.person_id' => 'child.mother_id' } - ], -); -$match = 'person mother JOIN (person child JOIN person father ON (' - . ' father.person_id = child.father_id )) ON ( mother.person_id = ' - . 'child.mother_id )' - ; -is_same_sql( - $sa->_recurse_from(@j2), - $match, - 'join 2 ok' -); - - -my @j3 = ( - { child => 'person' }, - [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ], - [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ], -); -$match = 'person child INNER JOIN person father ON ( father.person_id = ' - . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id ' - . '= child.mother_id )' - ; - -is_same_sql( - $sa->_recurse_from(@j3), - $match, - 'join 3 (inner join) ok' -); - -my @j4 = ( - { mother => 'person' }, - [ [ { child => 'person', -join_type => 'left' }, - [ { father => 'person', -join_type => 'right' }, - { 'father.person_id' => 'child.father_id' } - ] - ], - { 'mother.person_id' => 'child.mother_id' } - ], -); -$match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON (' - . ' father.person_id = child.father_id )) ON ( mother.person_id = ' - . 'child.mother_id )' - ; -is_same_sql( - $sa->_recurse_from(@j4), - $match, - 'join 4 (nested joins + join types) ok' -); - -my @j5 = ( - { child => 'person' }, - [ { father => 'person' }, { 'father.person_id' => \'!= child.father_id' }, ], - [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ], -); -$match = 'person child JOIN person father ON ( father.person_id != ' - . 'child.father_id ) JOIN person mother ON ( mother.person_id ' - . '= child.mother_id )' - ; -is_same_sql( - $sa->_recurse_from(@j5), - $match, - 'join 5 (SCALAR reference for ON statement) ok' -); - my $rs = $schema->resultset("CD")->search( { 'year' => 2001, 'artist.name' => 'Caterwauler McCrae' }, - { from => [ { 'me' => 'cd' }, - [ - { artist => 'artist' }, - { 'me.artist' => 'artist.artistid' } - ] ] } + { from => [ + { 'me' => 'cd' }, + [ + { artist => 'artist' }, + { 'me.artist' => { -ident => 'artist.artistid' } }, + ], + ] } ); is( $rs + 0, 1, "Single record in resultset"); diff --git a/t/sqlmaker/legacy_joins.t b/t/sqlmaker/legacy_joins.t new file mode 100644 index 0000000..5d17e99 --- /dev/null +++ b/t/sqlmaker/legacy_joins.t @@ -0,0 +1,97 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest ':DiffSQL'; + +use DBIx::Class::SQLMaker; +my $sa = DBIx::Class::SQLMaker->new; + +my @j = ( + { child => 'person' }, + [ { father => 'person' }, { 'father.person_id' => 'child.father_id' }, ], + [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ], +); +my $match = 'person child JOIN person father ON ( father.person_id = ' + . 'child.father_id ) JOIN person mother ON ( mother.person_id ' + . '= child.mother_id )' + ; +is_same_sql( + $sa->_recurse_from(@j), + $match, + 'join 1 ok' +); + +my @j2 = ( + { mother => 'person' }, + [ [ { child => 'person' }, + [ { father => 'person' }, + { 'father.person_id' => 'child.father_id' } + ] + ], + { 'mother.person_id' => 'child.mother_id' } + ], +); +$match = 'person mother JOIN (person child JOIN person father ON (' + . ' father.person_id = child.father_id )) ON ( mother.person_id = ' + . 'child.mother_id )' + ; +is_same_sql( + $sa->_recurse_from(@j2), + $match, + 'join 2 ok' +); + +my @j3 = ( + { child => 'person' }, + [ { father => 'person', -join_type => 'inner' }, { 'father.person_id' => 'child.father_id' }, ], + [ { mother => 'person', -join_type => 'inner' }, { 'mother.person_id' => 'child.mother_id' } ], +); +$match = 'person child INNER JOIN person father ON ( father.person_id = ' + . 'child.father_id ) INNER JOIN person mother ON ( mother.person_id ' + . '= child.mother_id )' + ; + +is_same_sql( + $sa->_recurse_from(@j3), + $match, + 'join 3 (inner join) ok' +); + +my @j4 = ( + { mother => 'person' }, + [ [ { child => 'person', -join_type => 'left' }, + [ { father => 'person', -join_type => 'right' }, + { 'father.person_id' => 'child.father_id' } + ] + ], + { 'mother.person_id' => 'child.mother_id' } + ], +); +$match = 'person mother LEFT JOIN (person child RIGHT JOIN person father ON (' + . ' father.person_id = child.father_id )) ON ( mother.person_id = ' + . 'child.mother_id )' + ; +is_same_sql( + $sa->_recurse_from(@j4), + $match, + 'join 4 (nested joins + join types) ok' +); + +my @j5 = ( + { child => 'person' }, + [ { father => 'person' }, { 'father.person_id' => \'!= child.father_id' }, ], + [ { mother => 'person' }, { 'mother.person_id' => 'child.mother_id' } ], +); +$match = 'person child JOIN person father ON ( father.person_id != ' + . 'child.father_id ) JOIN person mother ON ( mother.person_id ' + . '= child.mother_id )' + ; +is_same_sql( + $sa->_recurse_from(@j5), + $match, + 'join 5 (SCALAR reference for ON statement) ok' +); + +done_testing;