From b4abac9a404bc2169f6c7b7be70172387c761acb Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 4 Nov 2010 15:11:04 -0700 Subject: [PATCH] Add defaults for lastUpdated, dateCreated. Crud data now has to be manually written to the db. --- lib/WebGUI/Crud.pm | 9 +++++++++ t/Crud.t | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/WebGUI/Crud.pm b/lib/WebGUI/Crud.pm index 3c8a90221..07f6dd37d 100644 --- a/lib/WebGUI/Crud.pm +++ b/lib/WebGUI/Crud.pm @@ -32,12 +32,21 @@ has session => ( has lastUpdated => ( is => 'rw', + lazy => 1, + builder => '_now'; ); has dateCreated => ( is => 'rw', + lazy => 1, + builder => '_now'; ); +sub _now { + my $self = shift; + return WebGUI::DateTime->new($session)->toDatabase; +} + has sequenceNumber => ( is => 'rw', ); diff --git a/t/Crud.t b/t/Crud.t index d6428a2f2..d569a5540 100644 --- a/t/Crud.t +++ b/t/Crud.t @@ -31,7 +31,7 @@ define tableName => 'some_crud_table'; define tableKey => 'id'; has id => ( - is => 'ro', + is => 'ro', ); package main; @@ -81,7 +81,8 @@ is($record2->get('id'),'theshawshankredemption',"custom id works"); $record2->delete; # instanciation -my $record2 = WebGUI::Cruddy->new($session); +$record2 = WebGUI::Cruddy->new($session); +$record2->write; isnt($record1->getId, $record2->getId, "can retrieve unique rows"); my $copyOfRecord2 = WebGUI::Cruddy->new($session, $record2->getId); is($record2->getId, $copyOfRecord2->getId, "can reinstanciate record");