From 567bf374144ab1bf0ffac9c7f1d5f821d640c5d6 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Mon, 11 Nov 2024 12:56:23 -0800 Subject: [PATCH] [#4554] ClausePresenter: don't attempt to call #display_label on a non-existant field configuration This fixes an error that appeared when a user specified a search field that does not exist. It is essentially the same as upstream fix https://github.com/projectblacklight/blacklight/pull/3442, so if that is accepted and we start using a Blacklight release that includes it, we can remove our customized version. --- app/presenters/orangelight/clause_presenter.rb | 7 +++++++ .../presenters/orangelight/clause_presenter_spec.rb | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/presenters/orangelight/clause_presenter.rb b/app/presenters/orangelight/clause_presenter.rb index 6ab6f43d2..f59c6ef85 100644 --- a/app/presenters/orangelight/clause_presenter.rb +++ b/app/presenters/orangelight/clause_presenter.rb @@ -8,5 +8,12 @@ def label super end end + + # We will no longer need to override #field_label when/if we + # use a release of Blacklight that includes + # https://github.com/projectblacklight/blacklight/pull/3442 + def field_label + field_config&.display_label('search') + end end end diff --git a/spec/presenters/orangelight/clause_presenter_spec.rb b/spec/presenters/orangelight/clause_presenter_spec.rb index 53c3429a4..9db89bd1a 100644 --- a/spec/presenters/orangelight/clause_presenter_spec.rb +++ b/spec/presenters/orangelight/clause_presenter_spec.rb @@ -16,4 +16,17 @@ expect(subject.label).to eq 'NOT some search string' end end + describe '#field_label' do + context 'when the field config does not exist' do + let(:field_config) { nil } + + it 'returns nil' do + expect(subject.field_label).to be_nil + end + + it 'does not raise an error' do + expect { subject.field_label }.not_to raise_error + end + end + end end