added tests for additional_classes, additional_base_classes, left_base_classes
Brandon Black [Mon, 30 Jan 2006 19:39:00 +0000 (19:39 +0000)]
TODO
t/TestAdditional.pm [new file with mode: 0644]
t/TestAdditionalBase.pm [new file with mode: 0644]
t/TestLeftBase.pm [new file with mode: 0644]
t/dbixcsl_common_tests.pm

diff --git a/TODO b/TODO
index 24c6e2f..db0a04c 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,7 +3,6 @@ Reminders to myself or whoever else ever looks in here...
 
 SQLite needs some heavy refactoring, the subroutines are becoming too complex to understand easily.
 MySQL needs implicit FK support, I think.
-Need tests for left_base_classes, additional_classes, additional_base_classes...
 
 Consider:
    If local column is UNIQUE or PK, use has_one() for relation?
diff --git a/t/TestAdditional.pm b/t/TestAdditional.pm
new file mode 100644 (file)
index 0000000..d47fddb
--- /dev/null
@@ -0,0 +1,5 @@
+package TestAdditional;
+
+sub test_additional { return "test_additional"; }
+
+1;
diff --git a/t/TestAdditionalBase.pm b/t/TestAdditionalBase.pm
new file mode 100644 (file)
index 0000000..85159c0
--- /dev/null
@@ -0,0 +1,7 @@
+package TestAdditionalBase;
+
+sub test_additional_base { return "test_additional_base"; }
+sub test_additional_base_override { return "test_additional_base_override"; }
+sub test_additional_base_additional { return TestAdditional->test_additional; }
+
+1;
diff --git a/t/TestLeftBase.pm b/t/TestLeftBase.pm
new file mode 100644 (file)
index 0000000..c836957
--- /dev/null
@@ -0,0 +1,5 @@
+package TestLeftBase;
+
+sub test_additional_base_override { return "test_left_base_override"; }
+
+1;
index d3a5a6a..1a35c10 100644 (file)
@@ -37,7 +37,7 @@ sub skip_tests {
 sub run_tests {
     my $self = shift;
 
-    plan tests => 32;
+    plan tests => 38;
 
     $self->create();
 
@@ -46,12 +46,15 @@ sub run_tests {
     my $debug = ($self->{verbose} > 1) ? 1 : 0;
 
     my %loader_opts = (
-        dsn           => $self->{dsn},
-        user          => $self->{user},
-        password      => $self->{password},
-        constraint    => '^(?:\S+\.)?(?i:loader_test)[0-9]+$',
-        relationships => 1,
-        debug         => $debug,
+        dsn                     => $self->{dsn},
+        user                    => $self->{user},
+        password                => $self->{password},
+        constraint              => '^(?:\S+\.)?(?i:loader_test)[0-9]+$',
+        relationships           => 1,
+        additional_classes      => 'TestAdditional',
+        additional_base_classes => 'TestAdditionalBase',
+        left_base_classes       => [ qw/TestLeftBase/ ],
+        debug                   => $debug,
     );
 
     $loader_opts{db_schema} = $self->{db_schema} if $self->{db_schema};
@@ -63,7 +66,7 @@ sub run_tests {
 
         __PACKAGE__->load_from_connection(\%loader_opts);
     };
-    ok(!$@, "Loader initialization failed: $@");
+    ok(!$@, "Loader initialization") or diag $@;
 
     my $conn = $schema_class->connect($self->{dsn},$self->{user},$self->{password});
     my $monikers = $schema_class->loader->monikers;
@@ -80,6 +83,19 @@ sub run_tests {
     isa_ok( $rsobj1, "DBIx::Class::ResultSet" );
     isa_ok( $rsobj2, "DBIx::Class::ResultSet" );
 
+    can_ok( $class1, 'test_additional_base' );
+    can_ok( $class1, 'test_additional_base_override' );
+    can_ok( $class1, 'test_additional_base_additional' );
+
+    is( $class1->test_additional_base, "test_additional_base",
+        "Additional Base method" );
+
+    is( $class1->test_additional_base_override, "test_left_base_override",
+        "Left Base overrides Additional Base method" );
+
+    is( $class1->test_additional_base_additional, "test_additional",
+        "Additional Base can use Additional package method" );
+
     my $obj    = $rsobj1->find(1);
     is( $obj->id,  1 );
     is( $obj->dat, "foo" );