# Insert the new ones
for my $attribute (@$attributes) {
- $self->_result->create_related('borrower_attributes', $attribute);
+ eval {
+ $self->_result->create_related('borrower_attributes', $attribute);
+ };
+ # FIXME We should:
+ # 1 - Raise an exception
+ # 2 - Execute in a transaction and don't save
+ # or Insert anyway but display a message on the UI
+ warn $@ if $@;
}
}
);
$schema->storage->txn_rollback;
subtest 'extended_attributes' => sub {
- plan tests => 10;
+ plan tests => 11;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
}
)->store;
+ my $deleted_attribute_type = $builder->build_object({ class => 'Koha::Patron::Attribute::Types' });
+ my $deleted_attribute_type_code = $deleted_attribute_type->code;
+ $deleted_attribute_type->delete;
+
my $new_library = $builder->build( { source => 'Branch' } );
my $attribute_type_limited = Koha::Patron::Attribute::Type->new(
{ code => 'my code3', description => 'my description3' } )->store;
{
attribute => 'my attribute limited 2',
code => $attribute_type_limited->code(),
+ },
+ {
+ attribute => 'my nonexistent attribute 2',
+ code => $deleted_attribute_type_code,
}
];
$patron_1->extended_attributes->filter_by_branch_limitations->delete;
$patron_2->extended_attributes->filter_by_branch_limitations->delete;
$patron_1->extended_attributes($attributes_for_1);
- $patron_2->extended_attributes($attributes_for_2);
+
+ my $print_error = $schema->storage->dbh->{PrintError};
+ $schema->storage->dbh->{PrintError} = 0;
+ warning_like {
+ $patron_2->extended_attributes($attributes_for_2);
+ } [ qr/a foreign key constraint fails/, qr/a foreign key constraint fails/ ], 'nonexistent attribute should have not exploded but print a warning';
+ $schema->storage->dbh->{PrintError} = $print_error;
my $extended_attributes_for_1 = $patron_1->extended_attributes;
is( $extended_attributes_for_1->count, 3, 'There should be 3 attributes now for patron 1');