+#!/usr/bin/perl -w
+
use strict;
use Test::More;
-
+use Test::Warn;
#----------------------------------------------------------------------
# Test lazy loading
next;
}
eval "use DBD::SQLite";
- plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 30);
+ plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 35);
}
INIT {
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,
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;
# 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($_[0] . '-01-01') },
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;