adds the ability to filter generated code
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 27filter_generated.t
1 use strict;
2 use File::Slurp qw(slurp);
3 use File::Path;
4 use Test::More tests => 4;
5 use Test::Exception;
6 use lib qw(t/lib);
7 use make_dbictest_db;
8 use dbixcsl_test_dir qw/$tdir/;
9
10 use DBIx::Class::Schema::Loader;
11
12 my $dump_path = "$tdir/dump";
13
14 my %original_class_data;
15
16 {
17     package DBICTest::Schema::1;
18     use base qw/ DBIx::Class::Schema::Loader /;
19     __PACKAGE__->loader_options(
20         dump_directory => $dump_path,
21         filter_generated_text => sub {
22             my ($class, $text) = @_;
23             $original_class_data{$class} = $text;
24             if ($class =~ /::1$/) {
25                 $text = "No Gotcha!";
26             }
27             else {
28                 $text .= q{"Kilroy was here";};
29             }
30             return $text;
31         },
32     );
33 }
34
35 DBICTest::Schema::1->connect($make_dbictest_db::dsn);
36
37 my $foo = slurp("$dump_path/DBICTest/Schema/1/Result/Foo.pm");
38 ok(! -e "$dump_path/DBICTest/Schema/1.pm",
39      "No package means no file written");
40 ok($original_class_data{"DBICTest::Schema::1"},
41      "Even though we processed the missing class");
42 like($foo, qr/# Created by .* THE FIRST PART/s,
43      "We get the whole autogenerated text");
44 like($foo, qr/Kilroy was here/, "Can insert text");
45
46 END { rmtree($dump_path, 1, 1); }