name 'DBIx-Class-Schema-Loader';
all_from 'lib/DBIx/Class/Schema/Loader.pm';
-test_requires 'Test::More' => '0.47';
-test_requires 'DBI' => '1.56';
-test_requires 'DBD::SQLite' => '1.12';
-test_requires 'File::Path' => 0;
+test_requires 'Test::More' => '0.47';
+test_requires 'DBI' => '1.56';
+test_requires 'DBD::SQLite' => '1.12';
+test_requires 'File::Path' => 0;
+test_requires 'Class::Unload' => 0;
requires 'File::Spec' => 0;
requires 'Scalar::Util' => 0;
my $target = shift;
my $schema_class = $self->schema_class;
- my $blist = join(q{ }, @_);
- warn "$target: use base qw/ $blist /;" if $self->debug && @_;
- $self->_raw_stmt($target, "use base qw/ $blist /;") if @_;
+ my $blist = join(q{ }, map "+$_", @_);
+ warn "$target: __PACKAGE__->load_components( qw/ $blist / );" if $self->debug && @_;
+ $self->_raw_stmt($target, "__PACKAGE__->load_components( qw/ $blist / );") if @_;
foreach (@_) {
$_->require or croak ($_ . "->require: $@");
$schema_class->inject_base($target, $_);
use Test::More;
use DBIx::Class::Schema::Loader;
-use Class::Inspector;
+use Class::Unload;
+use File::Path;
use DBI;
+my $DUMP_DIR = './t/_common_dump';
+rmtree $DUMP_DIR;
+
sub new {
my $class = shift;
sub run_tests {
my $self = shift;
- plan tests => 134 + ($self->{extra}->{count} || 0);
+ plan tests => 3 + 2 * (131 + ($self->{extra}->{count} || 0));
$self->create();
+ my @connect_info = ( $self->{dsn}, $self->{user}, $self->{password} );
+
+ # First, with in-memory classes
+ my $schema_class = $self->setup_schema(@connect_info);
+ $self->test_schema($schema_class);
+
+ # Then, with dumped classes
+ $self->drop_tables;
+ $self->create;
+ $self->{dump} = 1;
+
+ unshift @INC, $DUMP_DIR;
+ $self->reload_schema($schema_class);
+ $schema_class->connection(@connect_info);
+ $self->test_schema($schema_class);
+}
+
+sub setup_schema {
+ my $self = shift;
+ my @connect_info = @_;
+
my $schema_class = 'DBIXCSL_Test::Schema';
my $debug = ($self->{verbose} > 1) ? 1 : 0;
- my @connect_info = ( $self->{dsn}, $self->{user}, $self->{password} );
my %loader_opts = (
constraint => qr/^(?:\S+\.)?(?:$self->{vendor}_)?loader_test[0-9]+$/i,
relationships => 1,
inflect_singular => { fkid => 'fkid_singular' },
moniker_map => \&_monikerize,
debug => $debug,
+ dump_directory => $DUMP_DIR,
);
$loader_opts{db_schema} = $self->{db_schema} if $self->{db_schema};
__PACKAGE__->loader_options(\%loader_opts);
__PACKAGE__->connection(\@connect_info);
};
+
ok(!$@, "Loader initialization") or diag $@;
if($self->{skip_rels}) {
SKIP: {
- is(scalar(@loader_warnings), 0, "No loader warnings")
+ is(scalar(@loader_warnings), 2, "No loader warnings")
or diag @loader_warnings;
skip "No missing PK warnings without rels", 1;
}
}
else {
- is(scalar(@loader_warnings), 1, "Expected loader warning")
+ is(scalar(@loader_warnings), 3, "Expected loader warning")
or diag @loader_warnings;
like($loader_warnings[0], qr/loader_test9 has no primary key/i,
"Missing PK warning");
}
}
+
+ return $schema_class;
+}
+
+sub test_schema {
+ my $self = shift;
+ my $schema_class = shift;
my $conn = $schema_class->clone;
my $monikers = {};
# rescan test
SKIP: {
skip $self->{skip_rels}, 4 if $self->{skip_rels};
+ skip "Can't rescan dumped schema", 4 if $self->{dump};
my @statements_rescan = (
qq{
$dbh->disconnect;
}
+sub reload_schema {
+ my ($self, $schema) = @_;
+
+ for my $source ($schema->sources) {
+ Class::Unload->unload( $schema->class( $source ) );
+ Class::Unload->unload( ref $schema->resultset( $source ) );
+ }
+
+ Class::Unload->unload( $schema );
+ eval "require $schema" or die $@;
+}
+
sub DESTROY {
my $self = shift;
$self->drop_tables if $self->{_created};
+ rmtree $DUMP_DIR;
}
1;