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

Commit

Permalink
Default to loading unknown objects as a Dor::Item instance
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 11, 2016
1 parent 82705a1 commit 67aeb23
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/dor-services.rb
@@ -1,4 +1,5 @@
require 'active_fedora'
require 'active_fedora/version'
require 'active_support/core_ext/module/attribute_accessors'
require 'modsulator'
require 'dor/utils/sdr_client'
Expand Down
15 changes: 14 additions & 1 deletion lib/dor/models/identifiable.rb
Expand Up @@ -233,7 +233,20 @@ def adapt_to_cmodel
if object_class
self.instance_of?(object_class) ? self : self.adapt_to(object_class)
else
super
if ActiveFedora::VERSION < '8'
result = super
if result.class == Dor::Abstract
self.adapt_to(Dor::Item)
else
result
end
else
begin
super
rescue ActiveFedora::ModelNotAsserted
self.adapt_to(Dor::Item)
end
end
end
end

Expand Down
8 changes: 8 additions & 0 deletions spec/dor/identifiable_spec.rb
Expand Up @@ -345,5 +345,13 @@ class IdentifiableItem < ActiveFedora::Base
expect(item.adapt_to_cmodel.class).to eq Dor::Agreement
end
end

context 'for an object without identityMetadata or a RELS-EXT model' do
let(:item) { item_from_foxml(read_fixture('foxml_empty.xml'), Dor::Abstract) }

it 'defaults to Dor::Item' do
expect(item.adapt_to_cmodel.class).to eq Dor::Item
end
end
end
end

0 comments on commit 67aeb23

Please sign in to comment.