adds the ability to filter generated code
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 27filter_generated.t
diff --git a/t/27filter_generated.t b/t/27filter_generated.t
new file mode 100644 (file)
index 0000000..22eb772
--- /dev/null
@@ -0,0 +1,46 @@
+use strict;
+use File::Slurp qw(slurp);
+use File::Path;
+use Test::More tests => 4;
+use Test::Exception;
+use lib qw(t/lib);
+use make_dbictest_db;
+use dbixcsl_test_dir qw/$tdir/;
+
+use DBIx::Class::Schema::Loader;
+
+my $dump_path = "$tdir/dump";
+
+my %original_class_data;
+
+{
+    package DBICTest::Schema::1;
+    use base qw/ DBIx::Class::Schema::Loader /;
+    __PACKAGE__->loader_options(
+        dump_directory => $dump_path,
+        filter_generated_text => sub {
+            my ($class, $text) = @_;
+            $original_class_data{$class} = $text;
+           if ($class =~ /::1$/) {
+                $text = "No Gotcha!";
+           }
+            else {
+               $text .= q{"Kilroy was here";};
+           }
+            return $text;
+        },
+    );
+}
+
+DBICTest::Schema::1->connect($make_dbictest_db::dsn);
+
+my $foo = slurp("$dump_path/DBICTest/Schema/1/Result/Foo.pm");
+ok(! -e "$dump_path/DBICTest/Schema/1.pm",
+     "No package means no file written");
+ok($original_class_data{"DBICTest::Schema::1"},
+     "Even though we processed the missing class");
+like($foo, qr/# Created by .* THE FIRST PART/s,
+     "We get the whole autogenerated text");
+like($foo, qr/Kilroy was here/, "Can insert text");
+
+END { rmtree($dump_path, 1, 1); }