Allow CDBI objects to be accessed like hashes as people tend to do for
[dbsrgits/DBIx-Class.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=> 6);
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 warnings_like {
23     is $waves->{title}, $waves->Title, "columns can be accessed as hashes";
24 } qr{^Column 'title' of 'Film/$waves' was accessed as a hash at .*$};
25
26 $waves->Rating("G");
27
28 warnings_like {
29     is $waves->{rating}, "G", "updating via the accessor updates the hash";
30 } qr{^Column 'rating' of 'Film/$waves' was accessed as a hash .*$};
31
32 $waves->{rating} = "PG";
33
34 warnings_like {
35     $waves->update;
36 } qr{^Column 'rating' of 'Film/$waves' was updated as a hash .*$};
37
38 my @films = Film->search( Rating => "PG", Title => "Breaking the Waves" );
39 is @films, 1, "column updated as hash was saved";