Tax: add the delete method, with tests

This commit is contained in:
Colin Kuskie 2008-02-16 05:36:25 +00:00
parent 19591d37d4
commit 645c21bc3b
2 changed files with 58 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package WebGUI::Shop::Tax;
use strict;
use Class::InsideOut qw{ :std };
use Carp qw(croak);
=head1 NAME
@ -67,6 +68,33 @@ sub add {
#-------------------------------------------------------------------
=head2 delete ( [$params] )
Deletes data from the tax table by taxId.
=head3 $params
A hashref containing the taxId of the data to delete from the table.
=head4 taxId
The taxId of the data to delete from the table.
=cut
sub delete {
my $self = shift;
my $params = shift;
croak "Must pass in a hashref"
unless ref($params) eq 'HASH';
croak "Hash ref must contain a taxId key with a defined value"
unless exists($params->{taxId}) and defined $params->{taxId};
$self->session->db->write('delete from tax where taxId=?', [$params->{taxId}]);
return;
}
#-------------------------------------------------------------------
=head2 getItems ( )
Returns a WebGUI::SQL::Result object for accessing all of the data in the tax table. This

View file

@ -28,7 +28,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 11;
my $tests = 17;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -119,6 +119,35 @@ is($taxIterator->rows, 2, 'add did not add another row since it would be a dupli
##city rate: 0.5%
##Wisconsin rate 5.0%
#######################################################################
#
# delete
#
#######################################################################
eval{$taxer->delete()};
like($@, qr{Must pass in a hashref},
'delete: error handling for missing hashref');
eval{$taxer->delete({})};
like($@, qr{Hash ref must contain a taxId key with a defined value},
'delete: error handling for missing key in hashref');
eval{$taxer->delete({ taxId => undef })};
like($@, qr{Hash ref must contain a taxId key with a defined value},
'delete: error handling for an undefined taxId value');
$taxer->delete({ taxId => $oregonTaxId });
$taxIterator = $taxer->getItems;
is($taxIterator->rows, 1, 'One row was deleted from the tax table');
$taxer->delete({ taxId => $session->id->generate });
$taxIterator = $taxer->getItems;
is($taxIterator->rows, 1, 'No rows were deleted from the table since the requested id does not exist');
is($taxIterator->hashRef->{taxId}, $wisconsinTaxId, 'The correct tax information was deleted');
}