X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcdbi-t%2F04-lazy.t;h=27e7ab5f9af5ed84d24dc94035c48f8dbff1fb7e;hb=1b32d56ec274e0f7054381c5b630b73f2ce3a699;hp=b9e33708f43d85742c7843b96dd727a03331f92f;hpb=289ba852733fc488dc43cd474f47780f7fa1771e;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/cdbi-t/04-lazy.t b/t/cdbi-t/04-lazy.t index b9e3370..27e7ab5 100644 --- a/t/cdbi-t/04-lazy.t +++ b/t/cdbi-t/04-lazy.t @@ -1,18 +1,21 @@ +#!/usr/bin/perl -w + use strict; use Test::More; - -BEGIN { - eval "use DBIx::Class::CDBICompat;"; - plan $@ ? (skip_all => 'Class::Trigger and DBIx::ContextualFetch required') : (tests=> 24); -} +use Test::Warn; #---------------------------------------------------------------------- # Test lazy loading #---------------------------------------------------------------------- BEGIN { + eval "use DBIx::Class::CDBICompat;"; + if ($@) { + plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required'); + next; + } eval "use DBD::SQLite"; - plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 25); + plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 35); } INIT { @@ -78,3 +81,76 @@ eval { # Multiple false columns }; ok($@, $@); + +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, + that => 2, + 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; + + ok $l->db_Main->do(qq{ + UPDATE @{[ $l->table ]} + SET oop = ? + WHERE this = ? + }, undef, 23, $l->this); + + is $l->oop, 23; + + $l->delete; +} + + +# Now again for inflated values +{ + Lazy->has_a( + orp => 'Date::Simple', + inflate => sub { Date::Simple->new($_[0] . '-01-01') }, + deflate => 'format' + ); + + my $l = Lazy->create({ + this => 89, + 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; + + ok $l->db_Main->do(qq{ + UPDATE @{[ $l->table ]} + SET orp = ? + WHERE this = ? + }, undef, 1942, $l->this); + + is $l->orp, '1942-01-01'; + + $l->delete; +}