Bug 27857: Get the right column

This patch makes the search for mandatory attribute types actually use
'code' instead of 'class' for comparisson.

Tests are added to cover this behavior.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Patron.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

https://bugs.koha-community.org/show_bug.cgi?id=27587

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2021-03-19 07:56:39 -03:00 committed by Jonathan Druart
parent 881b610db6
commit 0d59e57508
2 changed files with 14 additions and 4 deletions

View file

@ -1576,7 +1576,7 @@ sub extended_attributes {
undef
},
{ join => 'borrower_attribute_types_branches' }
)->get_column('class');
)->get_column('code');
for my $type ( @required_attribute_types ) {
Koha::Exceptions::Object::FKConstraint->throw(
broken_fk => "$type",

View file

@ -616,21 +616,21 @@ subtest 'extended_attributes' => sub {
subtest 'globally mandatory attributes tests' => sub {
plan tests => 3;
plan tests => 5;
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $attribute_type_1 = $builder->build_object(
{
class => 'Koha::Patron::Attribute::Types',
value => { mandatory => 1 }
value => { mandatory => 1, class => 'a' }
}
);
my $attribute_type_2 = $builder->build_object(
{
class => 'Koha::Patron::Attribute::Types',
value => { mandatory => 0 }
value => { mandatory => 0, class => 'a' }
}
);
@ -647,7 +647,17 @@ subtest 'extended_attributes' => sub {
'Koha::Exceptions::Object::FKConstraint',
'Exception thrown on missing mandatory attribute type';
is( $@->value, $attribute_type_1->code, 'Exception parameters are correct' );
is( $patron->extended_attributes->count, 0, 'Extended attributes storing rolled back' );
$patron->extended_attributes(
[
{ code => $attribute_type_1->code, attribute => 'b' }
]
);
is( $patron->extended_attributes->count, 1, 'Extended attributes succeeded' );
};
$schema->storage->txn_rollback;