diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 6cd290c..608cbcc 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -910,7 +910,7 @@ sub _verifyId($$) { } -=item _verifyRequestTypeId() +=item _lookupRequestTypeById() Parameters: @@ -923,22 +923,26 @@ Parameters: =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. +Die if the C<$requestTypeId> isn't a number. =cut -sub _verifyRequestTypeId($$) { +sub _lookupRequestTypeById($$) { my($self, $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'); - return (defined $val and defined $val->{$requestTypeId}); - + if (defined $val and defined $val->{$requestTypeId}) { + return $val->{$requestTypeId}{type}; + } else { + return undef; + } } =item _getOrCreateRequestType diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 2694e86..7b2dd50 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -532,20 +532,20 @@ lives_ok { $tempSP->_getOrCreateRequestType(\%hh); } is_deeply(\%hh, { requestTypeId => $rr }, "_getOrCreateRequestType: deletes requestType if both are provided."); -dies_ok { $tempSP->_verifyRequestTypeId(undef); } - "_verifyRequestTypeId: dies for undefined requestTypeId"; +dies_ok { $tempSP->_lookupRequestTypeById(undef); } + "_lookupRequestTypeById: dies for undefined requestTypeId"; -dies_ok { $tempSP->_verifyRequestTypeId("NoStringsPlease"); } - "_verifyRequestTypeId: dies for a string requestTypeId"; +dies_ok { $tempSP->_lookupRequestTypeById("NoStringsPlease"); } + "_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. -ok( (not $tempSP->_verifyRequestTypeId($rr + 1)), - "_verifyRequestTypeId: returns false for id one greater than last added"); +ok( (not $tempSP->_lookupRequestTypeById($rr + 1)), + "_lookupRequestTypeById: returns false for id one greater than last added"); -ok( ($tempSP->_verifyRequestTypeId($rr)), - "_verifyRequestTypeId: returns true for id known to be in database"); +is($tempSP->_lookupRequestTypeById($rr), "test-request", + "_lookupRequestTypeById: returns proper result for id known to be in database"); =item _getOrCreateRequestConfiguration