Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
Guard against calling #thumb on a collection object
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 22, 2016
1 parent e72f764 commit 1627a62
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dor/models/concerns/publishable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Publishable
# Compute the thumbnail for this object following the rules at https://consul.stanford.edu/display/chimera/The+Rules+of+Thumb
# @return [String] the computed thumb filename, with the druid prefix and a slash in front of it, e.g. oo000oo0001/filenamewith space.jp2
def thumb
return if contentMetadata.nil?
return unless respond_to?(:contentMetadata) && !contentMetadata.nil?
cm = contentMetadata.ng_xml
mime_type_finder = "@mimetype='image/jp2' or @mimeType='image/jp2'" # allow the mimetype attribute to be lower or camelcase when searching to make it more robust
thumb_image=nil
Expand Down
6 changes: 6 additions & 0 deletions spec/models/concerns/publishable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ItemizableItem < ActiveFedora::Base
before :each do

@item = instantiate_fixture('druid:ab123cd4567', PublishableItem)
@collection = instantiate_fixture('druid:ab123cd4567', Dor::Collection)
@apo = instantiate_fixture('druid:fg890hi1234', Dor::AdminPolicyObject)
allow(@item).to receive(:admin_policy_object).and_return(@apo)
@mods = <<-EOXML
Expand Down Expand Up @@ -100,6 +101,11 @@ class ItemizableItem < ActiveFedora::Base
end

describe '#thumb' do
it 'should return nil if there is no contentMetadata datastream' do
expect(@collection.thumb).to be_nil
expect(@collection.thumb_url).to be_nil
end

it 'should return nil if there is no contentMetadata' do
expect(@item.thumb).to be_nil
expect(@item.thumb_url).to be_nil
Expand Down

0 comments on commit 1627a62

Please sign in to comment.