From 0d59e57508201778ff4481dcc75be19a0e9a3cd0 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 19 Mar 2021 07:56:39 -0300 Subject: [PATCH] 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 https://bugs.koha-community.org/show_bug.cgi?id=27587 Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 2 +- t/db_dependent/Koha/Patron.t | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 1160084ca6..be83c399ce 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -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", diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 98b079f4c3..bf211af98e 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -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; -- 2.39.5