support downgrade from use_namespaces
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 25backcompat_v4.t
CommitLineData
66afce69 1use strict;
2use warnings;
3use Test::More;
b24cb177 4use Test::Exception;
a0e0a56a 5use File::Path qw/rmtree make_path/;
66afce69 6use Class::Unload;
ffc705f3 7use File::Temp qw/tempfile tempdir/;
8use IO::File;
68d49e50 9use DBIx::Class::Schema::Loader ();
66afce69 10use lib qw(t/lib);
11use make_dbictest_db2;
12
13my $DUMP_DIR = './t/_common_dump';
14rmtree $DUMP_DIR;
a0e0a56a 15my $SCHEMA_CLASS = 'DBIXCSL_Test::Schema';
66afce69 16
66afce69 17# test dynamic schema in 0.04006 mode
18{
19 my $res = run_loader();
a0e0a56a 20 my $warning = $res->{warnings}[0];
66afce69 21
a0e0a56a 22 like $warning, qr/dynamic schema/i,
66afce69 23 'dynamic schema in backcompat mode detected';
a0e0a56a 24 like $warning, qr/run in 0\.04006 mode/i,
66afce69 25 'dynamic schema in 0.04006 mode warning';
a0e0a56a 26 like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/,
27 'warning refers to upgrading doc';
28
29 run_v4_tests($res);
30}
66afce69 31
a0e0a56a 32# setting naming accessor on dynamic schema should disable warning (even when
33# we're setting it to 'v4' .)
34{
35 my $res = run_loader(naming => 'v4');
66afce69 36
a0e0a56a 37 is_deeply $res->{warnings}, [], 'no warnings with naming attribute set';
f53dcdf0 38
39 run_v4_tests($res);
a0e0a56a 40}
41
42# test upgraded dynamic schema
43{
44 my $res = run_loader(naming => 'current');
66afce69 45
a0e0a56a 46# to dump a schema for debugging...
47# {
48# mkdir '/tmp/HLAGH';
49# $schema->_loader->{dump_directory} = '/tmp/HLAGH';
50# $schema->_loader->_dump_to_dir(values %{ $res->{classes} });
51# }
66afce69 52
a0e0a56a 53 is_deeply $res->{warnings}, [], 'no warnings with naming attribute set';
66afce69 54
a0e0a56a 55 run_v5_tests($res);
56}
57
ffc705f3 58# test upgraded dynamic schema with external content loaded
59{
60 my $temp_dir = tempdir;
61 push @INC, $temp_dir;
62
63 my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
64 make_path $external_result_dir;
65
b24cb177 66 # make external content for Result that will be singularized
ffc705f3 67 IO::File->new(">$external_result_dir/Quuxs.pm")->print(<<"EOF");
68package ${SCHEMA_CLASS}::Quuxs;
69sub a_method { 'hlagh' }
b24cb177 70
71__PACKAGE__->has_one('bazrel', 'DBIXCSL_Test::Schema::Bazs',
72 { 'foreign.baz_num' => 'self.baz_id' });
73
741;
75EOF
76
77 # make external content for Result that will NOT be singularized
78 IO::File->new(">$external_result_dir/Bar.pm")->print(<<"EOF");
79package ${SCHEMA_CLASS}::Bar;
80
81__PACKAGE__->has_one('foorel', 'DBIXCSL_Test::Schema::Foos',
82 { 'foreign.fooid' => 'self.foo_id' });
83
ffc705f3 841;
85EOF
86
87 my $res = run_loader(naming => 'current');
88 my $schema = $res->{schema};
89
90 is scalar @{ $res->{warnings} }, 1,
91'correct nummber of warnings for upgraded dynamic schema with external ' .
92'content for unsingularized Result.';
93
94 my $warning = $res->{warnings}[0];
95 like $warning, qr/Detected external content/i,
96 'detected external content warning';
97
b24cb177 98 lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'hlagh' }
ffc705f3 99'external custom content for unsingularized Result was loaded by upgraded ' .
100'dynamic Schema';
101
b24cb177 102 lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel,
103 $res->{classes}{bazs} }
104 'unsingularized class names in external content are translated';
105
106 lives_and { isa_ok $schema->resultset('Bar')->find(1)->foorel,
107 $res->{classes}{foos} }
108'unsingularized class names in external content from unchanged Result class ' .
109'names are translated';
110
ffc705f3 111 run_v5_tests($res);
112
113 rmtree $temp_dir;
114 pop @INC;
115}
116
805dbe0a 117# test upgraded dynamic schema with use_namespaces with external content loaded
118{
119 my $temp_dir = tempdir;
120 push @INC, $temp_dir;
121
122 my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
123 make_path $external_result_dir;
124
125 # make external content for Result that will be singularized
126 IO::File->new(">$external_result_dir/Quuxs.pm")->print(<<"EOF");
127package ${SCHEMA_CLASS}::Quuxs;
128sub a_method { 'hlagh' }
129
a4b94090 130__PACKAGE__->has_one('bazrel4', 'DBIXCSL_Test::Schema::Bazs',
805dbe0a 131 { 'foreign.baz_num' => 'self.baz_id' });
132
1331;
134EOF
135
136 # make external content for Result that will NOT be singularized
137 IO::File->new(">$external_result_dir/Bar.pm")->print(<<"EOF");
138package ${SCHEMA_CLASS}::Bar;
139
a4b94090 140__PACKAGE__->has_one('foorel4', 'DBIXCSL_Test::Schema::Foos',
805dbe0a 141 { 'foreign.fooid' => 'self.foo_id' });
142
1431;
144EOF
145
146 my $res = run_loader(naming => 'current', use_namespaces => 1);
147 my $schema = $res->{schema};
148
149 is scalar @{ $res->{warnings} }, 2,
150'correct nummber of warnings for upgraded dynamic schema with external ' .
151'content for unsingularized Result with use_namespaces.';
152
153 my $warning = $res->{warnings}[0];
154 like $warning, qr/Detected external content/i,
155 'detected external content warning';
156
157 lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'hlagh' }
158'external custom content for unsingularized Result was loaded by upgraded ' .
159'dynamic Schema';
160
a4b94090 161 lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel4,
805dbe0a 162 $res->{classes}{bazs} }
163 'unsingularized class names in external content are translated';
164
a4b94090 165 lives_and { isa_ok $schema->resultset('Bar')->find(1)->foorel4,
805dbe0a 166 $res->{classes}{foos} }
167'unsingularized class names in external content from unchanged Result class ' .
168'names are translated';
169
170 run_v5_tests($res);
171
172 rmtree $temp_dir;
173 pop @INC;
174}
175
176
30a4c064 177# test upgraded static schema with external content loaded
178{
179 my $temp_dir = tempdir;
180 push @INC, $temp_dir;
181
182 my $external_result_dir = join '/', $temp_dir, split /::/, $SCHEMA_CLASS;
183 make_path $external_result_dir;
184
b24cb177 185 # make external content for Result that will be singularized
30a4c064 186 IO::File->new(">$external_result_dir/Quuxs.pm")->print(<<"EOF");
187package ${SCHEMA_CLASS}::Quuxs;
188sub a_method { 'dongs' }
b24cb177 189
190__PACKAGE__->has_one('bazrel2', 'DBIXCSL_Test::Schema::Bazs',
191 { 'foreign.baz_num' => 'self.baz_id' });
192
1931;
194EOF
195
196 # make external content for Result that will NOT be singularized
197 IO::File->new(">$external_result_dir/Bar.pm")->print(<<"EOF");
198package ${SCHEMA_CLASS}::Bar;
199
200__PACKAGE__->has_one('foorel2', 'DBIXCSL_Test::Schema::Foos',
201 { 'foreign.fooid' => 'self.foo_id' });
202
30a4c064 2031;
204EOF
205
206 write_v4_schema_pm();
207
208 my $res = run_loader(dump_directory => $DUMP_DIR, naming => 'current');
209 my $schema = $res->{schema};
210
211 run_v5_tests($res);
212
b24cb177 213 lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'dongs' }
30a4c064 214'external custom content for unsingularized Result was loaded by upgraded ' .
215'static Schema';
216
b24cb177 217 lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel2,
218 $res->{classes}{bazs} }
219 'unsingularized class names in external content are translated';
220
221 lives_and { isa_ok $schema->resultset('Bar')->find(1)->foorel2,
222 $res->{classes}{foos} }
223'unsingularized class names in external content from unchanged Result class ' .
224'names are translated in static schema';
225
30a4c064 226 my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
227 my $code = do { local ($/, @ARGV) = (undef, $file); <> };
228
229 like $code, qr/package ${SCHEMA_CLASS}::Quux;/,
230'package line translated correctly from external custom content in static dump';
231
232 like $code, qr/sub a_method { 'dongs' }/,
233'external custom content loaded into static dump correctly';
234
235 rmtree $temp_dir;
236 pop @INC;
237}
238
b24cb177 239# test running against v4 schema without upgrade, twice, then upgrade
a0e0a56a 240{
30a4c064 241 write_v4_schema_pm();
a0e0a56a 242 my $res = run_loader(dump_directory => $DUMP_DIR);
a1a91c42 243 my $warning = $res->{warnings}[1];
a0e0a56a 244
245 like $warning, qr/static schema/i,
246 'static schema in backcompat mode detected';
247 like $warning, qr/0.04006/,
248 'correct version detected';
249 like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/,
250 'refers to upgrading doc';
251
a1a91c42 252 is scalar @{ $res->{warnings} }, 4,
ffc705f3 253 'correct number of warnings for static schema in backcompat mode';
254
a0e0a56a 255 run_v4_tests($res);
256
257 # add some custom content to a Result that will be replaced
258 my $schema = $res->{schema};
259 my $quuxs_pm = $schema->_loader
260 ->_get_dump_filename($res->{classes}{quuxs});
261 {
262 local ($^I, @ARGV) = ('', $quuxs_pm);
263 while (<>) {
264 if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
265 print;
b24cb177 266 print <<EOF;
267sub a_method { 'mtfnpy' }
268
269__PACKAGE__->has_one('bazrel3', 'DBIXCSL_Test::Schema::Bazs',
270 { 'foreign.baz_num' => 'self.baz_id' });
271EOF
a0e0a56a 272 }
273 else {
274 print;
275 }
276 }
277 }
278
b24cb177 279 # Rerun the loader in backcompat mode to make sure it's still in backcompat
280 # mode.
281 $res = run_loader(dump_directory => $DUMP_DIR);
282 run_v4_tests($res);
283
a0e0a56a 284 # now upgrade the schema
a1a91c42 285 $res = run_loader(
286 dump_directory => $DUMP_DIR,
287 naming => 'current',
288 use_namespaces => 1
289 );
a0e0a56a 290 $schema = $res->{schema};
291
292 like $res->{warnings}[0], qr/Dumping manual schema/i,
293 'correct warnings on upgrading static schema (with "naming" set)';
294
295 like $res->{warnings}[1], qr/dump completed/i,
296 'correct warnings on upgrading static schema (with "naming" set)';
297
298 is scalar @{ $res->{warnings} }, 2,
f53dcdf0 299'correct number of warnings on upgrading static schema (with "naming" set)'
300 or diag @{ $res->{warnings} };
a0e0a56a 301
302 run_v5_tests($res);
303
a1a91c42 304 (my $result_dir = "$DUMP_DIR/$SCHEMA_CLASS/Result") =~ s{::}{/}g;
305 my $result_count =()= glob "$result_dir/*";
306
307 is $result_count, 4,
308 'un-singularized results were replaced during upgrade';
309
310 # check that custom content was preserved
311 lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'mtfnpy' }
312 'custom content was carried over from un-singularized Result';
313
314 lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel3,
315 $res->{classes}{bazs} }
316 'unsingularized class names in custom content are translated';
317
318 my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
319 my $code = do { local ($/, @ARGV) = (undef, $file); <> };
320
321 like $code, qr/sub a_method { 'mtfnpy' }/,
322'custom content from unsingularized Result loaded into static dump correctly';
323}
324
325# test running against v4 schema without upgrade, then upgrade with
326# use_namespaces not explicitly set
327{
328 write_v4_schema_pm();
329 my $res = run_loader(dump_directory => $DUMP_DIR);
330 my $warning = $res->{warnings}[1];
331
332 like $warning, qr/static schema/i,
333 'static schema in backcompat mode detected';
334 like $warning, qr/0.04006/,
335 'correct version detected';
336 like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/,
337 'refers to upgrading doc';
338
339 is scalar @{ $res->{warnings} }, 4,
340 'correct number of warnings for static schema in backcompat mode';
341
342 run_v4_tests($res);
343
344 # add some custom content to a Result that will be replaced
345 my $schema = $res->{schema};
346 my $quuxs_pm = $schema->_loader
347 ->_get_dump_filename($res->{classes}{quuxs});
348 {
349 local ($^I, @ARGV) = ('', $quuxs_pm);
350 while (<>) {
351 if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
352 print;
353 print <<EOF;
354sub a_method { 'mtfnpy' }
355
a4b94090 356__PACKAGE__->has_one('bazrel5', 'DBIXCSL_Test::Schema::Bazs',
a1a91c42 357 { 'foreign.baz_num' => 'self.baz_id' });
358EOF
359 }
360 else {
361 print;
362 }
363 }
364 }
365
366 # now upgrade the schema
367 $res = run_loader(
368 dump_directory => $DUMP_DIR,
369 naming => 'current'
370 );
371 $schema = $res->{schema};
372
373 like $res->{warnings}[0], qr/load_classes/i,
374'correct warnings on upgrading static schema (with "naming" set and ' .
375'use_namespaces not set)';
376
377 like $res->{warnings}[1], qr/Dumping manual schema/i,
378'correct warnings on upgrading static schema (with "naming" set and ' .
379'use_namespaces not set)';
380
381 like $res->{warnings}[2], qr/dump completed/i,
382'correct warnings on upgrading static schema (with "naming" set and ' .
383'use_namespaces not set)';
384
385 is scalar @{ $res->{warnings} }, 3,
386'correct number of warnings on upgrading static schema (with "naming" set)'
387 or diag @{ $res->{warnings} };
388
389 run_v5_tests($res);
390
a0e0a56a 391 (my $result_dir = "$DUMP_DIR/$SCHEMA_CLASS") =~ s{::}{/}g;
392 my $result_count =()= glob "$result_dir/*";
393
394 is $result_count, 4,
395 'un-singularized results were replaced during upgrade';
396
397 # check that custom content was preserved
b24cb177 398 lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'mtfnpy' }
a0e0a56a 399 'custom content was carried over from un-singularized Result';
b24cb177 400
a4b94090 401 lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel5,
402 $res->{classes}{bazs} }
403 'unsingularized class names in custom content are translated';
404
405 my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
406 my $code = do { local ($/, @ARGV) = (undef, $file); <> };
407
408 like $code, qr/sub a_method { 'mtfnpy' }/,
409'custom content from unsingularized Result loaded into static dump correctly';
410}
411
412# test running against v4 schema with load_namespaces, upgrade to v5 but
413# downgrade to load_classes
414{
415 write_v4_schema_pm(use_namespaces => 1);
416 my $res = run_loader(dump_directory => $DUMP_DIR);
417 my $warning = $res->{warnings}[0];
418
419 like $warning, qr/static schema/i,
420 'static schema in backcompat mode detected';
421 like $warning, qr/0.04006/,
422 'correct version detected';
423 like $warning, qr/DBIx::Class::Schema::Loader::Manual::UpgradingFromV4/,
424 'refers to upgrading doc';
425
426 is scalar @{ $res->{warnings} }, 3,
427 'correct number of warnings for static schema in backcompat mode';
428
429 run_v4_tests($res);
430
431 # add some custom content to a Result that will be replaced
432 my $schema = $res->{schema};
433 my $quuxs_pm = $schema->_loader
434 ->_get_dump_filename($res->{classes}{quuxs});
435 {
436 local ($^I, @ARGV) = ('', $quuxs_pm);
437 while (<>) {
438 if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
439 print;
440 print <<EOF;
441sub a_method { 'mtfnpy' }
442
443__PACKAGE__->has_one('bazrel6', 'DBIXCSL_Test::Schema::Result::Bazs',
444 { 'foreign.baz_num' => 'self.baz_id' });
445EOF
446 }
447 else {
448 print;
449 }
450 }
451 }
452
453 # now upgrade the schema to v5 but downgrade to load_classes
454 $res = run_loader(
455 dump_directory => $DUMP_DIR,
456 naming => 'current',
457 use_namespaces => 0,
458 );
459 $schema = $res->{schema};
460
461 like $res->{warnings}[0], qr/Dumping manual schema/i,
462'correct warnings on upgrading static schema (with "naming" set and ' .
463'use_namespaces => 0)';
464
465 like $res->{warnings}[1], qr/dump completed/i,
466'correct warnings on upgrading static schema (with "naming" set and ' .
467'use_namespaces => 0)';
468
469 is scalar @{ $res->{warnings} }, 2,
470'correct number of warnings on upgrading static schema (with "naming" set)'
471 or diag @{ $res->{warnings} };
472
473 run_v5_tests($res);
474
475 (my $result_dir = "$DUMP_DIR/$SCHEMA_CLASS") =~ s{::}{/}g;
476 my $result_count =()= glob "$result_dir/*";
477
478 is $result_count, 4,
479'un-singularized results were replaced during upgrade and Result dir removed';
480
481 ok ((not -d "$result_dir/Result"),
482 'Result dir was removed for load_classes downgrade');
483
484 # check that custom content was preserved
485 lives_and { is $schema->resultset('Quux')->find(1)->a_method, 'mtfnpy' }
486 'custom content was carried over from un-singularized Result';
487
488 lives_and { isa_ok $schema->resultset('Quux')->find(1)->bazrel6,
b24cb177 489 $res->{classes}{bazs} }
490 'unsingularized class names in custom content are translated';
491
492 my $file = $schema->_loader->_get_dump_filename($res->{classes}{quuxs});
493 my $code = do { local ($/, @ARGV) = (undef, $file); <> };
494
495 like $code, qr/sub a_method { 'mtfnpy' }/,
496'custom content from unsingularized Result loaded into static dump correctly';
497}
498
68d49e50 499# test upgrading a v4 schema, the check that the version string is correct
500{
501 write_v4_schema_pm();
502 run_loader(dump_directory => $DUMP_DIR);
503 my $res = run_loader(dump_directory => $DUMP_DIR, naming => 'current');
504 my $schema = $res->{schema};
505
506 my $file = $schema->_loader->_get_dump_filename($SCHEMA_CLASS);
507 my $code = do { local ($/, @ARGV) = (undef, $file); <> };
508
509 my ($dumped_ver) =
510 $code =~ /^# Created by DBIx::Class::Schema::Loader v(\S+)/m;
511
512 is $dumped_ver, $DBIx::Class::Schema::Loader::VERSION,
513 'correct version dumped after upgrade of v4 static schema';
514}
515
b24cb177 516# Test upgrading an already singular result with custom content that refers to
517# old class names.
518{
519 write_v4_schema_pm();
520 my $res = run_loader(dump_directory => $DUMP_DIR);
521 my $schema = $res->{schema};
522 run_v4_tests($res);
523
524 # add some custom content to a Result that will be replaced
525 my $bar_pm = $schema->_loader
526 ->_get_dump_filename($res->{classes}{bar});
527 {
528 local ($^I, @ARGV) = ('', $bar_pm);
529 while (<>) {
530 if (/DO NOT MODIFY THIS OR ANYTHING ABOVE/) {
531 print;
532 print <<EOF;
533sub a_method { 'lalala' }
534
535__PACKAGE__->has_one('foorel3', 'DBIXCSL_Test::Schema::Foos',
536 { 'foreign.fooid' => 'self.foo_id' });
537EOF
538 }
539 else {
540 print;
541 }
542 }
543 }
544
545 # now upgrade the schema
546 $res = run_loader(dump_directory => $DUMP_DIR, naming => 'current');
547 $schema = $res->{schema};
548 run_v5_tests($res);
549
550 # check that custom content was preserved
551 lives_and { is $schema->resultset('Bar')->find(1)->a_method, 'lalala' }
552 'custom content was preserved from Result pre-upgrade';
553
554 lives_and { isa_ok $schema->resultset('Bar')->find(1)->foorel3,
555 $res->{classes}{foos} }
556'unsingularized class names in custom content from Result with unchanged ' .
557'name are translated';
558
559 my $file = $schema->_loader->_get_dump_filename($res->{classes}{bar});
560 my $code = do { local ($/, @ARGV) = (undef, $file); <> };
561
562 like $code, qr/sub a_method { 'lalala' }/,
563'custom content from Result with unchanged name loaded into static dump ' .
564'correctly';
66afce69 565}
566
567done_testing;
568
ffc705f3 569END {
570 rmtree $DUMP_DIR unless $ENV{SCHEMA_LOADER_TESTS_NOCLEANUP};
571}
a0e0a56a 572
dbe9e0f7 573sub run_loader {
574 my %loader_opts = @_;
575
576 eval {
577 foreach my $source_name ($SCHEMA_CLASS->clone->sources) {
578 Class::Unload->unload("${SCHEMA_CLASS}::${source_name}");
579 }
580
581 Class::Unload->unload($SCHEMA_CLASS);
582 };
583 undef $@;
584
585 my @connect_info = $make_dbictest_db2::dsn;
586 my @loader_warnings;
587 local $SIG{__WARN__} = sub { push(@loader_warnings, $_[0]); };
588 eval qq{
589 package $SCHEMA_CLASS;
590 use base qw/DBIx::Class::Schema::Loader/;
591
592 __PACKAGE__->loader_options(\%loader_opts);
593 __PACKAGE__->connection(\@connect_info);
594 };
595
596 ok(!$@, "Loader initialization") or diag $@;
597
598 my $schema = $SCHEMA_CLASS->clone;
599 my (%monikers, %classes);
600 foreach my $source_name ($schema->sources) {
601 my $table_name = $schema->source($source_name)->from;
602 $monikers{$table_name} = $source_name;
d073740e 603 $classes{$table_name} = $schema->source($source_name)->result_class;
dbe9e0f7 604 }
605
606 return {
607 schema => $schema,
608 warnings => \@loader_warnings,
609 monikers => \%monikers,
610 classes => \%classes,
611 };
612}
613
30a4c064 614sub write_v4_schema_pm {
a4b94090 615 my %opts = @_;
616
30a4c064 617 (my $schema_dir = "$DUMP_DIR/$SCHEMA_CLASS") =~ s/::[^:]+\z//;
618 rmtree $schema_dir;
619 make_path $schema_dir;
620 my $schema_pm = "$schema_dir/Schema.pm";
621 open my $fh, '>', $schema_pm or die $!;
a4b94090 622 if (not $opts{use_namespaces}) {
623 print $fh <<'EOF';
30a4c064 624package DBIXCSL_Test::Schema;
625
626use strict;
627use warnings;
628
629use base 'DBIx::Class::Schema';
630
631__PACKAGE__->load_classes;
632
633
634# Created by DBIx::Class::Schema::Loader v0.04006 @ 2009-12-25 01:49:25
635# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ibIJTbfM1ji4pyD/lgSEog
636
637
638# You can replace this text with custom content, and it will be preserved on regeneration
6391;
640EOF
a4b94090 641 }
642 else {
643 print $fh <<'EOF';
644package DBIXCSL_Test::Schema;
645
646use strict;
647use warnings;
648
649use base 'DBIx::Class::Schema';
650
651__PACKAGE__->load_namespaces;
652
653
654# Created by DBIx::Class::Schema::Loader v0.04006 @ 2010-01-12 16:04:12
655# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:d3wRVsHBNisyhxeaWJZcZQ
656
657
658# You can replace this text with custom content, and it will be preserved on
659# regeneration
6601;
661EOF
662 }
30a4c064 663}
664
dbe9e0f7 665sub run_v4_tests {
666 my $res = shift;
667 my $schema = $res->{schema};
668
669 is_deeply [ @{ $res->{monikers} }{qw/foos bar bazs quuxs/} ],
670 [qw/Foos Bar Bazs Quuxs/],
671 'correct monikers in 0.04006 mode';
672
673 isa_ok ((my $bar = eval { $schema->resultset('Bar')->find(1) }),
674 $res->{classes}{bar},
675 'found a bar');
676
677 isa_ok eval { $bar->foo_id }, $res->{classes}{foos},
678 'correct rel name in 0.04006 mode';
679
680 ok my $baz = eval { $schema->resultset('Bazs')->find(1) };
681
682 isa_ok eval { $baz->quux }, 'DBIx::Class::ResultSet',
683 'correct rel type and name for UNIQUE FK in 0.04006 mode';
684}
685
686sub run_v5_tests {
687 my $res = shift;
688 my $schema = $res->{schema};
689
690 is_deeply [ @{ $res->{monikers} }{qw/foos bar bazs quuxs/} ],
691 [qw/Foo Bar Baz Quux/],
692 'correct monikers in current mode';
693
694 ok my $bar = eval { $schema->resultset('Bar')->find(1) };
695
696 isa_ok eval { $bar->foo }, $res->{classes}{foos},
697 'correct rel name in current mode';
698
699 ok my $baz = eval { $schema->resultset('Baz')->find(1) };
700
701 isa_ok eval { $baz->quux }, $res->{classes}{quuxs},
702 'correct rel type and name for UNIQUE FK in current mode';
703}