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