Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify finding thumbnail #1770

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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