From: Jess Robinson Date: Tue, 20 Apr 2010 06:06:26 +0000 (+0000) Subject: Warn if a class found in ResultSet/ is not a subclass of ::ResultSet X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1d3108a48a8220200e4377793f03bb05d1eecd5e;p=dbsrgits%2FDBIx-Class-Historic.git Warn if a class found in ResultSet/ is not a subclass of ::ResultSet --- diff --git a/Changes b/Changes index 79934bc..185677f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - Add a warning to load_namespaces if a class in ResultSet/ is not a subclass of DBIx::Class::ResultSet - InflateColumn::DateTime support for MSSQL via DBD::Sybase - millisecond precision support for MSSQL datetimes for InflateColumn::DateTime diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index c64eed0..cea821a 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -271,6 +271,10 @@ sub load_namespaces { } elsif($rs_class ||= $default_resultset_class) { $class->ensure_class_loaded($rs_class); + if(!$rs_class->isa("DBIx::Class::ResultSet")) { + carp "load_namespaces found ResultSet class $rs_class that does not subclass DBIx::Class::ResultSet"; + } + $class->_ns_get_rsrc_instance ($result_class)->resultset_class($rs_class); } diff --git a/t/39load_namespaces_1.t b/t/39load_namespaces_1.t index f20ca8c..5798518 100644 --- a/t/39load_namespaces_1.t +++ b/t/39load_namespaces_1.t @@ -7,8 +7,6 @@ use Test::More; use lib qw(t/lib); use DBICTest; # do not remove even though it is not used -plan tests => 8; - my $warnings; eval { local $SIG{__WARN__} = sub { $warnings .= shift }; @@ -16,8 +14,10 @@ eval { use base qw/DBIx::Class::Schema/; __PACKAGE__->load_namespaces; }; -ok(!$@) or diag $@; -like($warnings, qr/load_namespaces found ResultSet class C with no corresponding Result class/); +ok(!$@, 'load_namespaces doesnt die') or diag $@; +like($warnings, qr/load_namespaces found ResultSet class C with no corresponding Result class/, 'Found warning about extra ResultSet classes'); + +like($warnings, qr/load_namespaces found ResultSet class DBICNSTest::ResultSet::D that does not subclass DBIx::Class::ResultSet/, 'Found warning about ResultSets with incorrect subclass'); my $source_a = DBICNSTest->source('A'); isa_ok($source_a, 'DBIx::Class::ResultSource::Table'); @@ -31,5 +31,7 @@ isa_ok($rset_b, 'DBIx::Class::ResultSet'); for my $moniker (qw/A B/) { my $class = "DBICNSTest::Result::$moniker"; - ok(!defined($class->result_source_instance->source_name)); + ok(!defined($class->result_source_instance->source_name), "Source name of $moniker not defined"); } + +done_testing;