From 7e77eb658ea757330e919a74f7d918f3d33fd65d Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 13 Nov 2024 15:38:01 -0800 Subject: [PATCH 1/2] [i886] - Fix collection thumbnail fallback logic in Hyrax::ThumbnailPathServiceDecorator The default work thumbnail was displaying even though the default collection thumbnail was set. Issue: - https://github.com/scientist-softserv/adventist_knapsack/issues/886 - Updated #call method to use default_collection_image for collection resources when thumbnail_id is blank. - Ensures collections without specific thumbnails use the site-wide default collection image instead of the default work image. - Improved fallback logic to distinguish between collections and works, avoiding issues with collections displaying the work default image. --- app/services/hyrax/thumbnail_path_service_decorator.rb | 6 +++++- config/environments/production.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/services/hyrax/thumbnail_path_service_decorator.rb b/app/services/hyrax/thumbnail_path_service_decorator.rb index 876c87a7c..d64447aa0 100644 --- a/app/services/hyrax/thumbnail_path_service_decorator.rb +++ b/app/services/hyrax/thumbnail_path_service_decorator.rb @@ -10,10 +10,14 @@ def call(object) collection_thumbnail = CollectionBrandingInfo.where(collection_id: object.id.to_s, role: "thumbnail").first return collection_thumbnail.local_path.gsub(Hyrax.config.branding_path.to_s, '/branding') if collection_thumbnail - return default_image if object.try(:thumbnail_id).blank? + if object.try(:thumbnail_id).blank? + return default_collection_image if object.try(:collection?) + return default_image + end thumb = fetch_thumbnail(object) return default_collection_image unless thumb + return call(thumb) unless thumb.file_set? if audio?(thumb) audio_image diff --git a/config/environments/production.rb b/config/environments/production.rb index 94a15f300..6691a6ac2 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -50,7 +50,7 @@ config.force_ssl = true config.ssl_options = { redirect: { - exclude: -> request { request.path == '/healthz' } + exclude: ->(request) { request.path == '/healthz' } } } # Use the lowest log level to ensure availability of diagnostic information From d0a437fae631e97869085a422749a9dacbf6b492 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 14 Nov 2024 11:20:36 -0800 Subject: [PATCH 2/2] :white_check_mark: add spec for `default_collection_image` in `ThumbnailPathServiceDecorator` - Added a test for `default_collection_image` to verify it returns the site-specific default collection image when available. - Stubbed `Site.instance` to ensure the spec accurately tests behavior when a site default image is present or absent. --- .../hyrax/thumbnail_path_service_spec.rb | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spec/services/hyrax/thumbnail_path_service_spec.rb b/spec/services/hyrax/thumbnail_path_service_spec.rb index 5aa1889ff..6a0ca2790 100644 --- a/spec/services/hyrax/thumbnail_path_service_spec.rb +++ b/spec/services/hyrax/thumbnail_path_service_spec.rb @@ -18,4 +18,26 @@ end end end + + describe '.default_collection_image' do + context 'when the site has a default collection image' do + let(:collection_image) { '/assets/site_default_collection_image.png' } + let(:site_instance_double) { instance_double(Site, default_collection_image: double('DefaultCollectionImage', url: collection_image)) } + + before do + # Stub Site.instance to return our site_instance_double with the expected url + allow(Site).to receive(:instance).and_return(site_instance_double) + end + + it 'returns the default collection image from the site' do + expect(described_class.default_collection_image).to eq(collection_image) + end + end + + context 'when the site does not have a default collection image' do + it 'returns the Hyrax default collection image' do + expect(described_class.default_collection_image).to eq(ActionController::Base.helpers.image_path('default.png')) + end + end + end end