Skip to content

Commit

Permalink
Merge pull request #2333 from dkinzer/issue-2234-fix-undefined-method…
Browse files Browse the repository at this point in the history
…-for-nil-class

Fix heading error when document has no fields.
  • Loading branch information
jcoyne authored Sep 24, 2020
2 parents 59f4d81 + 95f39c9 commit d582cf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/presenters/blacklight/document_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def heading

fields = Array.wrap(view_config.title_field) + [configuration.document_model.unique_key]
f = fields.lazy.map { |field| field_config(field) }.detect { |field_config| field_presenter(field_config).any? }
field_value(f, except_operations: [Rendering::HelperMethod])
f ? field_value(f, except_operations: [Rendering::HelperMethod]) : ""
end

def display_type(base_name = nil, default: nil)
Expand Down
8 changes: 8 additions & 0 deletions spec/presenters/blacklight/show_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ def mock_document_app_helper_url *args
config.show.title_field = Blacklight::Configuration::Field.new(field: 'x', values: ->(*_) { 'hardcoded' })
expect(subject.heading).to eq 'hardcoded'
end

context "when empty document" do
let(:document) { SolrDocument.new({}) }

it "returns an empty string as the heading" do
expect(subject.heading).to eq("")
end
end
end

describe "#html_title" do
Expand Down

0 comments on commit d582cf5

Please sign in to comment.