Skip to content

Commit

Permalink
Fix heading error when document has no fields.
Browse files Browse the repository at this point in the history
Fixes project_blacklight/blacklight#2234
  • Loading branch information
dkinzer committed Sep 24, 2020
1 parent 59f4d81 commit 95f39c9
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 95f39c9

Please sign in to comment.