X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F95sql_maker.t;h=c4a65a29381a194f57f2bc98191ad9e221cc0239;hb=67810cf454129cb28562cbe0240bb010495e5860;hp=0971d1202c448428d33e71a283361ad887748a43;hpb=e5938571f31c21e93865da521f2fa1c14e45827e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/95sql_maker.t b/t/95sql_maker.t index 0971d12..c4a65a2 100644 --- a/t/95sql_maker.t +++ b/t/95sql_maker.t @@ -2,17 +2,12 @@ use strict; use warnings; use Test::More; -use SQL::Abstract::Test import => ['is_same_sql_bind']; - - -BEGIN { - eval "use DBD::SQLite"; - plan $@ - ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 3 ); -} +use Test::Exception; use lib qw(t/lib); +use DBIC::SqlMakerTest; + +plan tests => 4; use_ok('DBICTest'); @@ -21,33 +16,42 @@ my $schema = DBICTest->init_schema(); my $sql_maker = $schema->storage->sql_maker; -my ($sql, @bind) = $sql_maker->insert( - 'lottery', - { - 'day' => '2008-11-16', - 'numbers' => [13, 21, 34, 55, 89] - } -); - -is_same_sql_bind( - $sql, \@bind, - q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/, - [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], - 'sql_maker passes arrayrefs in insert' -); - - -($sql, @bind) = $sql_maker->update( - 'lottery', - { - 'day' => '2008-11-16', - 'numbers' => [13, 21, 34, 55, 89] - } -); - -is_same_sql_bind( - $sql, \@bind, - q/UPDATE lottery SET day = ?, numbers = ?/, - [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], - 'sql_maker passes arrayrefs in update' -); +{ + my ($sql, @bind) = $sql_maker->insert( + 'lottery', + { + 'day' => '2008-11-16', + 'numbers' => [13, 21, 34, 55, 89] + } + ); + + is_same_sql_bind( + $sql, \@bind, + q/INSERT INTO lottery (day, numbers) VALUES (?, ?)/, + [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], + 'sql_maker passes arrayrefs in insert' + ); + + + ($sql, @bind) = $sql_maker->update( + 'lottery', + { + 'day' => '2008-11-16', + 'numbers' => [13, 21, 34, 55, 89] + } + ); + + is_same_sql_bind( + $sql, \@bind, + q/UPDATE lottery SET day = ?, numbers = ?/, + [ ['day' => '2008-11-16'], ['numbers' => [13, 21, 34, 55, 89]] ], + 'sql_maker passes arrayrefs in update' + ); +} + +# Make sure the carp/croak override in SQLA works (via SQLAHacks) +my $file = __FILE__; +$file = "\Q$file\E"; +throws_ok (sub { + $schema->resultset ('Artist')->search ({}, { order_by => { -asc => 'stuff', -desc => 'staff' } } )->as_query; +}, qr/$file/, 'Exception correctly croak()ed');