Skip to content

Commit

Permalink
Merge pull request #4424 from samvera/display-image-af-fallback
Browse files Browse the repository at this point in the history
test & document DisplaysImage fallback behavior
  • Loading branch information
jeremyf authored Jul 11, 2020
2 parents 7b26675 + 17ebea6 commit 4b19b4e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/presenters/hyrax/displays_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ def image_format(channels)
channels&.include?('rgba') ? 'png' : 'jpg'
end

##
# @api private
#
# Get the id for the latest version of original file. If
# `#originial_file_id` is available on the object, simply use that value.
# Otherwise, retrieve the original file directly from the datastore and
# resolve the current version using `VersioningService`.
#
# The fallback lookup normally happens when a File Set was indexed prior
# to the introduction of `#original_file_id` to the index document,
# but is useful as a generalized failsafe to ensure we have done our best
# to resolve the content.
#
# @note this method caches agressively. it's here to support IIIF
# manifest generation and we expect this object to exist only for
# the generation of a single manifest document. this insulates callers
# from the complex lookup behavior and protects against expensive and
# unnecessary database lookups.
def latest_file_id
@latest_file_id ||=
begin
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/file_sets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
content { File.open(Hyrax::Engine.root + 'spec/fixtures/world.png') }
end

trait :with_original_file do
after(:create) do |file_set, _evaluator|
Hydra::Works::AddFileToFileSet
.call(file_set, File.open(Hyrax::Engine.root + 'spec/fixtures/world.png'), :original_file)
end
end

factory :file_with_work do
after(:build) do |file, _evaluator|
file.title = ['testfile']
Expand Down
14 changes: 14 additions & 0 deletions spec/presenters/hyrax/iiif_manifest_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@
expect(presenter.display_image).to be_nil
end
end

context 'when no original file is indexed' do
let(:solr_doc) do
index_hash = file_set.to_solr
index_hash.delete('original_file_id_ssi')

SolrDocument.new(index_hash)
end

it 'can still resolve the image' do
expect(presenter.display_image.to_json)
.to include 'fcr:versions%2Fversion1/full'
end
end
end
end

Expand Down

0 comments on commit 4b19b4e

Please sign in to comment.