Skip to content

Commit

Permalink
Merge pull request #1770 from sul-dlss/simplify-thumbnail
Browse files Browse the repository at this point in the history
Simplify finding thumbnail
  • Loading branch information
jcoyne authored Nov 17, 2023
2 parents 0223ef9 + 9b33f8d commit 55b50a7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 28 deletions.
4 changes: 3 additions & 1 deletion app/models/embed/purl/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def primary_types

# @return [ResourceFile]
def thumbnail
files.find(&:thumbnail?)
return unless Settings.resource_types_that_contain_thumbnails.include?(type)

files.find(&:image?)
end

# @return [ResourceFile]
Expand Down
4 changes: 0 additions & 4 deletions app/models/embed/purl/resource_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ def hierarchical_title
title.split('/').last
end

def thumbnail?
image? && Settings.resource_types_that_contain_thumbnails.include?(resource.type)
end

def vtt?
mimetype == 'text/vtt'
end
Expand Down
23 changes: 0 additions & 23 deletions spec/models/embed/purl/resource_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,6 @@
end
end

describe '#thumbnail?' do
let(:resource) { instance_double(Embed::Purl::Resource) }
let(:file) { double('File') }
let(:resource_file) { described_class.new(resource, file, double('Rights')) }

it 'is false when the file is not an image' do
allow(file).to receive(:attributes).and_return('mimetype' => double(value: 'not-an-image'))
expect(resource_file).not_to be_thumbnail
end

it 'is true when the parent resource type is listed as having file-level thumbnail behaviors (and it is an image)' do
allow(resource).to receive_messages(type: 'video')
allow(file).to receive(:attributes).and_return('mimetype' => double(value: 'image/jp2'))
expect(resource_file).to be_thumbnail
end

it 'is false when the parent resource type is not listed as having file-level thumbnail behaviors (even if it is an image)' do
allow(resource).to receive_messages(type: 'book')
allow(file).to receive(:attributes).and_return('mimetype' => double(value: 'image/jp2'))
expect(resource_file).not_to be_thumbnail
end
end

describe 'previewable?' do
it 'returns true if the mimetype of the file is previewable' do
stub_purl_xml_response_with_fixture(image_purl_xml)
Expand Down

0 comments on commit 55b50a7

Please sign in to comment.