Valiadate inputs to create.

This commit is contained in:
Colin Kuskie 2008-02-22 00:15:44 +00:00
parent 6cc51fa176
commit 3f4aed78d2
2 changed files with 23 additions and 7 deletions

View file

@ -32,7 +32,6 @@ These subroutines are available from this package:
readonly session => my %session; readonly session => my %session;
readonly className => my %className; readonly className => my %className;
readonly shipperId => my %shipperId; readonly shipperId => my %shipperId;
readonly label => my %label;
readonly options => my %options; readonly options => my %options;
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -46,7 +45,7 @@ to do calculations.
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 create ( $session, $properties ) =head2 create ( $session, $options )
Constructor for new WebGUI::Shop::ShipperDriver objects. Returns a WebGUI::Shop::ShipperDriver object. Constructor for new WebGUI::Shop::ShipperDriver objects. Returns a WebGUI::Shop::ShipperDriver object.
To access driver objects that have already been configured, use C<new>. To access driver objects that have already been configured, use C<new>.
@ -55,7 +54,7 @@ To access driver objects that have already been configured, use C<new>.
A WebGUI::Session object. A WebGUI::Session object.
=head4 $properties =head4 $options
A list of properties to assign to this ShipperDriver. See C<definition> for details. A list of properties to assign to this ShipperDriver. See C<definition> for details.
@ -64,10 +63,21 @@ A list of properties to assign to this ShipperDriver. See C<definition> for det
sub create { sub create {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $options = shift;
croak "You must pass a hashref of options to create a new ShipDriver object"
unless defined($options) and ref $options eq 'HASH' and scalar keys %{ $options };
my $self = {}; my $self = {};
bless $self, $class; bless $self, $class;
register $self; register $self;
$session{ id $self } = $session;
my $shipperId = $session->id->generate;
my $id = id $self;
$session{ $id } = $session;
$shipperId{ $id } = $shipperId;
$options{ $id } = $options;
$className{ $id } = __PACKAGE__;
return $self; return $self;
} }

View file

@ -28,7 +28,7 @@ my $session = WebGUI::Test->session;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# Tests # Tests
my $tests = 3; my $tests = 4;
plan tests => 1 + $tests; plan tests => 1 + $tests;
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -96,8 +96,14 @@ cmp_deeply(
# #
####################################################################### #######################################################################
#my $driver = WebGUI::Shop::ShipDriver->create($session); my $driver;
#
eval { $driver = WebGUI::Shop::ShipDriver->create($session); };
like ($@, qr/You must pass a hashref of options to create a new ShipDriver object/, 'create croaks without a hashref of options');
eval { $driver = WebGUI::Shop::ShipDriver->create($session, {}); };
like ($@, qr/You must pass a hashref of options to create a new ShipDriver object/, 'create croaks with an empty hashref of options');
#isa_ok($driver, 'WebGUI::Shop::ShipDriver'); #isa_ok($driver, 'WebGUI::Shop::ShipDriver');
# #
#isa_ok($driver->session, 'WebGUI::Session', 'session method returns a session object'); #isa_ok($driver->session, 'WebGUI::Session', 'session method returns a session object');