Bug 14697: (QA follow-up) Restore FK on issue_id and adjust tests

This patch reintroduces the FK constraint on issue_id. The tests are
adjusted to reflect the UNIQUE constraint we also added.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomás Cohen Arazi 2019-10-29 17:43:13 -03:00 committed by Martin Renvoize
parent 93143b207f
commit efa8ef9dcb
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F
3 changed files with 40 additions and 10 deletions

View file

@ -17,7 +17,8 @@ if( CheckVersion( $DBversion ) ) {
resolved_by int(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `itemnumber` (`itemnumber`),
UNIQUE( issue_id ),
CONSTRAINT UNIQUE `issue_id` ( issue_id ),
CONSTRAINT `issue_id` FOREIGN KEY (`issue_id`) REFERENCES `issues` (`issue_id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `rc_items_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `rc_borrowers_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `rc_created_by_ibfk` FOREIGN KEY (`created_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,

View file

@ -4439,7 +4439,8 @@ CREATE TABLE return_claims (
resolved_by int(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `itemnumber` (`itemnumber`),
UNIQUE( issue_id ),
CONSTRAINT UNIQUE `issue_id` ( issue_id ),
CONSTRAINT `issue_id` FOREIGN KEY (`issue_id`) REFERENCES `issues` (`issue_id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `rc_items_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `rc_borrowers_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `rc_created_by_ibfk` FOREIGN KEY (`created_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,

View file

@ -30,7 +30,7 @@ my $builder = t::lib::TestBuilder->new;
subtest "store() tests" => sub {
plan tests => 6;
plan tests => 8;
$schema->storage->txn_begin;
@ -82,7 +82,39 @@ subtest "store() tests" => sub {
throws_ok {
Koha::Checkouts::ReturnClaim->new(
{
issue_id => $checkout->id + 1000,
issue_id => $checkout->id,
itemnumber => $checkout->itemnumber,
borrowernumber => $checkout->borrowernumber,
notes => 'Some notes',
created_by => $librarian->borrowernumber
}
)->store;
}
'Koha::Exceptions::Object::DuplicateID',
'An exception is thrown on duplicate issue_id';
close STDERR;
is(
$@->duplicate_id,
'issue_id',
'Exception field is correct'
);
}
{ # hide useless warnings
local *STDERR;
open STDERR, '>', '/dev/null';
my $another_checkout = $builder->build_object({ class => 'Koha::Checkouts' });
my $checkout_id = $another_checkout->id;
$another_checkout->delete;
my $THE_claim;
throws_ok {
$THE_claim = Koha::Checkouts::ReturnClaim->new(
{
issue_id => $checkout_id,
itemnumber => $checkout->itemnumber,
borrowernumber => $checkout->borrowernumber,
notes => 'Some notes',
@ -91,14 +123,10 @@ subtest "store() tests" => sub {
)->store;
}
'Koha::Exceptions::Object::FKConstraint',
'An exception is thrown on invalid issue_id';
'An exception is thrown on invalid issue_id';
close STDERR;
is(
$@->broken_fk,
'issue_id',
'Exception field is correct'
);
is( $@->broken_fk, 'issue_id', 'Exception field is correct' );
}
$schema->storage->txn_rollback;