Test and merge fixes
[dbsrgits/DBIx-Class.git] / t / 746mssql.t
index 5989d6e..7cfb460 100644 (file)
@@ -10,9 +10,9 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MSSQL_ODBC_${_}" } qw/DSN USER PA
 plan skip_all => 'Set $ENV{DBICTEST_MSSQL_ODBC_DSN}, _USER and _PASS to run this test'
   unless ($dsn && $user);
 
-plan tests => 21;
+plan tests => 19;
 
-my $schema = DBICTest::Schema->connect($dsn, $user, $pass, {AutoCommit => 1});
+my $schema = DBICTest::Schema->connect($dsn, $user, $pass);
 
 {
   no warnings 'redefine';
@@ -90,19 +90,29 @@ CREATE TABLE Books (
 
 CREATE TABLE Owners (
    id INT IDENTITY (1, 1) NOT NULL,
-   [name] VARCHAR(100),
+   name VARCHAR(100),
 )
 
-SET IDENTITY_INSERT Owners ON
-
 SQL
 
 });
 $schema->populate ('Owners', [
-  [qw/id  [name]  /],
+  [qw/id  name  /],
   [qw/1   wiggle/],
   [qw/2   woggle/],
   [qw/3   boggle/],
+  [qw/4   fREW/],
+  [qw/5   fRIOUX/],
+  [qw/6   fROOH/],
+  [qw/7   fRUE/],
+  [qw/8   fISMBoC/],
+  [qw/9   station/],
+  [qw/10   mirror/],
+  [qw/11   dimly/],
+  [qw/12   face_to_face/],
+  [qw/13   icarus/],
+  [qw/14   dream/],
+  [qw/15   dyrstyggyr/],
 ]);
 
 $schema->populate ('BooksInLibrary', [
@@ -110,6 +120,15 @@ $schema->populate ('BooksInLibrary', [
   [qw/Library 1     secrets1/],
   [qw/Eatery  1     secrets2/],
   [qw/Library 2     secrets3/],
+  [qw/Library 3     secrets4/],
+  [qw/Eatery  3     secrets5/],
+  [qw/Library 4     secrets6/],
+  [qw/Library 5     secrets7/],
+  [qw/Eatery  5     secrets8/],
+  [qw/Library 6     secrets9/],
+  [qw/Library 7     secrets10/],
+  [qw/Eatery  7     secrets11/],
+  [qw/Library 8     secrets12/],
 ]);
 
 #
@@ -117,26 +136,40 @@ $schema->populate ('BooksInLibrary', [
 #
 
 {
-  # try a ->has_many direction (due to a 'multi' accessor the select/group_by group is collapsed)
-  my $owners = $schema->resultset ('Owners')->search (
-    { 'books.id' => { '!=', undef }},
-    { prefetch => 'books', distinct => 1 }
-  );
-  my $owners2 = $schema->resultset ('Owners')->search ({ id => { -in => $owners->get_column ('me.id')->as_query }});
-  for ($owners, $owners2) {
-    is ($_->all, 2, 'Prefetched grouped search returns correct number of rows');
-    is ($_->count, 2, 'Prefetched grouped search returns correct count');
+  # try a ->has_many direction (group_by is not possible on has_many with limit)
+  my $owners = $schema->resultset ('Owners')->search ({
+      'books.id' => { '!=', undef }
+    }, {
+      prefetch => 'books',
+      order_by => 'name',
+      page     => 2,
+      rows     => 4,
+    });
+
+  TODO: {
+    local $TODO = 'limit past end of resultset problem';
+    is ($owners->all, 3, 'has_many prefetch returns correct number of rows');
+    is ($owners->count, 3, 'has-many prefetch returns correct count');
   }
 
-  # try a ->belongs_to direction (no select collapse)
-  my $books = $schema->resultset ('BooksInLibrary')->search (
-    { 'owner.name' => 'wiggle' },
-    { prefetch => 'owner', distinct => 1 }
-  );
-  my $books2 = $schema->resultset ('BooksInLibrary')->search ({ id => { -in => $books->get_column ('me.id')->as_query }});
-  for ($books, $books2) {
-    is ($_->all, 1, 'Prefetched grouped search returns correct number of rows');
-    is ($_->count, 1, 'Prefetched grouped search returns correct count');
+  # try a ->belongs_to direction (no select collapse, group_by should work)
+  my $books = $schema->resultset ('BooksInLibrary')->search ({
+      'owner.name' => 'wiggle'
+    }, {
+      distinct => 1,
+      prefetch => 'owner',
+      order_by => 'name',
+      rows     => 5,
+    });
+
+
+  is ($books->page(1)->all, 1, 'Prefetched grouped search returns correct number of rows');
+  is ($books->page(1)->count, 1, 'Prefetched grouped search returns correct count');
+
+  TODO: {
+    local $TODO = 'limit past end of resultset problem';
+    is ($books->page(2)->all, 0, 'Prefetched grouped search returns correct number of rows');
+    is ($books->page(2)->count, 0, 'Prefetched grouped search returns correct count');
   }
 }
 
@@ -145,4 +178,4 @@ END {
     my $dbh = eval { $schema->storage->_dbh };
     $dbh->do('DROP TABLE artist') if $dbh;
 }
-
+# vim:sw=2 sts=2