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