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