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