Fix typo in t/46relationships_multi_m2m.t
[dbsrgits/DBIx-Class-Schema-Loader.git] / t / 46relationships_multi_m2m.t
CommitLineData
da7342ae 1use strict;
2use warnings;
3use Test::More;
4use lib qw(t/lib);
5use make_dbictest_db_multi_m2m;
6use Devel::Dwarn;
7
8use DBIx::Class::Schema::Loader;
9
10my $schema_counter = 0;
11
12{
13 my $hashmap = schema_with(
14 rel_name_map => {
15 foos_2s => "other_foos",
16 bars_2s => "other_bars",
17 },
18 );
19
20 foreach ([qw(Foo bars)], [qw(Bar foos)]) {
21 my ($source, $rel) = @{$_};
22 my $row = $hashmap->resultset($source)->find(1);
23 foreach my $link ("", "other_") {
24 can_ok $row, "${link}${rel}";
25 }
26 }
27}
28{
29 my $submap = schema_with(
30 rel_name_map => sub {
31 my ($args) = @_;
32 if ($args->{type} eq "many_to_many") {
33 like $args->{link_class},
34 qr/\ADBICTest::Schema::${schema_counter}::Result::FooBar(?:One|Two)\z/,
35 "link_class";
36 like $args->{link_moniker}, qr/\AFooBar(?:One|Two)\z/,
37 "link_moniker";
8c673265 38 like $args->{link_rel_name}, qr/\Afoo_bar_(?:ones|twos)\z/,
da7342ae 39 "link_rel_name";
40
41 return $args->{name}."_".(split /_/, $args->{link_rel_name})[-1];
42 }
43 },
44 );
45 foreach ([qw(Foo bars)], [qw(Bar foos)]) {
46 my ($source, $rel) = @{$_};
47 my $row = $submap->resultset($source)->find(1);
8c673265 48 foreach ([ones => 1], [twos => 2]) {
da7342ae 49 my ($link, $count) = @{$_};
50 my $m2m = "${rel}_${link}";
51 can_ok $row, $m2m;
52 is $row->$m2m->count, $count, "$m2m count";
53 }
54 }
55}
56
57done_testing;
58
59#### generates a new schema with the given opts every time it's called
60sub schema_with {
61 $schema_counter++;
62 DBIx::Class::Schema::Loader::make_schema_at(
63 'DBICTest::Schema::'.$schema_counter,
64 { naming => 'current', @_ },
65 [ $make_dbictest_db_multi_m2m::dsn ],
66 );
67 "DBICTest::Schema::$schema_counter"->clone;
68}