App-Dochazka-Common
view release on metacpan or search on metacpan
lib/App/Dochazka/Common/Model/Component.pm view on Meta::CPAN
# POSSIBILITY OF SUCH DAMAGE.
# *************************************************************************
package App::Dochazka::Common::Model::Component;
use 5.012;
use strict;
use warnings;
use App::Dochazka::Common::Model;
use constant ATTRS => qw( cid path source acl validations );
BEGIN {
App::Dochazka::Common::Model::boilerplate( __PACKAGE__, ATTRS );
}
1;
t/model/component.t view on Meta::CPAN
use Test::More;
note( 'spawn badness' );
like( exception { App::Dochazka::Common::Model::Component->spawn( 'bogus' ); },
qr/Odd number of parameters/ );
like( exception { App::Dochazka::Common::Model::Component->spawn( 'bogus' => 1 ); },
qr/not listed in the validation options: bogus/ );
note( 'spawn goodness' );
my $object = App::Dochazka::Common::Model::Component->spawn(
cid => 14,
path => 'path/to/bubba/component',
source => 'Bunchofcharacters',
acl => 'admin',
);
is( ref $object, 'App::Dochazka::Common::Model::Component' );
is( $object->cid, 14 );
is( $object->path, 'path/to/bubba/component' );
is( $object->source, 'Bunchofcharacters' );
is( $object->acl, 'admin' );
note( 'reset badness' );
like( exception { $object->reset( 'bogus' ); },
qr/Odd number of parameters/ );
like( exception { $object->reset( 'bogus' => 1 ); },
qr/not listed in the validation options: bogus/ );
note( 'reset goodness' );
my %props = (
cid => 55,
path => 'prd',
source => 'dont wanna live like a a refugee',
acl => 'inactive',
validations => {},
);
$object->reset( %props );
my $obj2 = App::Dochazka::Common::Model::Component->spawn( %props );
is( ref $object, 'App::Dochazka::Common::Model::Component' );
is( ref $obj2, 'App::Dochazka::Common::Model::Component' );
is_deeply( $object, $obj2 );
map { is( $object->{$_}, $props{$_} ); } keys( %props );
is( $object->cid, $object->{'cid'} );
is( $object->path, $object->{'path'} );
is( $object->source, $object->{'source'} );
is( $object->acl, $object->{'acl'} );
is( $object->validations, $object->{'validations'} );
note( 'TO_JSON' );
my $u_obj = $object->TO_JSON;
is( ref $u_obj, 'HASH' );
is_deeply( $u_obj, {
'cid' => 55,
'path' => 'prd',
'source' => 'dont wanna live like a a refugee',
'acl' => 'inactive',
'validations' => {},
});
note( 'clone, compare' );
$obj2 = $object->clone;
isnt( $object, $obj2 );
is_deeply( $object, $obj2 );
ok( $object->compare( $obj2 ) );
$obj2->cid( 27 );
ok( ! $object->compare( $obj2 ) );
note( 'accessors already tested above' );
done_testing;
t/model/reset.t view on Meta::CPAN
# Include _all_ parameters for each class
my %props_dispatch = (
'Activity' => {
aid => undef,
code => 'BAZZED_BAR',
long_desc => 'not interesting',
remark => 'interesting',
disabled => 0,
},
'Component' => {
cid => undef,
path => 'elephant/trunk.mi',
source => 'head',
acl => 'passerby',
validations => {},
},
'Employee' => {
eid => undef,
sec_id => undef,
nick => 'missreset',
fullname => 'Miss Reset Machine',
( run in 0.691 second using v1.01-cache-2.11-cpan-de7293f3b23 )