adds the ability to filter generated code
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 27filter_generated.t
CommitLineData
dde95f2c 1use strict;
2use File::Slurp qw(slurp);
3use File::Path;
4use Test::More tests => 4;
5use Test::Exception;
6use lib qw(t/lib);
7use make_dbictest_db;
8use dbixcsl_test_dir qw/$tdir/;
9
10use DBIx::Class::Schema::Loader;
11
12my $dump_path = "$tdir/dump";
13
14my %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
35DBICTest::Schema::1->connect($make_dbictest_db::dsn);
36
37my $foo = slurp("$dump_path/DBICTest/Schema/1/Result/Foo.pm");
38ok(! -e "$dump_path/DBICTest/Schema/1.pm",
39 "No package means no file written");
40ok($original_class_data{"DBICTest::Schema::1"},
41 "Even though we processed the missing class");
42like($foo, qr/# Created by .* THE FIRST PART/s,
43 "We get the whole autogenerated text");
44like($foo, qr/Kilroy was here/, "Can insert text");
45
46END { rmtree($dump_path, 1, 1); }