Fix the POD coverage test.
[dbsrgits/DBIx-Class-Historic.git] / t / cdbi-t / columns_as_hashes.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More;
5 use Test::Warn;
6
7 BEGIN {
8   eval "use DBIx::Class::CDBICompat;";
9   plan $@ ? (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@")
10           : (tests=> 9);
11 }
12
13 use lib 't/testlib';
14 use Film;
15
16 my $waves = Film->insert({
17     Title     => "Breaking the Waves",
18     Director  => 'Lars von Trier',
19     Rating    => 'R'
20 });
21
22 local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 1;
23
24 warnings_like {
25     my $rating = $waves->{rating};
26     $waves->Rating("PG");
27     is $rating, "R", 'evaluation of column value is not deferred';
28 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at \Q$0};
29
30 warnings_like {
31     is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
32 } qr{^Column 'title' of 'Film/$waves' was fetched as a hash at\b};
33
34 $waves->Rating("G");
35
36 warnings_like {
37     is $waves->{rating}, "G", "updating via the accessor updates the hash";
38 } qr{^Column 'rating' of 'Film/$waves' was fetched as a hash at\b};
39
40
41 warnings_like {
42     $waves->{rating} = "PG";
43 } qr{^Column 'rating' of 'Film/$waves' was stored as a hash at\b};
44
45 $waves->update;
46 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
47 is @films, 1, "column updated as hash was saved";
48
49
50 warning_is {
51     local $ENV{DBIC_CDBICOMPAT_HASH_WARN} = 0;
52     $waves->{rating}
53 } '', 'DBIC_CDBICOMPAT_HASH_WARN controls warnings';