Skip to content

Commit

Permalink
Handle the case where no solr response is available in context (e.g. …
Browse files Browse the repository at this point in the history
…SirTrevor search results widget). (#1073)
  • Loading branch information
Jessie Keck authored and camillevilla committed Jan 30, 2018
1 parent 20541da commit 597a4da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 597a4da

Please sign in to comment.