diff --git a/CHANGELOG.md b/CHANGELOG.md index efcfc969e..2e2c123b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Removed - Removes i18n keys for deprecated bibliography service #983 ### Fixed +- Fixed bug that caused feature pages using the search results widget to throw an error #1073 ### Security ## [1.14.1] - 2018-01-17 diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 98d0fc9ab..9c2dea355 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -379,7 +379,7 @@ class << self # section. In the case of our full text field, we do not render it in the normal results # so we need to not display the field at all unless it was returned in the highlighting. def full_text_highlight_exists_in_response?(context, config, document) - response = context.instance_variable_get(:@response) + response = context.instance_variable_get(:@response) || {} document_highlight = response.dig('highlighting', document['id']) return true if document_highlight.present? && document_highlight[config.key].present? false diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb new file mode 100644 index 000000000..78f9e9f5e --- /dev/null +++ b/spec/controllers/catalog_controller_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe CatalogController do + describe '#full_text_highlight_exists_in_response?' do + context 'when there is no solr response' do + it 'does not throw an error (returns false)' do + expect( + described_class.full_text_highlight_exists_in_response?( + instance_double('Context'), + instance_double('Config'), + SolrDocument.new(id: 'abc123') + ) + ).to be false + end + end + end +end