From b004b54a83837c00601506c21674e895504c3e59 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Mon, 17 Dec 2018 16:46:39 -0800 Subject: [PATCH] Handle cases where the deprecated field value is not a string or symbol either --- app/presenters/blacklight/index_presenter.rb | 12 ++++++++---- spec/presenters/index_presenter_spec.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/presenters/blacklight/index_presenter.rb b/app/presenters/blacklight/index_presenter.rb index 28b397eefa..ca4364eec7 100644 --- a/app/presenters/blacklight/index_presenter.rb +++ b/app/presenters/blacklight/index_presenter.rb @@ -53,13 +53,17 @@ def render_document_index_label(*args) # @option options [String] :value def field_value field_or_name, options = {} field = case field_or_name + when Blacklight::Configuration::Field + field_or_name when String, Symbol - Deprecation.warn(self, "You provided a String or Symbol value to IndexPresenter#field_value " \ - "Provide a Blacklight::Configuration::Field instead. field_value() will not accept " \ - "strings or symbols in Blacklight 7") + Deprecation.warn(self, "You provided a #{field_or_name.class} value to IndexPresenter#field_value " \ + "Provide a Blacklight::Configuration::Field instead. This behavior is deprecated in Blacklight 7") field_config(field_or_name) else - field_or_name + Deprecation.warn(self, "You provided a #{field_or_name.class} value to IndexPresenter#field_value. " \ + "This will be silently ignored and will be an error in Blacklight 7.") + + Configuration::NullField.new end field_values(field, options) end diff --git a/spec/presenters/index_presenter_spec.rb b/spec/presenters/index_presenter_spec.rb index c4b894713f..fb2c3deef9 100644 --- a/spec/presenters/index_presenter_spec.rb +++ b/spec/presenters/index_presenter_spec.rb @@ -58,6 +58,15 @@ expect(subject).to eq 'document qwer value' end end + + context 'with a name as an integer' do + subject { presenter.field_value 123 } + + it 'raises a deprecation' do + expect(Deprecation).to receive(:warn) + expect(subject).to eq '' + end + end end context 'when an explicit value is provided' do