multi db_schema support
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 23dumpmore.t
index 9bd82a6..2c1ef7b 100644 (file)
@@ -13,10 +13,6 @@ $t->cleanup;
 # test loading external content
 $t->dump_test(
   classname => 'DBICTest::Schema::_no_skip_load_external',
-  warnings => [
-    qr/Dumping manual schema for DBICTest::Schema::_no_skip_load_external to directory /,
-    qr/Schema dump completed/,
-  ],
   regexes => {
     Foo => [
       qr/package DBICTest::Schema::_no_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
@@ -28,12 +24,8 @@ $t->dump_test(
 $t->dump_test(
   classname => 'DBICTest::Schema::_skip_load_external',
   options => {
-    skip_load_external => 1
+    skip_load_external => 1,
   },
-  warnings => [
-    qr/Dumping manual schema for DBICTest::Schema::_skip_load_external to directory /,
-    qr/Schema dump completed/,
-  ],
   neg_regexes => {
     Foo => [
       qr/package DBICTest::Schema::_skip_load_external::Foo;\nour \$skip_me = "bad mojo";\n1;/
@@ -52,10 +44,6 @@ $t->cleanup;
   $t->dump_test(
     classname => 'DBICTest::Schema::_config_file',
     options => { config_file => "$config_file" },
-    warnings => [
-      qr/Dumping manual schema for DBICTest::Schema::_config_file to directory /,
-      qr/Schema dump completed/,
-    ],
     neg_regexes => {
       Foo => [
         qr/has_many/,
@@ -68,9 +56,92 @@ $t->cleanup;
 $t->dump_test(
   classname => 'DBICTest::Schema::_clashing_monikers',
   test_db_class => 'make_dbictest_db_clashing_monikers',
-  error => qr/tables 'bar', 'bars' reduced to the same source moniker 'Bar'/,
+  error => qr/tables (?:"bar", "bars"|"bars", "bar") reduced to the same source moniker 'Bar'/,
+);
+
+
+$t->cleanup;
+
+# test naming => { column_accessors => 'preserve' }
+# also test POD for unique constraint
+$t->dump_test(
+    classname => 'DBICTest::Schema::_preserve_column_accessors',
+    test_db_class => 'make_dbictest_db_with_unique',
+    options => { naming => { column_accessors => 'preserve' } },
+    neg_regexes => {
+        RouteChange => [
+            qr/\baccessor\b/,
+        ],
+    },
+    regexes => {
+        Baz => [
+            qr/\n\n=head1 UNIQUE CONSTRAINTS\n\n=head2 C<baz_num_unique>\n\n=over 4\n\n=item \* L<\/baz_num>\n\n=back\n\n=cut\n\n__PACKAGE__->add_unique_constraint\("baz_num_unique"\, \["baz_num"\]\);\n\n/,
+        ],
+    }
+);
+
+$t->cleanup;
+
+# test that rels are sorted
+$t->dump_test(
+    classname => 'DBICTest::Schema::_sorted_rels',
+    test_db_class => 'make_dbictest_db_with_unique',
+    regexes => {
+        Baz => [
+            qr/->might_have\(\n  "quux".*->belongs_to\(\n  "station_visited"/s,
+        ],
+    }
 );
 
+$t->cleanup;
+
+# test naming => { monikers => 'plural' }
+$t->dump_test(
+    classname => 'DBICTest::Schema::_plural_monikers',
+    options => { naming => { monikers => 'plural' } },
+    regexes => {
+        Foos => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Foos\n\n=cut\n\n/,
+        ],
+        Bars => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_plural_monikers::Bars\n\n=cut\n\n/,
+        ],
+    },
+);
+
+$t->cleanup;
+
+# test naming => { monikers => 'singular' }
+$t->dump_test(
+    classname => 'DBICTest::Schema::_singular_monikers',
+    test_db_class => 'make_dbictest_db_plural_tables',
+    options => { naming => { monikers => 'singular' } },
+    regexes => {
+        Foo => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Foo\n\n=cut\n\n/,
+        ],
+        Bar => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_singular_monikers::Bar\n\n=cut\n\n/,
+        ],
+    },
+);
+
+$t->cleanup;
+
+# test naming => { monikers => 'preserve' }
+$t->dump_test(
+    classname => 'DBICTest::Schema::_preserve_monikers',
+    test_db_class => 'make_dbictest_db_plural_tables',
+    options => { naming => { monikers => 'preserve' } },
+    regexes => {
+        Foos => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Foos\n\n=cut\n\n/,
+        ],
+        Bars => [
+            qr/\n=head1 NAME\n\nDBICTest::Schema::_preserve_monikers::Bars\n\n=cut\n\n/,
+        ],
+    },
+);
 
 $t->cleanup;
 
@@ -88,10 +159,6 @@ $t->dump_test(
     left_base_classes => 'TestLeftBase',
     components => [ 'TestComponent', '+TestComponentFQN' ],
   },
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
-  ],
   regexes => {
     schema => [
       qr/package DBICTest::DumpMore::1;/,
@@ -99,32 +166,34 @@ $t->dump_test(
     ],
     Foo => [
       qr/package DBICTest::DumpMore::1::Foo;/,
-      qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\n/,
-      qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\n/,
-      qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item L<TestAdditional>\n\n=back\n\n=cut\n\n/,
-      qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
-      qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
-      qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item L<DBIx::Class::TestComponent>\n\n=item L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Foo\n\n=cut\n\nuse strict;\nuse warnings;\n\n/,
+      qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/,
+      qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 TABLE: C<foo>\n\n=cut\n\n__PACKAGE__->table\("foo"\);\n\n/,
       qr/\n=head1 ACCESSORS\n\n/,
       qr/\n=head2 fooid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 0\n\n/,
       qr/\n=head2 footext\n\n  data_type: 'text'\n  default_value: 'footext'\n  extra: {is_footext => 1}\n  is_nullable: 1\n\n/,
-      qr/->set_primary_key/,
+      qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/fooid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("fooid"\);\n/,
       qr/\n=head1 RELATIONS\n\n/,
       qr/\n=head2 bars\n\nType: has_many\n\nRelated object: L<DBICTest::DumpMore::1::Bar>\n\n=cut\n\n/,
       qr/1;\n$/,
     ],
     Bar => [
       qr/package DBICTest::DumpMore::1::Bar;/,
-      qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\n/,
-      qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\n/,
-      qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item L<TestAdditional>\n\n=back\n\n=cut\n\n/,
-      qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
-      qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
-      qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item L<DBIx::Class::TestComponent>\n\n=item L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 NAME\n\nDBICTest::DumpMore::1::Bar\n\n=cut\n\nuse strict;\nuse warnings;\n\n/,
+      qr/\n=head1 BASE CLASS: L<My::ResultBaseClass>\n\n=cut\n\nuse base 'My::ResultBaseClass';\n\n/,
+      qr/\n=head1 ADDITIONAL CLASSES USED\n\n=over 4\n\n=item \* L<TestAdditional>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 ADDITIONAL BASE CLASSES\n\n=over 4\n\n=item \* L<TestAdditionalBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 LEFT BASE CLASSES\n\n=over 4\n\n=item \* L<TestLeftBase>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 COMPONENTS LOADED\n\n=over 4\n\n=item \* L<DBIx::Class::TestComponent>\n\n=item \* L<TestComponentFQN>\n\n=back\n\n=cut\n\n/,
+      qr/\n=head1 TABLE: C<bar>\n\n=cut\n\n__PACKAGE__->table\("bar"\);\n\n/,
       qr/\n=head1 ACCESSORS\n\n/,
       qr/\n=head2 barid\n\n  data_type: 'integer'\n  is_auto_increment: 1\n  is_nullable: 0\n\n/,
       qr/\n=head2 fooref\n\n  data_type: 'integer'\n  is_foreign_key: 1\n  is_nullable: 1\n\n/,
-      qr/->set_primary_key/,
+      qr/\n=head1 PRIMARY KEY\n\n=over 4\n\n=item \* L<\/barid>\n\n=back\n\n=cut\n\n__PACKAGE__->set_primary_key\("barid"\);\n/,
       qr/\n=head1 RELATIONS\n\n/,
       qr/\n=head2 fooref\n\nType: belongs_to\n\nRelated object: L<DBICTest::DumpMore::1::Foo>\n\n=cut\n\n/,
       qr/\n1;\n$/,
@@ -132,16 +201,11 @@ $t->dump_test(
   },
 );
 
-
 $t->append_to_class('DBICTest::DumpMore::1::Foo',q{# XXX This is my custom content XXX});
 
 
 $t->dump_test(
   classname => 'DBICTest::DumpMore::1',
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
-  ],
   regexes => {
     schema => [
       qr/package DBICTest::DumpMore::1;/,
@@ -166,13 +230,6 @@ $t->dump_test(
   options => {
     really_erase_my_files => 1 
   },
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Deleting existing file /,
-    qr/Deleting existing file /,
-    qr/Deleting existing file /,
-    qr/Schema dump completed/,
-  ],
   regexes => {
     schema => [
       qr/package DBICTest::DumpMore::1;/,
@@ -206,10 +263,6 @@ $t->dump_test(
     use_namespaces => 1,
     generate_pod => 0
   },
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
-  ],
   neg_regexes => {
     'Result/Foo' => [
       qr/^=/m,
@@ -226,8 +279,7 @@ $t->dump_test(
     use_namespaces => 1
   },
   warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
+    qr/^db_schema is not supported on SQLite/,
   ],
   regexes => {
     'Result/Foo' => [
@@ -238,16 +290,33 @@ $t->dump_test(
   },
 );
 
+# test moniker_parts
 $t->dump_test(
   classname => 'DBICTest::DumpMore::1',
   options => {
-    use_namespaces => 1
+    db_schema => 'my_schema',
+    moniker_parts => ['_schema', 'name'],
+    qualify_objects => 1,
+    use_namespaces => 1,
   },
   warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
+    qr/^db_schema is not supported on SQLite/,
   ],
   regexes => {
+    'Result/MySchemaFoo' => [
+      qr/^\Q__PACKAGE__->table("my_schema.foo");\E/m,
+      # the has_many relname should not have the schema in it!
+      qr/^__PACKAGE__->has_many\(\n  "bars"/m,
+    ],
+  },
+);
+
+$t->dump_test(
+  classname => 'DBICTest::DumpMore::1',
+  options => {
+    use_namespaces => 1
+  },
+  regexes => {
     schema => [
       qr/package DBICTest::DumpMore::1;/,
       qr/->load_namespaces/,
@@ -274,17 +343,13 @@ $t->dump_test(
     resultset_namespace => 'RSet',
     default_resultset_class => 'RSetBase',
   },
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
-  ],
   regexes => {
     schema => [
       qr/package DBICTest::DumpMore::1;/,
       qr/->load_namespaces/,
-      qr/result_namespace => 'Res'/,
-      qr/resultset_namespace => 'RSet'/,
-      qr/default_resultset_class => 'RSetBase'/,
+      qr/result_namespace => "Res"/,
+      qr/resultset_namespace => "RSet"/,
+      qr/default_resultset_class => "RSetBase"/,
     ],
     'Res/Foo' => [
       qr/package DBICTest::DumpMore::1::Res::Foo;/,
@@ -310,17 +375,13 @@ $t->dump_test(
     result_base_class => 'My::ResultBaseClass',
     schema_base_class => 'My::SchemaBaseClass',
   },
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
-  ],
   regexes => {
     schema => [
       qr/package DBICTest::DumpMore::1;/,
       qr/->load_namespaces/,
-      qr/result_namespace => '\+DBICTest::DumpMore::1::Res'/,
-      qr/resultset_namespace => 'RSet'/,
-      qr/default_resultset_class => 'RSetBase'/,
+      qr/result_namespace => "\+DBICTest::DumpMore::1::Res"/,
+      qr/resultset_namespace => "RSet"/,
+      qr/default_resultset_class => "RSetBase"/,
       qr/use base 'My::SchemaBaseClass'/,
     ],
     'Res/Foo' => [
@@ -338,7 +399,6 @@ $t->dump_test(
   },
 );
 
-
 $t->dump_test(
   classname => 'DBICTest::DumpMore::1',
   options => {
@@ -356,10 +416,7 @@ $t->dump_test(
     '',
     { quote_char => '"' },
   ],
-  warnings => [
-    qr/Dumping manual schema for DBICTest::DumpMore::1 to directory /,
-    qr/Schema dump completed/,
-  ],
 );
 
 done_testing;
+# vim:et sts=4 sw=4 tw=0: