From b26a07a00b5b5e2c3313da407929ae3d73b42a65 Mon Sep 17 00:00:00 2001 From: Ben Pennell Date: Wed, 26 Feb 2025 10:27:49 -0500 Subject: [PATCH] HYC-2047 - Prevent error when depts are select in the advanced search (#1148) * Prevent error when depts are select in the advanced search, which produces a list of dept keys * Rubocop --- app/helpers/hyc_helper.rb | 8 ++++++-- spec/helpers/hyc_helper_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/helpers/hyc_helper.rb b/app/helpers/hyc_helper.rb index 27bb8977a..51653a0da 100644 --- a/app/helpers/hyc_helper.rb +++ b/app/helpers/hyc_helper.rb @@ -22,8 +22,12 @@ def language_links_facets(options) # Format affiliation to display short label if available, otherwise display the original facet value def format_affiliation_facet(facet_value) - label = DepartmentsService.short_label(facet_value) - label.blank? ? facet_value : label + if facet_value.kind_of?(Array) + facet_value.map { |value| format_affiliation_facet(value) || value } + else + label = DepartmentsService.short_label(facet_value) + label.blank? ? facet_value : label + end end def get_work_url(model, id) diff --git a/spec/helpers/hyc_helper_spec.rb b/spec/helpers/hyc_helper_spec.rb index 301ed86ac..23ef69821 100644 --- a/spec/helpers/hyc_helper_spec.rb +++ b/spec/helpers/hyc_helper_spec.rb @@ -53,6 +53,14 @@ end end + context 'with array facet value' do + let(:facet_value) { ['Department of Chemistry', 'Carolina Center for Genome Sciences'] } + + it 'returns the short label for the facet value' do + expect(helper.format_affiliation_facet(facet_value)).to eq ['Test short Department of Chemistry', 'Test short Carolina Center for Genome Sciences'] + end + end + context 'with invalid facet value' do let(:invalid_facet_value) { 'not-a-department' }