_verifyRequestTypeId =>_lookupRequestTypeById

I found need to have _verifyRequestTypeId() actually return the
request_type in a reimplementation of getRequest() that I'm working on,
so I've made this change.  Some tests are failing because of the use of
_verifyRequestTypeId().  Next commit will address that.
This commit is contained in:
Bradley M. Kuhn 2015-12-30 03:55:28 -08:00
parent b03a469338
commit 10030b3488
2 changed files with 19 additions and 15 deletions

View file

@ -910,7 +910,7 @@ sub _verifyId($$) {
} }
=item _verifyRequestTypeId() =item _lookupRequestTypeById()
Parameters: Parameters:
@ -923,22 +923,26 @@ Parameters:
=back =back
Returns: scalar boolean, which is true iff. the $requestTypeId is valid and Returns: scalar, which is the request_type found iff. the C<$requestTypeId> is valid and
already in the supporter database's request_type table. already in the supporter database's request_type table.
Die if the C<$requestTypeId> isn't a number.
=cut =cut
sub _verifyRequestTypeId($$) { sub _lookupRequestTypeById($$) {
my($self, $requestTypeId) = @_; my($self, $requestTypeId) = @_;
die "_verifyRequestTypeId() called with a non-numeric id" unless defined $requestTypeId and looks_like_number($requestTypeId); die "_verifyRequestTypeId() called with a non-numeric id" unless defined $requestTypeId and looks_like_number($requestTypeId);
my $val = $self->dbh()->selectall_hashref("SELECT id FROM request_type WHERE id = " . my $val = $self->dbh()->selectall_hashref("SELECT id, type FROM request_type WHERE id = " .
$self->dbh->quote($requestTypeId, 'SQL_INTEGER'), 'id'); $self->dbh->quote($requestTypeId, 'SQL_INTEGER'), 'id');
return (defined $val and defined $val->{$requestTypeId}); if (defined $val and defined $val->{$requestTypeId}) {
return $val->{$requestTypeId}{type};
} else {
return undef;
}
} }
=item _getOrCreateRequestType =item _getOrCreateRequestType

View file

@ -532,20 +532,20 @@ lives_ok { $tempSP->_getOrCreateRequestType(\%hh); }
is_deeply(\%hh, { requestTypeId => $rr }, is_deeply(\%hh, { requestTypeId => $rr },
"_getOrCreateRequestType: deletes requestType if both are provided."); "_getOrCreateRequestType: deletes requestType if both are provided.");
dies_ok { $tempSP->_verifyRequestTypeId(undef); } dies_ok { $tempSP->_lookupRequestTypeById(undef); }
"_verifyRequestTypeId: dies for undefined requestTypeId"; "_lookupRequestTypeById: dies for undefined requestTypeId";
dies_ok { $tempSP->_verifyRequestTypeId("NoStringsPlease"); } dies_ok { $tempSP->_lookupRequestTypeById("NoStringsPlease"); }
"_verifyRequestTypeId: dies for a string requestTypeId"; "_lookupRequestTypeById: dies for a string requestTypeId";
ok( (not $tempSP->_verifyRequestTypeId(0)), "_verifyRequestTypeId: returns false for id lookup for 0"); ok( (not $tempSP->_lookupRequestTypeById(0)), "_lookupRequestTypeById: returns false for id lookup for 0");
# Assumption here: that id number one more than the last added would never be in db. # Assumption here: that id number one more than the last added would never be in db.
ok( (not $tempSP->_verifyRequestTypeId($rr + 1)), ok( (not $tempSP->_lookupRequestTypeById($rr + 1)),
"_verifyRequestTypeId: returns false for id one greater than last added"); "_lookupRequestTypeById: returns false for id one greater than last added");
ok( ($tempSP->_verifyRequestTypeId($rr)), is($tempSP->_lookupRequestTypeById($rr), "test-request",
"_verifyRequestTypeId: returns true for id known to be in database"); "_lookupRequestTypeById: returns proper result for id known to be in database");
=item _getOrCreateRequestConfiguration =item _getOrCreateRequestConfiguration