added branch no_duplicate_indexes_for_pk_cols with test and fix
[dbsrgits/DBIx-Class.git] / t / 99dbic_sqlt_parser.t
index 86ddf76..ccfc60a 100644 (file)
@@ -5,6 +5,8 @@ use Test::More;
 use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
+use DBICTest::Schema;
+use Scalar::Util ();
 
 BEGIN {
   require DBIx::Class::Storage::DBI;
@@ -13,6 +15,16 @@ BEGIN {
     if not DBIx::Class::Storage::DBI->_sqlt_version_ok;
 }
 
+# Test for SQLT-related leaks
+{
+  my $s = DBICTest::Schema->clone;
+  create_schema ({ schema => $s });
+  Scalar::Util::weaken ($s);
+
+  ok (!$s, 'Schema not leaked');
+}
+
+
 my $schema = DBICTest->init_schema();
 # Dummy was yanked out by the sqlt hook test
 # CustomSql tests the horrific/deprecated ->name(\$sql) hack
@@ -26,14 +38,22 @@ my @sources = grep
 { 
   my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } });
 
-  foreach my $source (@sources) {
-    my $table = get_table($sqlt_schema, $schema, $source);
+  foreach my $source_name (@sources) {
+    my $table = get_table($sqlt_schema, $schema, $source_name);
 
     my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
     my @indices = $table->get_indices;
+
     my $index_count = scalar(@indices);
-    $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
-    is($index_count, $fk_count, "correct number of indices for $source with no args");
+    $index_count++ if ($source_name eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
+    is($index_count, $fk_count, "correct number of indices for $source_name with no args");
+    
+    for my $index (@indices) {
+        my $source = $schema->source($source_name);
+        my @pks = $source->primary_columns;
+        my @idx_cols = $index->fields;
+        ok ( !eq_set(\@pks, \@idx_cols), "no additional index for the primary columns exists in $source_name");
+    }
   }
 }
 
@@ -84,6 +104,24 @@ my @sources = grep
         'parser detects views with a view_definition';
 }
 
+lives_ok (sub {
+  my $sqlt_schema = create_schema ({
+    schema => $schema,
+    args => {
+      parser_args => {
+        sources => ['CD']
+      },
+    },
+  });
+
+  is_deeply (
+    [$sqlt_schema->get_tables ],
+    ['cd'],
+    'sources limitng with relationships works',
+  );
+
+});
+
 done_testing;
 
 sub create_schema {