X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi%2F19-set_sql.t;h=7118e4abd91da9c2831d0ecc8c323ef1410911ed;hb=68de943862f06cabd397d2e74d12cd9cdc999779;hp=eb464a33defb44c3c7c0a66149339af1a73a4d94;hpb=50891152d0b24649bfd67bdba97feec86b11c064;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi/19-set_sql.t b/t/cdbi/19-set_sql.t index eb464a3..7118e4a 100644 --- a/t/cdbi/19-set_sql.t +++ b/t/cdbi/19-set_sql.t @@ -5,10 +5,8 @@ BEGIN { eval "use DBIx::Class::CDBICompat;"; if ($@) { plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required'); - next; } - eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 20); + plan tests => 20; } use lib 't/cdbi/testlib'; @@ -16,14 +14,14 @@ use Film; use Actor; { # Check __ESSENTIAL__ expansion (RT#13038) - my @cols = Film->columns('Essential'); - is_deeply \@cols, ['title'], "1 Column in essential"; - is +Film->transform_sql('__ESSENTIAL__'), 'title', '__ESSENTIAL__ expansion'; - - # This provides a more interesting test - Film->columns(Essential => qw(title rating)); - is +Film->transform_sql('__ESSENTIAL__'), 'title, rating', - 'multi-col __ESSENTIAL__ expansion'; + my @cols = Film->columns('Essential'); + is_deeply \@cols, ['title'], "1 Column in essential"; + is +Film->transform_sql('__ESSENTIAL__'), 'title', '__ESSENTIAL__ expansion'; + + # This provides a more interesting test + Film->columns(Essential => qw(title rating)); + is +Film->transform_sql('__ESSENTIAL__'), 'title, rating', + 'multi-col __ESSENTIAL__ expansion'; } my $f1 = Film->create({ title => 'A', director => 'AA', rating => 'PG' }); @@ -33,43 +31,43 @@ my $f4 = Film->create({ title => 'D', director => 'BA', rating => '18' }); my $f5 = Film->create({ title => 'E', director => 'AA', rating => '18' }); Film->set_sql( - pgs => qq{ - SELECT __ESSENTIAL__ - FROM __TABLE__ - WHERE __TABLE__.rating = 'PG' - ORDER BY title DESC + pgs => qq{ + SELECT __ESSENTIAL__ + FROM __TABLE__ + WHERE __TABLE__.rating = 'PG' + ORDER BY title DESC } ); { - (my $sth = Film->sql_pgs())->execute; - my @pgs = Film->sth_to_objects($sth); - is @pgs, 2, "Execute our own SQL"; - is $pgs[0]->id, $f2->id, "get F2"; - is $pgs[1]->id, $f1->id, "and F1"; + (my $sth = Film->sql_pgs())->execute; + my @pgs = Film->sth_to_objects($sth); + is @pgs, 2, "Execute our own SQL"; + is $pgs[0]->id, $f2->id, "get F2"; + is $pgs[1]->id, $f1->id, "and F1"; } { - my @pgs = Film->search_pgs; - is @pgs, 2, "SQL creates search() method"; - is $pgs[0]->id, $f2->id, "get F2"; - is $pgs[1]->id, $f1->id, "and F1"; + my @pgs = Film->search_pgs; + is @pgs, 2, "SQL creates search() method"; + is $pgs[0]->id, $f2->id, "get F2"; + is $pgs[1]->id, $f1->id, "and F1"; }; Film->set_sql( - rating => qq{ - SELECT __ESSENTIAL__ - FROM __TABLE__ - WHERE rating = ? - ORDER BY title DESC + rating => qq{ + SELECT __ESSENTIAL__ + FROM __TABLE__ + WHERE rating = ? + ORDER BY title DESC } ); { - my @pgs = Film->search_rating('18'); - is @pgs, 2, "Can pass parameters to created search()"; - is $pgs[0]->id, $f5->id, "F5"; - is $pgs[1]->id, $f4->id, "and F4"; + my @pgs = Film->search_rating('18'); + is @pgs, 2, "Can pass parameters to created search()"; + is $pgs[0]->id, $f5->id, "F5"; + is $pgs[1]->id, $f4->id, "and F4"; }; { @@ -89,44 +87,44 @@ Film->set_sql( { - Actor->has_a(film => "Film"); - Film->set_sql( - namerate => qq{ - SELECT __ESSENTIAL(f)__ - FROM __TABLE(=f)__, __TABLE(Actor=a)__ - WHERE __JOIN(a f)__ - AND a.name LIKE ? - AND f.rating = ? - ORDER BY title - } - ); - - my $a1 = Actor->create({ name => "A1", film => $f1 }); - my $a2 = Actor->create({ name => "A2", film => $f2 }); - my $a3 = Actor->create({ name => "B1", film => $f1 }); - - my @apg = Film->search_namerate("A_", "PG"); - is @apg, 2, "2 Films with A* that are PG"; - is $apg[0]->title, "A", "A"; - is $apg[1]->title, "B", "and B"; + Actor->has_a(film => "Film"); + Film->set_sql( + namerate => qq{ + SELECT __ESSENTIAL(f)__ + FROM __TABLE(=f)__, __TABLE(Actor=a)__ + WHERE __JOIN(a f)__ + AND a.name LIKE ? + AND f.rating = ? + ORDER BY title + } + ); + + my $a1 = Actor->create({ name => "A1", film => $f1 }); + my $a2 = Actor->create({ name => "A2", film => $f2 }); + my $a3 = Actor->create({ name => "B1", film => $f1 }); + + my @apg = Film->search_namerate("A_", "PG"); + is @apg, 2, "2 Films with A* that are PG"; + is $apg[0]->title, "A", "A"; + is $apg[1]->title, "B", "and B"; } { # join in reverse - Actor->has_a(film => "Film"); - Film->set_sql( - ratename => qq{ - SELECT __ESSENTIAL(f)__ - FROM __TABLE(=f)__, __TABLE(Actor=a)__ - WHERE __JOIN(f a)__ - AND f.rating = ? - AND a.name LIKE ? - ORDER BY title - } - ); - - my @apg = Film->search_ratename(PG => "A_"); - is @apg, 2, "2 Films with A* that are PG"; - is $apg[0]->title, "A", "A"; - is $apg[1]->title, "B", "and B"; + Actor->has_a(film => "Film"); + Film->set_sql( + ratename => qq{ + SELECT __ESSENTIAL(f)__ + FROM __TABLE(=f)__, __TABLE(Actor=a)__ + WHERE __JOIN(f a)__ + AND f.rating = ? + AND a.name LIKE ? + ORDER BY title + } + ); + + my @apg = Film->search_ratename(PG => "A_"); + is @apg, 2, "2 Films with A* that are PG"; + is $apg[0]->title, "A", "A"; + is $apg[1]->title, "B", "and B"; }