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

Remove object_thumbnail? method #1749

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: 0 additions & 4 deletions app/models/embed/purl/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def description
end
end

def object_thumbnail?
@resource.attributes['thumb'].try(:value) == 'yes' || type == 'thumb'
end

def three_dimensional?
@resource.attributes['type']&.value == '3d'
end
Expand Down
8 changes: 2 additions & 6 deletions app/models/embed/purl/resource_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ def hierarchical_title
end

def primary?
primary_types = Settings.primary_mimetypes[resource.type] || []
!thumbnail? && primary_types.include?(mimetype)
Array(Settings.primary_mimetypes[resource.type]).include?(mimetype)
end

def thumbnail?
return true if resource.object_thumbnail?
return false unless image?

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

def vtt
Expand Down
11 changes: 3 additions & 8 deletions spec/components/embed/media_tag_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,9 @@
end

context 'with file and object level thumbnails' do
let(:purl) { file_and_object_level_thumb_purl }
let(:purl) { file_thumb_purl }

it 'does not include object level thumbnails' do
expect(page).to have_css('[data-file-label="audio.mp3"]', visible: :all)
expect(page).not_to have_css('[data-file-label="thumb.jp2"]', visible: :all)
end

it 'does not include file level thumbnails' do
it 'does not include thumbnails' do
expect(page).not_to have_css('[data-file-label="audio_1.jp2"]', visible: :all)
end

Expand Down Expand Up @@ -170,7 +165,7 @@

describe 'with a poster' do
context 'when a file level thumbnail is present' do
let(:purl) { file_and_object_level_thumb_purl }
let(:purl) { file_thumb_purl }
let(:resource_iteration) { instance_double(ActionView::PartialIteration, index: 1) }
let(:resource) { Embed::Purl.new(druid).contents.second }

Expand Down
5 changes: 1 addition & 4 deletions spec/fixtures/purl_fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ def audio_purl_multiple
XML
end

def file_and_object_level_thumb_purl
def file_thumb_purl
<<-XML
<publicObject>
<contentMetadata type="file">
Expand All @@ -1148,9 +1148,6 @@ def file_and_object_level_thumb_purl
<resource id="book_1" type="image">
<file id="book1.jp2" mimetype="image/jp2" size="77041"></file>
</resource>
<resource id="thumb_1" type="thumb" thumb="yes">
<file id="thumb.jp2" mimetype="image/jp2" size="7722"></file>
</resource>
</contentMetadata>
</publicObject>
XML
Expand Down
14 changes: 4 additions & 10 deletions spec/models/embed/purl/resource_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,19 @@
let(:file) { double('File') }
let(:resource_file) { described_class.new(resource, file, double('Rights')) }

it 'is true when the parent resource is an object level thumbnail' do
allow(resource).to receive(:object_thumbnail?).and_return(true)
expect(resource_file).to be_thumbnail
end

it 'is false when the file is not an image' do
allow(resource).to receive(:object_thumbnail?).and_return(false)
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 whitelisted as having file-level thumbnail behaviors (and it is an image)' do
allow(resource).to receive_messages(object_thumbnail?: false, type: 'video')
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 whitelisted as having file-level thumbnail behaviors (even if it is an image)' do
allow(resource).to receive_messages(object_thumbnail?: false, type: 'book')
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
Expand Down
24 changes: 0 additions & 24 deletions spec/models/embed/purl/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@
end
end

describe '#object_thumbnail?' do
subject { described_class.new('bc123df4567', node, instance_double(Dor::RightsAuth)) }

let(:node) { instance_double(Nokogiri::XML::Node, attributes:) }

context 'when type="thumb"' do
let(:attributes) { { 'type' => double(value: 'thumb') } }

it { is_expected.to be_object_thumbnail }
end

context 'when thumb="yes"' do
let(:attributes) { { 'thumb' => double(value: 'yes') } }

it { is_expected.to be_object_thumbnail }
end

context 'when any other value' do
let(:attributes) { { 'type' => double(value: 'image') } }

it { is_expected.not_to be_object_thumbnail }
end
end

describe 'files' do
it 'returns an array of Purl::Resource::ResourceFile objects' do
stub_purl_xml_response_with_fixture(file_purl_xml)
Expand Down