_verifyRequestTypeId: Implementation & unit tests.
Straightforward helper method.
This commit is contained in:
parent
1c33f4cbba
commit
9dcea735f4
2 changed files with 48 additions and 1 deletions
|
@ -548,6 +548,37 @@ sub _verifyId($$) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=item _verifyRequestTypeId()
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
=over
|
||||||
|
|
||||||
|
=item $self: current object.
|
||||||
|
|
||||||
|
=item $requestTypeId: A scalar numeric argument that is the request type id to lookup
|
||||||
|
|
||||||
|
|
||||||
|
=back
|
||||||
|
|
||||||
|
Returns: scalar boolean, which is true iff. the $requestTypeId is valid and
|
||||||
|
already in the supporter database's request_type table.
|
||||||
|
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
|
||||||
|
sub _verifyRequestTypeId($$) {
|
||||||
|
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 = " .
|
||||||
|
$self->dbh->quote($requestTypeId, 'SQL_INTEGER'), 'id');
|
||||||
|
return (defined $val and defined $val->{$requestTypeId});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
=item _getOrCreateRequestType
|
=item _getOrCreateRequestType
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Test::More tests => 110;
|
use Test::More tests => 124;
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
|
|
||||||
use Scalar::Util qw(looks_like_number reftype);
|
use Scalar::Util qw(looks_like_number reftype);
|
||||||
|
@ -423,6 +423,22 @@ 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); }
|
||||||
|
"_verifyRequestTypeId: dies for undefined requestTypeId";
|
||||||
|
|
||||||
|
dies_ok { $tempSP->_verifyRequestTypeId("NoStringsPlease"); }
|
||||||
|
"_verifyRequestTypeId: dies for a string requestTypeId";
|
||||||
|
|
||||||
|
ok( (not $tempSP->_verifyRequestTypeId(0)), "_verifyRequestTypeId: 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( ($tempSP->_verifyRequestTypeId($rr)),
|
||||||
|
"_verifyRequestTypeId: returns true for id known to be in database");
|
||||||
|
|
||||||
|
|
||||||
=item _getOrCreateRequestConfiguration
|
=item _getOrCreateRequestConfiguration
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
Loading…
Reference in a new issue