Extend test
[dbsrgits/DBIx-Class.git] / t / 47bind_attribute.t
index 8f66f6c..b9946a4 100644 (file)
@@ -3,7 +3,9 @@ use warnings;
 
 use Test::More;
 use lib qw(t/lib);
-use DBICTest;
+use DBIC::SqlMakerTest;
+
+use_ok('DBICTest');
 
 my $schema = DBICTest->init_schema;
 
@@ -11,11 +13,9 @@ BEGIN {
     eval "use DBD::SQLite";
     plan $@
         ? ( skip_all => 'needs DBD::SQLite for testing' )
-        : ( tests => 7 );
+        : ( tests => 9 );
 }
 
-### $schema->storage->debug(1);
-
 my $where_bind = {
     where => \'name like ?',
     bind  => [ 'Cat%' ],
@@ -55,10 +55,10 @@ my $new_source = $source->new($source);
 $new_source->source_name('Complex');
 
 $new_source->name(\<<'');
-( select a.*, cd.cdid as cdid, cd.title as title, cd.year as year 
-  from artist a
-  join cd on cd.artist=a.artistid
-  where cd.year=?)
+( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year 
+  FROM artist a
+  JOIN cd ON cd.artist = a.artistid
+  WHERE cd.year = ?)
 
 $schema->register_extra_source('Complex' => $new_source);
 
@@ -72,6 +72,20 @@ $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })
     ->search({ 'artistid' => 1 });
 is ( $rs->count, 1, '...cookbook (bind first) + chained search' );
 
+{
+  $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })->search({}, { where => \"title LIKE ?", bind => [ 'Spoon%' ] });
+  is_same_sql_bind(
+    $rs->as_query,
+    "(SELECT me.artistid, me.name, me.rank, me.charfield FROM (SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year FROM artist a JOIN cd ON cd.artist = a.artistid WHERE cd.year = ?) WHERE title LIKE ?)",
+    [
+      [ '!!dummy' => '1999' ], 
+      [ '!!dummy' => 'Spoon%' ]
+    ],
+    'got correct SQL'
+);
+
+}
+
 TODO: {
     local $TODO = 'bind args order needs fixing (semifor)';
     $rs = $schema->resultset('Complex')->search({}, { bind => [ 1999 ] })