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