[Bast-commits] r8220 - in
branches/DBIx-Class-Schema-Loader/current: .
lib/DBIx/Class/Schema/Loader t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sat Jan 2 05:01:34 GMT 2010
Author: caelum
Date: 2010-01-02 05:01:34 +0000 (Sat, 02 Jan 2010)
New Revision: 8220
Modified:
branches/DBIx-Class-Schema-Loader/current/Changes
branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
Log:
add test (and fix) for loading external custom content from unsingularized results into upgraded static schemas
Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes 2010-01-02 00:41:12 UTC (rev 8219)
+++ branches/DBIx-Class-Schema-Loader/current/Changes 2010-01-02 05:01:34 UTC (rev 8220)
@@ -1,5 +1,6 @@
Revision history for Perl extension DBIx::Class::Schema::Loader
+ - 'naming' attribute and backward compatibility with 0.04006
- added relationship_attrs option for setting attributes in
generated relationships
- added overwrite_modifications option that ignores md5sums on
Modified: branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT 2010-01-02 00:41:12 UTC (rev 8219)
+++ branches/DBIx-Class-Schema-Loader/current/TODO-BACKCOMPAT 2010-01-02 05:01:34 UTC (rev 8220)
@@ -1,10 +1,5 @@
SL Backcompat Plan:
-*** 0.04006 mode
-
-* test getting custom content from un-singularized classes in _load_external
- for a static schema
-
* make use_namespaces the default, and upgrade to it properly
*** Catalyst Helper
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2010-01-02 00:41:12 UTC (rev 8219)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2010-01-02 05:01:34 UTC (rev 8220)
@@ -578,9 +578,10 @@
or croak "Failed to open '$old_real_inc_path' for reading: $!";
$self->_ext_stmt($class, <<"EOF");
-# These lines were loaded from '$old_real_inc_path', based on the Result class
-# name that would have been created by an 0.04006 version of the Loader. For a
-# static schema, this happens only once during upgrade.
+# These lines were loaded from '$old_real_inc_path',
+# based on the Result class name that would have been created by an 0.04006
+# version of the Loader. For a static schema, this happens only once during
+# upgrade.
EOF
if ($self->dynamic) {
warn <<"EOF";
@@ -607,6 +608,7 @@
while(<$fh>) {
chomp;
+ s/$old_class/$class/g;
$self->_ext_stmt($class, $_);
}
$self->_ext_stmt($class,
Modified: branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t 2010-01-02 00:41:12 UTC (rev 8219)
+++ branches/DBIx-Class-Schema-Loader/current/t/25backcompat_v4.t 2010-01-02 05:01:34 UTC (rev 8220)
@@ -88,17 +88,47 @@
pop @INC;
}
+# test upgraded static schema with external content loaded
+{
+ my $temp_dir = tempdir;
+ push @INC, $temp_dir;
+
+ my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
+ make_path $external_result_dir;
+
+ IO::File->new(">$external_result_dir/Quuxs.pm")->print(<<"EOF");
+package ${SCHEMA_CLASS}::Quuxs;
+sub a_method { 'dongs' }
+1;
+EOF
+
+ write_v4_schema_pm();
+
+ my $res = run_loader(dump_directory => $DUMP_DIR, naming => 'current');
+ my $schema = $res->{schema};
+
+ run_v5_tests($res);
+
+ is eval { $schema->resultset('Quux')->find(1)->a_method }, 'dongs',
+'external custom content for unsingularized Result was loaded by upgraded ' .
+'static Schema';
+
+ my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
+ my $code = do { local ($/, @ARGV) = (undef, $file); <> };
+
+ like $code, qr/package ${SCHEMA_CLASS}::Quux;/,
+'package line translated correctly from external custom content in static dump';
+
+ like $code, qr/sub a_method { 'dongs' }/,
+'external custom content loaded into static dump correctly';
+
+ rmtree $temp_dir;
+ pop @INC;
+}
+
# test running against v4 schema without upgrade
{
- # write out the 0.04006 Schema.pm we have in __DATA__
- (my $schema_dir = "$DUMP_DIR/$SCHEMA_CLASS") =~ s/::[^:]+\z//;
- make_path $schema_dir;
- my $schema_pm = "$schema_dir/Schema.pm";
- open my $fh, '>', $schema_pm or die $!;
- while (<DATA>) {
- print $fh $_;
- }
- close $fh;
+ write_v4_schema_pm();
# now run the loader
my $res = run_loader(dump_directory => $DUMP_DIR);
@@ -207,6 +237,32 @@
};
}
+sub write_v4_schema_pm {
+ (my $schema_dir = "$DUMP_DIR/$SCHEMA_CLASS") =~ s/::[^:]+\z//;
+ rmtree $schema_dir;
+ make_path $schema_dir;
+ my $schema_pm = "$schema_dir/Schema.pm";
+ open my $fh, '>', $schema_pm or die $!;
+ print $fh <<'EOF';
+package DBIXCSL_Test::Schema;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Schema';
+
+__PACKAGE__->load_classes;
+
+
+# Created by DBIx::Class::Schema::Loader v0.04006 @ 2009-12-25 01:49:25
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ibIJTbfM1ji4pyD/lgSEog
+
+
+# You can replace this text with custom content, and it will be preserved on regeneration
+1;
+EOF
+}
+
sub run_v4_tests {
my $res = shift;
my $schema = $res->{schema};
@@ -246,24 +302,3 @@
isa_ok eval { $baz->quux }, $res->{classes}{quuxs},
'correct rel type and name for UNIQUE FK in current mode';
}
-
-# a Schema.pm made with 0.04006
-
-__DATA__
-package DBIXCSL_Test::Schema;
-
-use strict;
-use warnings;
-
-use base 'DBIx::Class::Schema';
-
-__PACKAGE__->load_classes;
-
-
-# Created by DBIx::Class::Schema::Loader v0.04006 @ 2009-12-25 01:49:25
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ibIJTbfM1ji4pyD/lgSEog
-
-
-# You can replace this text with custom content, and it will be preserved on regeneration
-1;
-
More information about the Bast-commits
mailing list