X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F68inflate.t;h=cc444a094e167dfabf46baf01876c0c67d600b2a;hb=e81a62410d9b030620169dc317c82f87c1e823bf;hp=0ce901cfcc2f381d5f8bd9a1a8f7ffc1301e6130;hpb=d0ed3b556279e0d36813cb941bad1f656ba49f39;p=dbsrgits%2FDBIx-Class.git diff --git a/t/68inflate.t b/t/68inflate.t index 0ce901c..cc444a0 100644 --- a/t/68inflate.t +++ b/t/68inflate.t @@ -11,7 +11,7 @@ my $schema = DBICTest->init_schema(); eval { require DateTime }; plan skip_all => "Need DateTime for inflation tests" if $@; -plan tests => 4; +plan tests => 15; DBICTest::Schema::CD->inflate_column( 'year', { inflate => sub { DateTime->new( year => shift ) }, @@ -28,6 +28,21 @@ is( $cd->year->year, 1997, 'inflated year ok' ); is( $cd->year->month, 1, 'inflated month ok' ); +eval { $cd->year(\'year +1'); }; +ok(!$@, 'updated year using a scalarref'); +$cd->update(); +$cd->discard_changes(); + +is( ref($cd->year), 'DateTime', 'year is still a DateTime, ok' ); + +is( $cd->year->year, 1998, 'updated year, bypassing inflation' ); + +is( $cd->year->month, 1, 'month is still 1' ); + +# get_inflated_column test + +is( ref($cd->get_inflated_column('year')), 'DateTime', 'get_inflated_column produces a DateTime'); + # deflate test my $now = DateTime->now; $cd->year( $now ); @@ -36,3 +51,33 @@ $cd->update; ($cd) = $schema->resultset("CD")->search( year => $now->year ); is( $cd->year->year, $now->year, 'deflate ok' ); +# set_inflated_column test +eval { $cd->set_inflated_column('year', $now) }; +ok(!$@, 'set_inflated_column with DateTime object'); +$cd->update; + +($cd) = $schema->resultset("CD")->search( year => $now->year ); +is( $cd->year->year, $now->year, 'deflate ok' ); + +eval { $cd->set_inflated_column('year', \'year + 1') }; +print STDERR "ERROR: $@" if($@); +ok(!$@, 'set_inflated_column to "year + 1"'); +$cd->update; +$cd->discard_changes(); + +($cd) = $schema->resultset("CD")->search( year => $now->year + 1 ); +is( $cd->year->year, $now->year+1, 'deflate ok' ); + +# store_inflated_column test +eval { $cd->store_inflated_column('year', $now) }; +ok(!$@, 'store_inflated_column with DateTime object'); +$cd->update; + +is( $cd->year->year, $now->year, 'deflate ok' ); + +# eval { $cd->store_inflated_column('year', \'year + 1') }; +# print STDERR "ERROR: $@" if($@); +# ok(!$@, 'store_inflated_column to "year + 1"'); + +# is_deeply( $cd->year, \'year + 1', 'deflate ok' ); +