X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi-t%2F04-lazy.t;h=7b5a24ce05a211ccf07e0aeffdc2ca42e75f6db8;hb=331a564;hp=15e1e1ce35b0fcbd3e5403b34f6969c6f28084ca;hpb=b57940c54326b7a819d874d0e7b38bf60765d2e9;p=dbsrgits%2FDBIx-Class.git diff --git a/t/cdbi-t/04-lazy.t b/t/cdbi-t/04-lazy.t index 15e1e1c..7b5a24c 100644 --- a/t/cdbi-t/04-lazy.t +++ b/t/cdbi-t/04-lazy.t @@ -1,6 +1,8 @@ +#!/usr/bin/perl -w + use strict; use Test::More; - +use Test::Warn; #---------------------------------------------------------------------- # Test lazy loading @@ -13,7 +15,7 @@ BEGIN { next; } eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 30); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 36); } INIT { @@ -80,7 +82,11 @@ eval { # Multiple false columns ok($@, $@); -# Test that update() throws out columns that changed +warning_is { + Lazy->columns( TEMP => qw(that) ); +} "Declaring column that as TEMP but it already exists"; + +# Test that create() and update() throws out columns that changed { my $l = Lazy->create({ this => 99, @@ -88,7 +94,15 @@ ok($@, $@); oop => 3, opop => 4, }); - + + ok $l->db_Main->do(qq{ + UPDATE @{[ $l->table ]} + SET oop = ? + WHERE this = ? + }, undef, 87, $l->this); + + is $l->oop, 87; + $l->oop(32); $l->update; @@ -105,10 +119,11 @@ ok($@, $@); # Now again for inflated values -{ +SKIP: { + skip "Requires Date::Simple", 5 unless eval "use Date::Simple; 1; "; Lazy->has_a( orp => 'Date::Simple', - inflate => sub { Date::Simple->new(shift . '-01-01') }, + inflate => sub { Date::Simple->new($_[0] . '-01-01') }, deflate => 'format' ); @@ -117,7 +132,15 @@ ok($@, $@); that => 2, orp => 1998, }); + + ok $l->db_Main->do(qq{ + UPDATE @{[ $l->table ]} + SET orp = ? + WHERE this = ? + }, undef, 1987, $l->this); + is $l->orp, '1987-01-01'; + $l->orp(2007); is $l->orp, '2007-01-01'; # make sure it's inflated $l->update; @@ -132,3 +155,30 @@ ok($@, $@); $l->delete; } + + +# Test that a deleted object works +{ + Lazy->search()->delete_all; + my $l = Lazy->create({ + this => 99, + that => 2, + oop => 3, + opop => 4, + }); + + # Delete the object without it knowing. + Lazy->db_Main->do(qq[ + DELETE + FROM @{[ Lazy->table ]} + WHERE this = 99 + ]); + + $l->eep; + + # The problem was when an object had an inflated object + # loaded. _flesh() would set _column_data to undef and + # get_column() would think nothing was there. + # I'm too lazy to set up the proper inflation test. + ok !exists $l->{_column_data}{orp}; +}