Update the Crud serialize test for Moose.
This commit is contained in:
parent
753cc9b75c
commit
5903cc5524
2 changed files with 30 additions and 19 deletions
|
|
@ -36,7 +36,8 @@ WebGUI::Test->addToCleanup(sub {
|
|||
WebGUI::Serialize->crud_dropTable($session);
|
||||
});
|
||||
|
||||
my $cereal = WebGUI::Serialize->create($session);
|
||||
my $cereal = WebGUI::Serialize->new($session);
|
||||
$cereal->write;
|
||||
isa_ok($cereal, 'WebGUI::Serialize');
|
||||
cmp_deeply(
|
||||
$cereal->get,
|
||||
|
|
@ -99,6 +100,7 @@ cmp_deeply(
|
|||
'new: deserialized data correctly'
|
||||
);
|
||||
|
||||
use Data::Dumper;
|
||||
my $objData = $cereal->get('jsonField');
|
||||
$objData->[0]->{fiber} = 0;
|
||||
cmp_deeply(
|
||||
|
|
@ -111,6 +113,6 @@ cmp_deeply(
|
|||
},
|
||||
],
|
||||
'get: returns safe references'
|
||||
);
|
||||
) or diag Dumper($cereal->jsonField);
|
||||
|
||||
#vim:ft=perl
|
||||
|
|
|
|||
|
|
@ -1,6 +1,28 @@
|
|||
package WebGUI::Serialize;
|
||||
|
||||
use base qw/WebGUI::Crud/;
|
||||
use Moose;
|
||||
use WebGUI::Definition::Crud;
|
||||
extends qw/WebGUI::Crud/;
|
||||
|
||||
define tableName => 'crudSerialize';
|
||||
define tableKey => 'serializeId';
|
||||
has serializeId => (
|
||||
required => 1,
|
||||
is => 'ro',
|
||||
);
|
||||
property someName => (
|
||||
label => 'someName',
|
||||
fieldType => 'text',
|
||||
default => 'someName',
|
||||
);
|
||||
property jsonField => (
|
||||
label => 'jsonField',
|
||||
fieldType => 'textarea',
|
||||
default => sub { return []; },
|
||||
isa => 'WebGUI::Type::JSONArray',
|
||||
coerce => 1,
|
||||
traits => ['Array', 'WebGUI::Definition::Meta::Property::Serialize',],
|
||||
);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -33,22 +55,9 @@ JSON blob text field.
|
|||
=cut
|
||||
|
||||
sub crud_definition {
|
||||
my ($class, $session) = @_;
|
||||
my $definition = $class->SUPER::crud_definition($session);
|
||||
$definition->{tableName} = 'crudSerialize';
|
||||
$definition->{tableKey} = 'serializeId';
|
||||
$definition->{sequenceKey} = '';
|
||||
my $properties = $definition->{properties};
|
||||
$properties->{someName} = {
|
||||
fieldType => 'text',
|
||||
defaultValue => 'someName',
|
||||
};
|
||||
$properties->{jsonField} = {
|
||||
fieldType => 'textarea',
|
||||
defaultValue => [],
|
||||
serialize => 1,
|
||||
};
|
||||
return $definition;
|
||||
my ($class, $session) = @_;
|
||||
my $definition = $class->SUPER::crud_definition($session);
|
||||
return $definition;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue