Commit | Line | Data |
35678f0b |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | |
5 | use lib qw(t/lib); |
8d6b1478 |
6 | use DBICTest; |
35678f0b |
7 | |
b234e9d9 |
8 | my $exp_warn = qr/The many-to-many relationship 'bars' is trying to create/; |
d81b2771 |
9 | |
35678f0b |
10 | { |
8273e845 |
11 | my @w; |
b234e9d9 |
12 | local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; |
d81b2771 |
13 | my $code = gen_code ( suffix => 1 ); |
eed5492f |
14 | |
15 | local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK}; |
d81b2771 |
16 | eval "$code"; |
52cf2a38 |
17 | ok (! $@, 'Eval code without warnings suppression') |
18 | || diag $@; |
d81b2771 |
19 | |
b7d1831a |
20 | ok (@w, "Warning triggered without DBIC_OVERWRITE_HELPER_METHODS_OK"); |
35678f0b |
21 | } |
22 | |
23 | { |
8273e845 |
24 | my @w; |
b234e9d9 |
25 | local $SIG{__WARN__} = sub { $_[0] =~ $exp_warn ? push @w, $_[0] : warn $_[0] }; |
d81b2771 |
26 | |
b234e9d9 |
27 | my $code = gen_code ( suffix => 2 ); |
28 | |
b7d1831a |
29 | local $ENV{DBIC_OVERWRITE_HELPER_METHODS_OK} = 1; |
d81b2771 |
30 | eval "$code"; |
52cf2a38 |
31 | ok (! $@, 'Eval code with warnings suppression') |
32 | || diag $@; |
d81b2771 |
33 | |
b7d1831a |
34 | ok (! @w, "No warning triggered with DBIC_OVERWRITE_HELPER_METHODS_OK"); |
35678f0b |
35 | } |
36 | |
d81b2771 |
37 | sub gen_code { |
38 | |
39 | my $args = { @_ }; |
40 | my $suffix = $args->{suffix}; |
d81b2771 |
41 | |
42 | return <<EOF; |
35678f0b |
43 | use strict; |
44 | use warnings; |
45 | |
46 | { |
47 | package # |
d81b2771 |
48 | DBICTest::Schema::Foo${suffix}; |
35678f0b |
49 | use base 'DBIx::Class::Core'; |
52cf2a38 |
50 | |
35678f0b |
51 | __PACKAGE__->table('foo'); |
52 | __PACKAGE__->add_columns( |
53 | 'fooid' => { |
54 | data_type => 'integer', |
55 | is_auto_increment => 1, |
56 | }, |
57 | ); |
58 | __PACKAGE__->set_primary_key('fooid'); |
59 | |
60 | |
d81b2771 |
61 | __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'bar'); |
35678f0b |
62 | __PACKAGE__->many_to_many( foos => foo_to_bar => 'bar' ); |
35678f0b |
63 | } |
64 | { |
65 | package # |
d81b2771 |
66 | DBICTest::Schema::FooToBar${suffix}; |
35678f0b |
67 | |
68 | use base 'DBIx::Class::Core'; |
69 | __PACKAGE__->table('foo_to_bar'); |
70 | __PACKAGE__->add_columns( |
71 | 'foo' => { |
72 | data_type => 'integer', |
73 | }, |
74 | 'bar' => { |
75 | data_type => 'integer', |
76 | }, |
77 | ); |
d81b2771 |
78 | __PACKAGE__->belongs_to('foo' => 'DBICTest::Schema::Foo${suffix}'); |
79 | __PACKAGE__->belongs_to('bar' => 'DBICTest::Schema::Foo${suffix}'); |
35678f0b |
80 | } |
81 | { |
82 | package # |
d81b2771 |
83 | DBICTest::Schema::Bar${suffix}; |
84 | |
35678f0b |
85 | use base 'DBIx::Class::Core'; |
52cf2a38 |
86 | |
35678f0b |
87 | __PACKAGE__->table('bar'); |
88 | __PACKAGE__->add_columns( |
89 | 'barid' => { |
90 | data_type => 'integer', |
91 | is_auto_increment => 1, |
92 | }, |
93 | ); |
94 | |
35678f0b |
95 | __PACKAGE__->set_primary_key('barid'); |
d81b2771 |
96 | __PACKAGE__->has_many('foo_to_bar' => 'DBICTest::Schema::FooToBar${suffix}' => 'foo'); |
97 | |
35678f0b |
98 | __PACKAGE__->many_to_many( bars => foo_to_bar => 'foo' ); |
99 | |
100 | sub add_to_bars {} |
101 | } |
102 | EOF |
d81b2771 |
103 | |
35678f0b |
104 | } |
052a832c |
105 | |
106 | done_testing; |