From 19bb1d0763835004bff520516678564aaa981238 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 25 Nov 2022 10:02:24 +0000 Subject: [PATCH] Bug 32350: Use array_minus and ignore nesting Note: Test will be extended in follow-up. This fixes the module_bit hash to follow the FK path from user_permissions to permissions to userflags. One step was missed in the existing test, although it did not fail. The change here revealed that now. Test plan: Run t/db_dependent/TestBuilder.t Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- t/db_dependent/TestBuilder.t | 4 +++- t/lib/TestBuilder.pm | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index c256fe53fc..30588da103 100755 --- a/t/db_dependent/TestBuilder.t +++ b/t/db_dependent/TestBuilder.t @@ -244,7 +244,9 @@ sub default_userpermission { privacy => 1, }, module_bit => { - flag => 'my flag', + module_bit => { + flag => 'my flag', + }, }, code => { code => 'my code', diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index bac6e3818e..fedcdc718d 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -13,6 +13,7 @@ use Carp qw( carp ); use Module::Load qw( load ); use String::Random; use List::Util qw( any ); +use Array::Utils qw( array_minus ); use constant { SIZE_BARCODE => 20, # Not perfect but avoid to fetch the value when creating a new item @@ -281,10 +282,9 @@ sub _buildColumnValues { my @columns = $self->schema->source($source)->columns; my %unique_constraints = $self->schema->source($source)->unique_constraints(); - for my $key ( keys %{$original_value} ) { - die "value passed for unrecognised column: $key" - if !( any { $key eq $_ } @columns ); - } + my @passed_keys = grep { ref($original_value->{$_}) ne 'HASH' } keys %$original_value; + my @minus = array_minus( @passed_keys, @columns ); + die "Error: value hash contains unrecognized columns: ". (join ',', @minus) if @minus; my $build_value = 5; # we try max $build_value times if there are unique constraints -- 2.20.1