Basic implementation of addRequestConfigurations
Adjusted one test slightly: there was a missing argument. Also, corrected test count. While implementing, I realized a failure mode that forces a rollback: duplication on the input list of configurations. Tests are now needed for that.
This commit is contained in:
parent
63af394ca6
commit
4331093cee
3 changed files with 19 additions and 5 deletions
|
@ -300,7 +300,8 @@ Arguments:
|
||||||
=item descriptionListRef
|
=item descriptionListRef
|
||||||
|
|
||||||
A list reference to the list of configuration descriptions to associate
|
A list reference to the list of configuration descriptions to associate
|
||||||
with this requestId.
|
with this requestId. Duplicates aren't permitted in this list, and
|
||||||
|
die()'s if duplicates exist.
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
@ -323,7 +324,17 @@ sub addRequestConfigurations($$$) {
|
||||||
unless defined $requestType;
|
unless defined $requestType;
|
||||||
|
|
||||||
my %descriptions;
|
my %descriptions;
|
||||||
|
my $sth = $self->dbh->prepare("INSERT INTO request_configuration(request_type_id, description) " .
|
||||||
|
"VALUES(?, ?)");
|
||||||
|
foreach my $description (@{$descriptionListRef}) {
|
||||||
|
if (defined $descriptions{$description}) {
|
||||||
|
$self->dbh->rollback();
|
||||||
|
die "addRequestConfigurations: attempt to create duplicate request_configuration \"$description\" for requestType, \"$requestType\"";
|
||||||
|
}
|
||||||
|
$sth->execute($requestId, $description);
|
||||||
|
$descriptions{$description} = $self->dbh->last_insert_id("","","","");
|
||||||
|
}
|
||||||
|
$sth->finish();
|
||||||
$self->dbh->commit();
|
$self->dbh->commit();
|
||||||
return { $requestId => \%descriptions };
|
return { $requestId => \%descriptions };
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Test::More tests => 38;
|
use Test::More tests => 49;
|
||||||
use Test::Exception;
|
use Test::Exception;
|
||||||
|
|
||||||
use Scalar::Util qw(looks_like_number);
|
use Scalar::Util qw(looks_like_number);
|
||||||
|
@ -176,13 +176,13 @@ my @sizeList = qw/LadiesS LadiesM LadiesL LadiesXL MenS MenM MenL MenXL Men2XL/;
|
||||||
|
|
||||||
my $tShirt0Data;
|
my $tShirt0Data;
|
||||||
|
|
||||||
lives_ok { $tShirt0Data = $sp->addRequestConfigurations('t-shirt-0') }
|
lives_ok { $tShirt0Data = $sp->addRequestConfigurations('t-shirt-0', \@sizeList) }
|
||||||
"addRequestConfigurations: existing requestType with configuration runs.";
|
"addRequestConfigurations: existing requestType with configuration runs.";
|
||||||
|
|
||||||
is( keys %{$tShirt0Data}, ($tShirt0RequestTypeId),
|
is( keys %{$tShirt0Data}, ($tShirt0RequestTypeId),
|
||||||
"addRequestConfigurations: reuses same requestTypeId on add of configurations");
|
"addRequestConfigurations: reuses same requestTypeId on add of configurations");
|
||||||
|
|
||||||
my $cnt;
|
my $cnt = 0;
|
||||||
foreach my $size (@sizeList) {
|
foreach my $size (@sizeList) {
|
||||||
ok( (defined $tShirt0Data->{$tShirt0RequestTypeId}{$size} and
|
ok( (defined $tShirt0Data->{$tShirt0RequestTypeId}{$size} and
|
||||||
looks_like_number($tShirt0Data->{$tShirt0RequestTypeId}{$size}) and
|
looks_like_number($tShirt0Data->{$tShirt0RequestTypeId}{$size}) and
|
||||||
|
|
|
@ -29,6 +29,9 @@ CREATE TABLE "request_configuration" (
|
||||||
"description" varchar(100) NOT NULL
|
"description" varchar(100) NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX request_configuration__single_description
|
||||||
|
ON request_configuration(request_type_id, description);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS "fulfillment";
|
DROP TABLE IF EXISTS "fulfillment";
|
||||||
|
|
||||||
CREATE TABLE "fulfillment" (
|
CREATE TABLE "fulfillment" (
|
||||||
|
|
Loading…
Reference in a new issue