preserve relnames when another FK is added (RT#62424), remove resultset_components...
Rafael Kitover [Thu, 16 Dec 2010 23:01:13 +0000 (18:01 -0500)]
13 files changed:
Changes
lib/DBIx/Class/Schema/Loader/Base.pm
lib/DBIx/Class/Schema/Loader/RelBuilder.pm
lib/DBIx/Class/Schema/Loader/Utils.pm
t/12pg_common.t
t/14ora_common.t
t/16mssql_common.t
t/18firebird_common.t
t/25backcompat.t
t/backcompat/0.04006/lib/DBIx/Class/TestRSComponent.pm [deleted file]
t/backcompat/0.04006/lib/dbixcsl_common_tests.pm
t/lib/DBIx/Class/TestRSComponent.pm [deleted file]
t/lib/dbixcsl_common_tests.pm

diff --git a/Changes b/Changes
index 8a592de..e3c4941 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+        - Preserve relationship names when redumping and another FK is added
+          (RT#62424)
+        - Remove resultset_components as ResultSetManager is deprecated
         - Fix a fail when very old Moose/CMOP is installed
         - Added warning for column-accessor collisions, doc section in ::Base
           ("COLUMN ACCESSOR COLLISIONS") and the col_collision_map option.
index 62391c4..0f3aa0c 100644 (file)
@@ -36,7 +36,6 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 additional_base_classes
                                 left_base_classes
                                 components
-                                resultset_components
                                 skip_relationships
                                 skip_load_external
                                 moniker_map
@@ -85,6 +84,7 @@ __PACKAGE__->mk_group_accessors('simple', qw/
                                 pod_comment_spillover_length
                                 preserve_case
                                 col_collision_map
+                                real_dump_directory
 /);
 
 =head1 NAME
@@ -345,13 +345,6 @@ List of additional components to be loaded into all of your table
 classes.  A good example would be
 L<InflateColumn::DateTime|DBIx::Class::InflateColumn::DateTime>
 
-=head2 resultset_components
-
-List of additional ResultSet components to be loaded into your table
-classes.  A good example would be C<AlwaysRS>.  Component
-C<ResultSetManager> will be automatically added to the above
-C<components> list if this option is set.
-
 =head2 use_namespaces
 
 This is now the default, to go back to L<DBIx::Class::Schema/load_classes> pass
@@ -366,13 +359,9 @@ to the call (and the generated result class names adjusted appropriately).
 
 =head2 dump_directory
 
-This option is designed to be a tool to help you transition from this
-loader to a manually-defined schema when you decide it's time to do so.
-
 The value of this option is a perl libdir pathname.  Within
 that directory this module will create a baseline manual
-L<DBIx::Class::Schema> module set, based on what it creates at runtime
-in memory.
+L<DBIx::Class::Schema> module set, based on what it creates at runtime.
 
 The created schema class will have the same classname as the one on
 which you are setting this option (and the ResultSource classes will be
@@ -512,7 +501,7 @@ my $CURRENT_V = 'v7';
 
 my @CLASS_ARGS = qw(
     schema_base_class result_base_class additional_base_classes
-    left_base_classes additional_classes components resultset_components
+    left_base_classes additional_classes components
 );
 
 # ensure that a peice of object data is a valid arrayref, creating
@@ -562,7 +551,6 @@ sub new {
                                additional_base_classes
                                left_base_classes
                                components
-                               resultset_components
                               /);
 
     $self->_validate_class_args;
@@ -574,9 +562,6 @@ sub new {
         }
     }
 
-    push(@{$self->{components}}, 'ResultSetManager')
-        if @{$self->{resultset_components}};
-
     $self->{monikers} = {};
     $self->{classes} = {};
     $self->{_upgrading_classes} = {};
@@ -596,6 +581,8 @@ sub new {
 
     $self->{dump_directory} ||= $self->{temp_directory};
 
+    $self->real_dump_directory($self->{dump_directory});
+
     $self->version_to_dump($DBIx::Class::Schema::Loader::VERSION);
     $self->schema_version_to_dump($DBIx::Class::Schema::Loader::VERSION);
 
@@ -794,8 +781,8 @@ sub _find_file_in_inc {
         my $fullpath = File::Spec->catfile($prefix, $file);
         return $fullpath if -f $fullpath
             # abs_path throws on Windows for nonexistant files
-            and eval { Cwd::abs_path($fullpath) } ne
-               (eval { Cwd::abs_path(File::Spec->catfile($self->dump_directory, $file)) } || '');
+            and (try { Cwd::abs_path($fullpath) }) ne
+               ((try { Cwd::abs_path(File::Spec->catfile($self->dump_directory, $file)) }) || '');
     }
 
     return;
@@ -1044,6 +1031,7 @@ sub _load_tables {
         local $self->{dump_directory} = $self->{temp_directory};
         $self->_reload_classes(\@tables);
         $self->_load_relationships($_) for @tables;
+        $self->_relbuilder->cleanup;
         $self->{quiet} = 0;
 
         # Remove that temp dir from INC so it doesn't get reloaded
@@ -1055,7 +1043,7 @@ sub _load_tables {
 
     # Reload without unloading first to preserve any symbols from external
     # packages.
-    $self->_reload_classes(\@tables, 0);
+    $self->_reload_classes(\@tables, { unload => 0 });
 
     # Drop temporary cache
     delete $self->{_cache};
@@ -1064,9 +1052,11 @@ sub _load_tables {
 }
 
 sub _reload_classes {
-    my ($self, $tables, $unload) = @_;
+    my ($self, $tables, $opts) = @_;
 
     my @tables = @$tables;
+
+    my $unload = $opts->{unload};
     $unload = 1 unless defined $unload;
 
     # so that we don't repeat custom sections
@@ -1137,10 +1127,12 @@ sub _reload_class {
     delete $INC{ $class_path };
 
 # kill redefined warnings
-    eval {
+    try {
         eval_without_redefine_warnings ("require $class");
+    }
+    catch {
+        die "Failed to reload class $class: $_";
     };
-    die "Failed to reload class $class: $@" if $@;
 }
 
 sub _get_dump_filename {
@@ -1150,6 +1142,23 @@ sub _get_dump_filename {
     return $self->dump_directory . q{/} . $class . q{.pm};
 }
 
+=head2 get_dump_filename
+
+Arguments: class
+
+Returns the full path to the file for a class that the class has been or will
+be dumped to. This is a file in a temp dir for a dynamic schema.
+
+=cut
+
+sub get_dump_filename {
+    my ($self, $class) = (@_);
+
+    local $self->{dump_directory} = $self->real_dump_directory;
+
+    return $self->_get_dump_filename($class);
+}
+
 sub _ensure_dump_subdirs {
     my ($self, $class) = (@_);
 
@@ -1180,13 +1189,13 @@ sub _dump_to_dir {
     my $schema_text =
           qq|package $schema_class;\n\n|
         . qq|# Created by DBIx::Class::Schema::Loader\n|
-        . qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|
-        . qq|use strict;\nuse warnings;\n\n|;
+        . qq|# DO NOT MODIFY THE FIRST PART OF THIS FILE\n\n|;
+
     if ($self->use_moose) {
         $schema_text.= qq|use Moose;\nuse MooseX::NonMoose;\nuse namespace::autoclean;\nextends '$schema_base_class';\n\n|;
     }
     else {
-        $schema_text .= qq|use base '$schema_base_class';\n\n|;
+        $schema_text .= qq|use strict;\nuse warnings;\n\nuse base '$schema_base_class';\n\n|;
     }
 
     if ($self->use_namespaces) {
@@ -1520,8 +1529,6 @@ sub _make_src_class {
         $self->_dbic_stmt($table_class, 'load_components', @components);
     }
 
-    $self->_dbic_stmt($table_class, 'load_resultset_components', @{$self->resultset_components})
-        if @{$self->resultset_components};
     $self->_inject($table_class, @{$self->additional_base_classes});
 }
 
@@ -1963,7 +1970,7 @@ sub _uc {
 sub _unregister_source_for_table {
     my ($self, $table) = @_;
 
-    eval {
+    try {
         local $@;
         my $schema = $self->schema;
         # in older DBIC it's a private method
index b212480..d78542b 100644 (file)
@@ -2,12 +2,17 @@ package DBIx::Class::Schema::Loader::RelBuilder;
 
 use strict;
 use warnings;
+use base 'Class::Accessor::Grouped';
 use mro 'c3';
 use Carp::Clan qw/^DBIx::Class/;
-use Scalar::Util ();
-
+use Scalar::Util 'weaken';
 use Lingua::EN::Inflect::Phrase ();
 use DBIx::Class::Schema::Loader::Utils 'split_name';
+use File::Slurp 'slurp';
+use Try::Tiny;
+use Class::Unload ();
+use List::MoreUtils 'apply';
+use namespace::clean;
 
 our $VERSION = '0.07002';
 
@@ -70,6 +75,14 @@ arguments, like so:
 
 =cut
 
+__PACKAGE__->mk_group_accessors('simple', qw/
+    base
+    schema
+    inflect_plural
+    inflect_singular
+    relationship_attrs
+    _temp_classes
+/);
 
 sub new {
     my ( $class, $base ) = @_;
@@ -89,17 +102,20 @@ sub new {
         inflect_plural     => $base->inflect_plural,
         inflect_singular   => $base->inflect_singular,
         relationship_attrs => $base->relationship_attrs,
+        _temp_classes      => [],
     };
 
-    Scalar::Util::weaken $self->{base}; #< don't leak
+    weaken $self->{base}; #< don't leak
+
+    bless $self => $class;
 
     # validate the relationship_attrs arg
-    if( defined $self->{relationship_attrs} ) {
-       ref $self->{relationship_attrs} eq 'HASH'
+    if( defined $self->relationship_attrs ) {
+       ref $self->relationship_attrs eq 'HASH'
            or croak "relationship_attrs must be a hashref";
     }
 
-    return bless $self => $class;
+    return $self;
 }
 
 
@@ -109,12 +125,12 @@ sub _inflect_plural {
 
     return '' if !defined $relname || $relname eq '';
 
-    if( ref $self->{inflect_plural} eq 'HASH' ) {
-        return $self->{inflect_plural}->{$relname}
-            if exists $self->{inflect_plural}->{$relname};
+    if( ref $self->inflect_plural eq 'HASH' ) {
+        return $self->inflect_plural->{$relname}
+            if exists $self->inflect_plural->{$relname};
     }
-    elsif( ref $self->{inflect_plural} eq 'CODE' ) {
-        my $inflected = $self->{inflect_plural}->($relname);
+    elsif( ref $self->inflect_plural eq 'CODE' ) {
+        my $inflected = $self->inflect_plural->($relname);
         return $inflected if $inflected;
     }
 
@@ -127,12 +143,12 @@ sub _inflect_singular {
 
     return '' if !defined $relname || $relname eq '';
 
-    if( ref $self->{inflect_singular} eq 'HASH' ) {
-        return $self->{inflect_singular}->{$relname}
-            if exists $self->{inflect_singular}->{$relname};
+    if( ref $self->inflect_singular eq 'HASH' ) {
+        return $self->inflect_singular->{$relname}
+            if exists $self->inflect_singular->{$relname};
     }
-    elsif( ref $self->{inflect_singular} eq 'CODE' ) {
-        my $inflected = $self->{inflect_singular}->($relname);
+    elsif( ref $self->inflect_singular eq 'CODE' ) {
+        my $inflected = $self->inflect_singular->($relname);
         return $inflected if $inflected;
     }
 
@@ -180,7 +196,7 @@ sub _default_relationship_attrs { +{
 # either a hashref (if some options are set), or nothing
 sub _relationship_attrs {
     my ( $self, $reltype ) = @_;
-    my $r = $self->{relationship_attrs};
+    my $r = $self->relationship_attrs;
 
     my %composite = (
         %{ $self->_default_relationship_attrs->{$reltype} || {} },
@@ -214,7 +230,7 @@ sub _remote_attrs {
 
     # If the referring column is nullable, make 'belongs_to' an
     # outer join, unless explicitly set by relationship_attrs
-    my $nullable = grep { $self->{schema}->source($local_moniker)->column_info($_)->{is_nullable} } @$local_cols;
+    my $nullable = grep { $self->schema->source($local_moniker)->column_info($_)->{is_nullable} } @$local_cols;
     $attrs->{join_type} = 'LEFT' if $nullable && !defined $attrs->{join_type};
 
     return $attrs;
@@ -269,7 +285,7 @@ sub generate_code {
 
     my $all_code = {};
 
-    my $local_class = $self->{schema}->class($local_moniker);
+    my $local_class = $self->schema->class($local_moniker);
 
     my %counters;
     foreach my $rel (@$rels) {
@@ -281,8 +297,8 @@ sub generate_code {
         my $remote_moniker = $rel->{remote_source}
             or next;
 
-        my $remote_class   = $self->{schema}->class($remote_moniker);
-        my $remote_obj     = $self->{schema}->source($remote_moniker);
+        my $remote_class   = $self->schema->class($remote_moniker);
+        my $remote_obj     = $self->schema->source($remote_moniker);
         my $remote_cols    = $rel->{remote_columns} || [ $remote_obj->primary_columns ];
 
         my $local_cols     = $rel->{local_columns};
@@ -334,43 +350,86 @@ sub _relnames_and_method {
     my ( $self, $local_moniker, $rel, $cond, $uniqs, $counters ) = @_;
 
     my $remote_moniker = $rel->{remote_source};
-    my $remote_obj     = $self->{schema}->source( $remote_moniker );
-    my $remote_class   = $self->{schema}->class(  $remote_moniker );
+    my $remote_obj     = $self->schema->source( $remote_moniker );
+    my $remote_class   = $self->schema->class(  $remote_moniker );
     my $remote_relname = $self->_remote_relname( $remote_obj->from, $cond);
 
-    my $local_cols  = $rel->{local_columns};
-    my $local_table = $self->{schema}->source($local_moniker)->from;
+    my $local_cols     = $rel->{local_columns};
+    my $local_table    = $self->schema->source($local_moniker)->from;
+    my $local_class    = $self->schema->class($local_moniker);
+    my $local_source   = $self->schema->source($local_moniker);
 
-    # If more than one rel between this pair of tables, use the local
-    # col names to distinguish
-    my ($local_relname, $local_relname_uninflected);
-    if ( $counters->{$remote_moniker} > 1) {
-        my $colnames = q{_} . $self->_normalize_name(join '_', @$local_cols);
-        $remote_relname .= $colnames if keys %$cond > 1;
-
-        $local_relname = $self->_normalize_name($local_table . $colnames);
-        $local_relname =~ s/_id$//;
-
-        $local_relname_uninflected = $local_relname;
-        $local_relname = $self->_inflect_plural($local_relname);
-    } else {
-        $local_relname_uninflected = $self->_normalize_name($local_table);
-        $local_relname = $self->_inflect_plural($self->_normalize_name($local_table));
-    }
+    my $local_relname_uninflected = $self->_normalize_name($local_table);
+    my $local_relname = $self->_inflect_plural($self->_normalize_name($local_table));
 
     my $remote_method = 'has_many';
 
     # If the local columns have a UNIQUE constraint, this is a one-to-one rel
-    my $local_source = $self->{schema}->source($local_moniker);
     if ($self->_array_eq([ $local_source->primary_columns ], $local_cols) ||
             grep { $self->_array_eq($_->[1], $local_cols) } @$uniqs) {
         $remote_method = 'might_have';
         $local_relname = $self->_inflect_singular($local_relname_uninflected);
     }
 
+    # If more than one rel between this pair of tables, use the local
+    # col names to distinguish, unless the rel was created previously.
+    if ($counters->{$remote_moniker} > 1) {
+        my $relationship_exists = 0;
+
+        if (-f (my $existing_remote_file = $self->{base}->get_dump_filename($remote_class))) {
+            my $class = "${remote_class}Temporary";
+
+            if (not do { no strict 'refs'; %{$class . '::'} }) {
+                my $code = slurp $existing_remote_file;
+
+                $code =~ s/(?<=package $remote_class)/Temporary/g;
+
+                $code =~ s/__PACKAGE__->meta->make_immutable;//g;
+
+                eval $code;
+                die $@ if $@;
+
+                push @{ $self->_temp_classes }, $class;
+            }
+
+            if ($class->has_relationship($local_relname)) {
+                my $rel_cols = [ sort { $a cmp $b } apply { s/^foreign\.//i }
+                    (keys %{ $class->relationship_info($local_relname)->{cond} }) ];
+
+                $relationship_exists = 1 if $self->_array_eq([ sort @$local_cols ], $rel_cols);
+            }
+        }
+
+        if (not $relationship_exists) {
+            my $colnames = q{_} . $self->_normalize_name(join '_', @$local_cols);
+            $remote_relname .= $colnames if keys %$cond > 1;
+
+            $local_relname = $self->_normalize_name($local_table . $colnames);
+            $local_relname =~ s/_id$//;
+
+            $local_relname_uninflected = $local_relname;
+            $local_relname = $self->_inflect_plural($local_relname);
+
+            # if colnames were added and this is a might_have, re-inflect
+            if ($remote_method eq 'might_have') {
+                $local_relname = $self->_inflect_singular($local_relname_uninflected);
+            }
+        }
+    }
+
     return ( $local_relname, $remote_relname, $remote_method );
 }
 
+sub cleanup {
+    my $self = shift;
+
+    for my $class (@{ $self->_temp_classes }) {
+        Class::Unload->unload($class);
+    }
+
+    $self->_temp_classes([]);
+}
+
 =head1 AUTHOR
 
 See L<DBIx::Class::Schema::Loader/AUTHOR> and L<DBIx::Class::Schema::Loader/CONTRIBUTORS>.
index a1350c7..f67988f 100644 (file)
@@ -4,9 +4,11 @@ package # hide from PAUSE
 use strict;
 use warnings;
 use Data::Dumper ();
+use Test::More;
+use namespace::clean;
 use Exporter 'import';
 
-our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_without_redefine_warnings/;
+our @EXPORT_OK = qw/split_name dumper dumper_squashed eval_without_redefine_warnings warnings_exist warnings_exist_silent/;
 
 use constant BY_CASE_TRANSITION =>
     qr/(?<=[[:lower:]\d])[\W_]*(?=[[:upper:]])|[\W_]+/;
@@ -48,5 +50,38 @@ sub eval_without_redefine_warnings {
     die $@ if $@;
 }
 
+sub warnings_exist(&$$) {
+    my ($code, $re, $test_name) = @_;
+
+    my $matched = 0;
+
+    my $warn_handler = $SIG{__WARN__} || sub { warn @_ };
+    local $SIG{__WARN__} = sub {
+        if ($_[0] =~ $re) {
+            $matched = 1;
+        }
+        else {
+            $warn_handler->(@_)
+        }
+    };
+
+    $code->();
+
+    ok $matched, $test_name;
+}
+
+sub warnings_exist_silent(&$$) {
+    my ($code, $re, $test_name) = @_;
+
+    my $matched = 0;
+
+    local $SIG{__WARN__} = sub { $matched = 1 if $_[0] =~ $re; };
+
+    $code->();
+
+    ok $matched, $test_name;
+}
+
+
 1;
 # vim:et sts=4 sw=4 tw=0:
index a74bd0d..3f21d25 100644 (file)
@@ -168,7 +168,7 @@ my $tester = dbixcsl_common_tests->new(
                 'qualified sequence detected';
 
             my $class    = $classes->{pg_loader_test1};
-            my $filename = $schema->_loader->_get_dump_filename($class);
+            my $filename = $schema->_loader->get_dump_filename($class);
 
             my $code = slurp $filename;
 
@@ -179,7 +179,7 @@ my $tester = dbixcsl_common_tests->new(
                 'column comment and attrs';
 
             $class    = $classes->{pg_loader_test2};
-            $filename = $schema->_loader->_get_dump_filename($class);
+            $filename = $schema->_loader->get_dump_filename($class);
 
             $code = slurp $filename;
 
index c4c9f7a..f8bd668 100644 (file)
@@ -160,7 +160,7 @@ my $tester = dbixcsl_common_tests->new(
 
             SKIP: {
                 skip 'not running comment tests', 1 unless (my $class = $classes->{oracle_loader_test1});
-                my $filename = $schema->_loader->_get_dump_filename($class);
+                my $filename = $schema->_loader->get_dump_filename($class);
                 my $code = File::Slurp::slurp $filename;
 
                 like $code, qr/^=head1 NAME\n\n^$class - oracle_loader_test1 table comment\n\n^=cut\n/m,
index 7455727..805352b 100644 (file)
@@ -2,7 +2,8 @@ use strict;
 use warnings;
 use Test::More;
 use Test::Exception;
-use Test::Warn;
+use DBIx::Class::Schema::Loader::Utils 'warnings_exist_silent';
+use namespace::clean;
 
 # use this if you keep a copy of DBD::Sybase linked to FreeTDS somewhere else
 BEGIN {
@@ -257,7 +258,7 @@ my $tester = dbixcsl_common_tests->new(
             my $dbh = $schema->storage->dbh;
             $dbh->do("DROP TABLE mssql_loader_test3");
 
-            warnings_exist { $schema->rescan }
+            warnings_exist_silent { $schema->rescan }
               qr/^Bad table or view 'mssql_loader_test4'/, 'bad view ignored';
 
             throws_ok {
index 486bea2..eb42cde 100644 (file)
@@ -114,6 +114,7 @@ my $tester = dbixcsl_common_tests->new(
         count  => 6,
         run    => sub {
             $schema = shift;
+            my ($monikers, $classes, $self) = @_;
 
             cleanup_extra();
 
@@ -146,11 +147,7 @@ q{
             local $schema->_loader->{preserve_case} = 1;
             $schema->_loader->_setup;
 
-            {
-                # FIXME - need to remove blind trap (can not test firebird yet)
-                local $SIG{__WARN__} = sub {};
-                $schema->rescan;
-            }
+            $self->rescan_without_warnings($schema);
 
             ok ((my $rsrc = eval { $schema->resultset('FirebirdLoaderTest1')->result_source }),
                 'got rsrc for mixed case table');
index 2f2940d..3aec02f 100644 (file)
@@ -734,7 +734,7 @@ sub class_content_like;
     my $res = run_loader(static => 1, naming => 'current');
     my $schema = $res->{schema};
 
-    my $file = $schema->_loader->_get_dump_filename($SCHEMA_CLASS);
+    my $file = $schema->_loader->get_dump_filename($SCHEMA_CLASS);
     my $code = slurp $file;
 
     my ($dumped_ver) =
@@ -1301,7 +1301,7 @@ sub _rel_condition {
 sub class_content_like {
     my ($schema, $class, $re, $test_name) = @_;
 
-    my $file = $schema->_loader->_get_dump_filename($class);
+    my $file = $schema->_loader->get_dump_filename($class);
     my $code = slurp $file;
 
     like $code, $re, $test_name;
@@ -1333,7 +1333,7 @@ EOF
 sub _write_custom_content {
     my ($schema, $class, $content) = @_;
 
-    my $pm = $schema->_loader->_get_dump_filename($class);
+    my $pm = $schema->_loader->get_dump_filename($class);
     {
         local ($^I, @ARGV) = ('.bak', $pm);
         while (<>) {
diff --git a/t/backcompat/0.04006/lib/DBIx/Class/TestRSComponent.pm b/t/backcompat/0.04006/lib/DBIx/Class/TestRSComponent.pm
deleted file mode 100644 (file)
index e6808ad..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package DBIx::Class::TestRSComponent;
-use base qw/DBIx::Class::ResultSet/;
-
-sub dbix_class_testrscomponent { 'dbix_class_testrscomponent works' }
-
-1;
index 9e2b967..0a1e2d7 100644 (file)
@@ -43,7 +43,7 @@ sub _monikerize {
 sub run_tests {
     my $self = shift;
 
-    plan tests => 101;
+    plan tests => 98;
 
     $self->create();
 
@@ -66,13 +66,6 @@ sub run_tests {
     );
 
     $loader_opts{db_schema} = $self->{db_schema} if $self->{db_schema};
-    eval { require Class::Inspector };
-    if($@) {
-        $self->{_no_rs_components} = 1;
-    }
-    else {
-        $loader_opts{resultset_components} = [ qw/TestRSComponent/ ];
-    }
 
     {
        my @loader_warnings;
@@ -176,7 +169,7 @@ sub run_tests {
 
     {
         my ($skip_tab, $skip_tabo, $skip_taba, $skip_cmeth,
-            $skip_rsmeth, $skip_tcomp, $skip_trscomp);
+            $skip_tcomp, $skip_trscomp);
 
         can_ok( $class1, 'test_additional_base' ) or $skip_tab = 1;
         can_ok( $class1, 'test_additional_base_override' ) or $skip_tabo = 1;
@@ -184,8 +177,6 @@ sub run_tests {
         can_ok( $class1, 'dbix_class_testcomponent' ) or $skip_tcomp = 1;
         can_ok( $class1, 'loader_test1_classmeth' ) or $skip_cmeth = 1;
 
-        can_ok( $rsobj1, 'loader_test1_rsmeth' ) or $skip_rsmeth = 1;
-
         SKIP: {
             skip "Pre-requisite test failed", 1 if $skip_tab;
             is( $class1->test_additional_base, "test_additional_base",
@@ -212,26 +203,9 @@ sub run_tests {
         }
 
         SKIP: {
-            skip "These two tests need Class::Inspector installed", 2
-                     if $self->{_no_rs_components};
-            can_ok($rsobj1, 'dbix_class_testrscomponent') or $skip_trscomp = 1;
-            SKIP: {
-                skip "Pre-requisite test failed", 1 if $skip_trscomp;
-                is( $rsobj1->dbix_class_testrscomponent,
-                    'dbix_class_testrscomponent works' );
-            }
-        }
-
-        SKIP: {
             skip "Pre-requisite test failed", 1 if $skip_cmeth;
             is( $class1->loader_test1_classmeth, 'all is well' );
         }
-
-        # XXX put this back in when the TODO above works...
-        #SKIP: {
-        #    skip "Pre-requisite test failed", 1 if $skip_rsmeth;
-        #    is( $rsobj1->loader_test1_rsmeth, 'all is still well' );
-        #}
     }
 
 
diff --git a/t/lib/DBIx/Class/TestRSComponent.pm b/t/lib/DBIx/Class/TestRSComponent.pm
deleted file mode 100644 (file)
index e6808ad..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package DBIx::Class::TestRSComponent;
-use base qw/DBIx::Class::ResultSet/;
-
-sub dbix_class_testrscomponent { 'dbix_class_testrscomponent works' }
-
-1;
index 8ed64d4..d3b87f7 100644 (file)
@@ -22,6 +22,8 @@ use dbixcsl_test_dir qw/$tdir/;
 my $DUMP_DIR = "$tdir/common_dump";
 rmtree $DUMP_DIR;
 
+use constant RESCAN_WARNINGS => qr/(?i:loader_test)\d+ has no primary key|^Dumping manual schema|^Schema dump completed|collides with an inherited method|invalidates \d+ active statement|^Bad table or view/;
+
 sub new {
     my $class = shift;
 
@@ -92,7 +94,7 @@ sub run_tests {
 
     my $extra_count = $self->{extra}{count} || 0;
 
-    plan tests => @connect_info * (185 + $extra_count + ($self->{data_type_tests}{test_count} || 0));
+    plan tests => @connect_info * (181 + $extra_count + ($self->{data_type_tests}{test_count} || 0));
 
     foreach my $info_idx (0..$#connect_info) {
         my $info = $connect_info[$info_idx];
@@ -138,7 +140,7 @@ sub run_only_extra_tests {
         my $conn = $schema_class->clone;
 
         $self->test_data_types($conn);
-        $self->{extra}{run}->($conn, $monikers, $classes) if $self->{extra}{run};
+        $self->{extra}{run}->($conn, $monikers, $classes, $self) if $self->{extra}{run};
 
         if (not ($ENV{SCHEMA_LOADER_TESTS_NOCLEANUP} && $info_idx == $#$connect_info)) {
             $self->drop_extra_tables_only;
@@ -190,7 +192,6 @@ sub setup_schema {
         additional_base_classes => 'TestAdditionalBase',
         left_base_classes       => [ qw/TestLeftBase/ ],
         components              => [ qw/TestComponent/ ],
-        resultset_components    => [ qw/TestRSComponent/ ],
         inflect_plural          => { loader_test4 => 'loader_test4zes' },
         inflect_singular        => { fkid => 'fkid_singular' },
         moniker_map             => \&_monikerize,
@@ -247,7 +248,6 @@ sub setup_schema {
         is $file_count, $expected_count, 'correct number of files generated';
  
         my $warn_count = 2;
-        $warn_count++ if grep /ResultSetManager/, @loader_warnings;
  
         $warn_count++ for grep /^Bad table or view/, @loader_warnings;
  
@@ -401,25 +401,11 @@ sub test_schema {
     }
 
     SKIP: {
-        can_ok($rsobj1, 'dbix_class_testrscomponent')
-            or skip "Pre-requisite test failed", 1;
-        is( $rsobj1->dbix_class_testrscomponent,
-            'dbix_class_testrscomponent works',
-            'ResultSet component' );
-    }
-
-    SKIP: {
         can_ok( $class1, 'loader_test1_classmeth' )
             or skip "Pre-requisite test failed", 1;
         is( $class1->loader_test1_classmeth, 'all is well', 'Class method' );
     }
 
-    SKIP: {
-        can_ok( $rsobj1, 'loader_test1_rsmeth' )
-            or skip "Pre-requisite test failed";
-        is( $rsobj1->loader_test1_rsmeth, 'all is still well', 'Result set method' );
-    }
-    
     ok( $class1->column_info('id')->{is_auto_increment}, 'is_auto_increment detection' );
 
     my $obj    = $rsobj1->find(1);
@@ -856,16 +842,22 @@ sub test_schema {
 
             # relname is preserved when another fk is added
 
-            isa_ok $rsobj3->find(1)->loader_test4zes, 'DBIx::Class::ResultSet';
+            skip 'Sybase cannot add FKs via ALTER TABLE', 2
+                if $self->{vendor} eq 'sybase';
 
-            $conn->storage->dbh->do('ALTER TABLE loader_test4 ADD COLUMN fkid2 INTEGER REFERENCES loader_test3 (id)');
             {
-                local $SIG{__WARN__} = sub { warn @_
-                    unless $_[0] =~ /(?i:loader_test)\d+ has no primary key|^Dumping manual schema|^Schema dump completed|collides with an inherited method|invalidates \d+ active statement/
-                };
-                $conn->rescan;
+                local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ /invalidates \d+ active statement/ };
+                $conn->storage->disconnect; # for mssql
             }
 
+            isa_ok $rsobj3->find(1)->loader_test4zes, 'DBIx::Class::ResultSet';
+
+            $conn->storage->dbh->do('ALTER TABLE loader_test4 ADD fkid2 INTEGER REFERENCES loader_test3 (id)');
+
+            $conn->storage->disconnect; # for firebird
+
+            $self->rescan_without_warnings($conn);
+
             isa_ok eval { $rsobj3->find(1)->loader_test4zes }, 'DBIx::Class::ResultSet',
                 'relationship name preserved when another foreign key is added in remote table';
         }
@@ -950,12 +942,8 @@ sub test_schema {
 
         sleep 1;
 
-        my @new = do {
-            local $SIG{__WARN__} = sub { warn @_
-                unless $_[0] =~ /(?i:loader_test)\d+ has no primary key|^Dumping manual schema|^Schema dump completed|collides with an inherited method/
-            };
-            $conn->rescan;
-        };
+        my @new = $self->rescan_without_warnings($conn);
+
         is_deeply(\@new, [ qw/LoaderTest30/ ], "Rescan");
 
 #        system "cp t/_common_dump/DBIXCSL_Test/Schema/*.pm /tmp/after_rescan";
@@ -983,12 +971,8 @@ sub test_schema {
         $conn->storage->disconnect; # for Firebird
         $conn->storage->dbh->do("DROP TABLE loader_test30");
 
-        @new = do {
-            local $SIG{__WARN__} = sub { warn @_
-                unless $_[0] =~ /(?i:loader_test)\d+ has no primary key|^Dumping manual schema|^Schema dump completed|collides with an inherited method/
-            };
-            $conn->rescan;
-        };
+        @new = $self->rescan_without_warnings($conn);
+
         is_deeply(\@new, [], 'no new tables on rescan');
 
         throws_ok { $conn->resultset('LoaderTest30') }
@@ -999,7 +983,7 @@ sub test_schema {
     $self->test_data_types($conn);
 
     # run extra tests
-    $self->{extra}{run}->($conn, $monikers, $classes) if $self->{extra}{run};
+    $self->{extra}{run}->($conn, $monikers, $classes, $self) if $self->{extra}{run};
 
     $self->test_preserve_case($conn);
 
@@ -1064,12 +1048,7 @@ qq| INSERT INTO ${oqt}LoaderTest41${cqt} VALUES (1, 1) |,
     $conn->_loader->_setup;
 
 
-    {
-        local $SIG{__WARN__} = sub { warn @_
-            unless $_[0] =~ /(?i:loader_test)\d+ has no primary key|^Dumping manual schema|^Schema dump completed|collides with an inherited method/
-        };
-        $conn->rescan;
-    };
+    $self->rescan_without_warnings($conn);
 
     if (not $self->{skip_rels}) {
         is $conn->resultset('LoaderTest41')->find(1)->loader_test40->foo3_bar, 'foo',
@@ -1873,6 +1852,13 @@ sub setup_data_type_tests {
     return $test_count;
 }
 
+sub rescan_without_warnings {
+    my ($self, $conn) = @_;
+
+    local $SIG{__WARN__} = sub { warn @_ unless $_[0] =~ RESCAN_WARNINGS };
+    return $conn->rescan;
+}
+
 sub DESTROY {
     my $self = shift;
     unless ($ENV{SCHEMA_LOADER_TESTS_NOCLEANUP}) {