diff --git a/app/overrides/presenters/blacklight/thumbnail_presenter_override.rb b/app/overrides/presenters/blacklight/thumbnail_presenter_override.rb index 2b03fb305..52993d47b 100644 --- a/app/overrides/presenters/blacklight/thumbnail_presenter_override.rb +++ b/app/overrides/presenters/blacklight/thumbnail_presenter_override.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +# https://github.com/projectblacklight/blacklight/blob/v8.7.0/app/presenters/blacklight/thumbnail_presenter.rb module Blacklight class ThumbnailPresenter private @@ -16,7 +17,7 @@ def retrieve_values(field_config) if needs_thumbnail_path_update?(document_hash) file_set_id = document_hash['file_set_ids_ssim']&.first document_hash['thumbnail_path_ss'] = "/downloads/#{file_set_id}?file=thumbnail" - Rails.logger.info("Updated thumbnail_path_ss: #{document_hash['thumbnail_path_ss']} for work with id #{document.id}") + Rails.logger.info("Updated thumbnail_path_ss: #{document_hash['thumbnail_path_ss']} for work with id #{document_hash['id']}") # Create a temporary SolrDocument from the updated hash updated_document = SolrDocument.new(document_hash) FieldRetriever.new(updated_document, field_config, view_context).fetch @@ -38,9 +39,10 @@ def extract_solr_document(doc) def needs_thumbnail_path_update?(document) thumbnail_path = document['thumbnail_path_ss'] || '' file_set_ids = document['file_set_ids_ssim'] + thumbnail_missing_or_default = thumbnail_path.blank? || thumbnail_path !~ %r{^/downloads/\w+\?file=thumbnail$} - # Check if the thumbnail path is the default or missing and file_set_ids are present - thumbnail_path !~ %r{^/downloads/\w+\?file=thumbnail$} && file_set_ids.present? + # Returns true if file_set_ids are present and the thumbnail path is the default or missing entirely + file_set_ids.present? && thumbnail_missing_or_default end end end diff --git a/app/overrides/presenters/hyrax/work_show_presenter_override.rb b/app/overrides/presenters/hyrax/work_show_presenter_override.rb index 937e99de4..33553c197 100644 --- a/app/overrides/presenters/hyrax/work_show_presenter_override.rb +++ b/app/overrides/presenters/hyrax/work_show_presenter_override.rb @@ -6,7 +6,7 @@ delegate :title, :date_created, :date_issued, :description, :doi, :creator, :place_of_publication, :creator_display, :contributor, :subject, :publisher, :language, :embargo_release_date, :lease_expiration_date, :license, :source, :rights_statement, :thumbnail_id, :representative_id, - :rendering_ids, :member_of_collection_ids, :member_ids, :alternative_title, to: :solr_document + :rendering_ids, :member_of_collection_ids, :bibliographic_citation, :alternative_title, :member_ids, to: :solr_document # [hyc-override] Add default scholarly? method # Indicates if the work is considered scholarly according to google scholar @@ -23,10 +23,10 @@ def fetch_primary_fileset_id # [hyc-override] Use a work's first related fileset_id instead of the representative_id if it's nil # @return FileSetPresenter presenter for the representative FileSets def representative_presenter - primary_fileset_id = fetch_primary_fileset_id - return nil if primary_fileset_id.blank? @representative_presenter ||= begin + primary_fileset_id = fetch_primary_fileset_id + return nil if primary_fileset_id.blank? result = member_presenters([primary_fileset_id]).first return nil if result.try(:id) == id result.try(:representative_presenter) || result diff --git a/spec/presenters/blacklight/thumbnail_presenter_spec.rb b/spec/presenters/blacklight/thumbnail_presenter_spec.rb index 995c2ace8..8346aaa5a 100644 --- a/spec/presenters/blacklight/thumbnail_presenter_spec.rb +++ b/spec/presenters/blacklight/thumbnail_presenter_spec.rb @@ -15,10 +15,11 @@ allow(retriever_instance).to receive(:fetch).and_return('default_thumbnail') allow(presenter).to receive(:extract_solr_document) - presenter.send(:retrieve_values, field_config) + result = presenter.send(:retrieve_values, field_config) expect(Blacklight::FieldRetriever).to have_received(:new).with(nil, field_config, view_context) # Presenter should not process the document if it's nil expect(presenter).not_to have_received(:extract_solr_document) + expect(result).to eq('default_thumbnail') end it 'updates the thumbnail_path_ss if it needs an update' do @@ -39,11 +40,12 @@ allow(retriever_instance).to receive(:fetch).and_return('updated_thumbnail') allow(Rails.logger).to receive(:info) - presenter.send(:retrieve_values, field_config) + result = presenter.send(:retrieve_values, field_config) expect(Rails.logger).to have_received(:info).with('Updated thumbnail_path_ss: /downloads/file_set_1?file=thumbnail for work with id 1') expect(SolrDocument).to have_received(:new).with( hash_including('thumbnail_path_ss' => '/downloads/file_set_1?file=thumbnail') ) + expect(result).to eq('updated_thumbnail') end end end