refactor code needing version
[dbsrgits/DBIx-Class.git] / t / 86might_have.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Test::Warn;
6 use lib qw(t/lib);
7 use DBICTest;
8
9 my $schema = DBICTest->init_schema();
10
11 my $cd = $schema->resultset("CD")->find(1);
12 $cd->title('test');
13
14 $schema->is_executed_querycount( sub {
15   $cd->update;
16 }, {
17   BEGIN => 1,
18   UPDATE => 1,
19   COMMIT => 1,
20 }, 'liner_notes (might_have) not prefetched - do not load liner_notes on update' );
21
22 my $cd2 = $schema->resultset("CD")->find(2, {prefetch => 'liner_notes'});
23 $cd2->title('test2');
24
25 $schema->is_executed_querycount( sub {
26   $cd2->update;
27 }, {
28   BEGIN => 1,
29   UPDATE => 1,
30   COMMIT => 1,
31 }, 'liner_notes (might_have) prefetched - do not load liner_notes on update');
32
33 warning_like {
34   local $ENV{DBIC_DONT_VALIDATE_RELS};
35
36   DBICTest::Schema::Bookmark->might_have(
37     linky => 'DBICTest::Schema::Link',
38     { "foreign.id" => "self.link" },
39   );
40 }
41   qr{"might_have/has_one" must not be on columns with is_nullable set to true},
42   'might_have should warn if the self.id column is nullable';
43
44 {
45   local $ENV{DBIC_DONT_VALIDATE_RELS} = 1;
46   warning_is {
47     DBICTest::Schema::Bookmark->might_have(
48       slinky => 'DBICTest::Schema::Link',
49       { "foreign.id" => "self.link" },
50     );
51   }
52   undef,
53   'Setting DBIC_DONT_VALIDATE_RELS suppresses nullable relation warnings';
54 }
55
56 done_testing();