diff --git a/hydra-pcdm.gemspec b/hydra-pcdm.gemspec index 70e7b7e0..40fdda72 100644 --- a/hydra-pcdm.gemspec +++ b/hydra-pcdm.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ['lib'] + spec.add_dependency 'active-fedora', '>= 9.4.1' spec.add_dependency 'activefedora-aggregation', '~> 0.4' spec.add_dependency 'mime-types', '>= 1' diff --git a/lib/hydra/pcdm/collection_indexer.rb b/lib/hydra/pcdm/collection_indexer.rb index 1baa121e..2bb9f18d 100644 --- a/lib/hydra/pcdm/collection_indexer.rb +++ b/lib/hydra/pcdm/collection_indexer.rb @@ -2,8 +2,8 @@ module Hydra::PCDM class CollectionIndexer < ObjectIndexer def generate_solr_document super.tap do |solr_doc| - solr_doc['member_ids_ssim'] = object.member_ids - solr_doc['child_collection_ids_ssim'] = object.child_collection_ids + solr_doc['member_ids_ssim'] = object.member_ids + solr_doc['collection_ids_ssim'] = object.collection_ids end end end diff --git a/lib/hydra/pcdm/models/concerns/collection_behavior.rb b/lib/hydra/pcdm/models/concerns/collection_behavior.rb index 3759d529..1b4bfb1e 100644 --- a/lib/hydra/pcdm/models/concerns/collection_behavior.rb +++ b/lib/hydra/pcdm/models/concerns/collection_behavior.rb @@ -17,7 +17,7 @@ module CollectionBehavior type Vocab::PCDMTerms.Collection include ::Hydra::PCDM::PcdmBehavior - filters_association :members, as: :child_collections, condition: :pcdm_collection? + filters_association :members, as: :collections, condition: :pcdm_collection? end module ClassMethods @@ -36,5 +36,20 @@ def pcdm_object? def pcdm_collection? true end + + def child_collections + warn '[DEPRECATION] `child_collections` is deprecated in Hydra::PCDM. Please use `collections` instead. This has a target date for removal of 10-31-2015' + collections + end + + def child_collections=(new_collections) + warn '[DEPRECATION] `child_collections=` is deprecated in Hydra::PCDM. Please use `collections=` instead. This has a target date for removal of 10-31-2015' + self.collections = new_collections + end + + def child_collection_ids + warn '[DEPRECATION] `child_collection_ids` is deprecated in Hydra::PCDM. Please use `collection_ids` instead. This has a target date for removal of 10-31-2015' + collection_ids + end end end diff --git a/lib/hydra/pcdm/models/concerns/object_behavior.rb b/lib/hydra/pcdm/models/concerns/object_behavior.rb index d1951d88..02bf3679 100644 --- a/lib/hydra/pcdm/models/concerns/object_behavior.rb +++ b/lib/hydra/pcdm/models/concerns/object_behavior.rb @@ -39,10 +39,15 @@ def pcdm_collection? false end - def parent_objects + def in_objects aggregated_by.select(&:pcdm_object?) end + def parent_objects + warn '[DEPRECATION] `parent_objects` is deprecated in Hydra::PCDM. Please use `in_objects` instead. This has a target date for removal of 10-31-2015' + in_objects + end + # Returns directly contained files that have the requested RDF Type # @param [RDF::URI] uri for the desired Type # @example diff --git a/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb b/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb index 69495502..d31abcd6 100644 --- a/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb +++ b/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb @@ -5,7 +5,7 @@ module PcdmBehavior aggregates :members, predicate: Vocab::PCDMTerms.hasMember, class_name: 'ActiveFedora::Base', type_validator: type_validator - filters_association :members, as: :child_objects, condition: :pcdm_object? + filters_association :members, as: :objects, condition: :pcdm_object? indirectly_contains :related_objects, has_member_relation: RDF::Vocab::ORE.aggregates, inserted_content_relation: RDF::Vocab::ORE.proxyFor, class_name: 'ActiveFedora::Base', through: 'ActiveFedora::Aggregation::Proxy', foreign_key: :target, @@ -22,16 +22,31 @@ def type_validator end end - def parents + def member_of aggregated_by end - def parent_collections + def parents + warn '[DEPRECATION] `parents` is deprecated in Hydra::PCDM. Please use `member_of` instead. This has a target date for removal of 10-31-2015' + member_of + end + + def in_collections aggregated_by.select(&:pcdm_collection?) end + def parent_collections + warn '[DEPRECATION] `parent_collections` is deprecated in Hydra::PCDM. Please use `in_collections` instead. This has a target date for removal of 10-31-2015' + in_collections + end + + def in_collection_ids + in_collections.map(&:id) + end + def parent_collection_ids - parent_collections.map(&:id) + warn '[DEPRECATION] `parent_collection_ids` is deprecated in Hydra::PCDM. Please use `in_collection_ids` instead. This has a target date for removal of 10-31-2015' + in_collection_ids end def ancestor?(record) @@ -41,5 +56,20 @@ def ancestor?(record) def ancestor_checker @ancestor_checker ||= ::Hydra::PCDM::AncestorChecker.new(self) end + + def child_objects + warn '[DEPRECATION] `child_objects` is deprecated in Hydra::PCDM. Please use `objects` instead. This has a target date for removal of 10-31-2015' + objects + end + + def child_objects=(new_objects) + warn '[DEPRECATION] `child_objects=` is deprecated in Hydra::PCDM. Please use `objects=` instead. This has a target date for removal of 10-31-2015' + self.objects = new_objects + end + + def child_object_ids + warn '[DEPRECATION] `child_object_ids` is deprecated in Hydra::PCDM. Please use `object_ids` instead. This has a target date for removal of 10-31-2015' + object_ids + end end end diff --git a/lib/hydra/pcdm/object_indexer.rb b/lib/hydra/pcdm/object_indexer.rb index c066a4bf..b1749f39 100644 --- a/lib/hydra/pcdm/object_indexer.rb +++ b/lib/hydra/pcdm/object_indexer.rb @@ -2,7 +2,7 @@ module Hydra::PCDM class ObjectIndexer < ActiveFedora::IndexingService def generate_solr_document super.tap do |solr_doc| - solr_doc['child_object_ids_ssim'] = object.child_object_ids + solr_doc['object_ids_ssim'] = object.object_ids end end end diff --git a/lib/hydra/pcdm/version.rb b/lib/hydra/pcdm/version.rb index f87cfc8e..99537ad3 100644 --- a/lib/hydra/pcdm/version.rb +++ b/lib/hydra/pcdm/version.rb @@ -1,5 +1,5 @@ module Hydra module PCDM - VERSION = '0.1.0' + VERSION = '0.2.0' end end diff --git a/spec/hydra/pcdm/collection_indexer_spec.rb b/spec/hydra/pcdm/collection_indexer_spec.rb index dcf82c4a..a774bfdb 100644 --- a/spec/hydra/pcdm/collection_indexer_spec.rb +++ b/spec/hydra/pcdm/collection_indexer_spec.rb @@ -2,14 +2,14 @@ describe Hydra::PCDM::CollectionIndexer do let(:collection) { Hydra::PCDM::Collection.new } - let(:child_collection_ids) { %w(123 456) } - let(:child_object_ids) { ['789'] } + let(:collection_ids) { %w(123 456) } + let(:object_ids) { ['789'] } let(:member_ids) { %w(123 456 789) } let(:indexer) { described_class.new(collection) } before do - allow(collection).to receive(:child_collection_ids).and_return(child_collection_ids) - allow(collection).to receive(:child_object_ids).and_return(child_object_ids) + allow(collection).to receive(:collection_ids).and_return(collection_ids) + allow(collection).to receive(:object_ids).and_return(object_ids) allow(collection).to receive(:member_ids).and_return(member_ids) end @@ -17,8 +17,8 @@ subject { indexer.generate_solr_document } it 'has fields' do - expect(subject['child_collection_ids_ssim']).to eq %w(123 456) - expect(subject['child_object_ids_ssim']).to eq ['789'] + expect(subject['collection_ids_ssim']).to eq %w(123 456) + expect(subject['object_ids_ssim']).to eq ['789'] expect(subject['member_ids_ssim']).to eq %w(123 456 789) end end diff --git a/spec/hydra/pcdm/models/collection_spec.rb b/spec/hydra/pcdm/models/collection_spec.rb index 3d23ea26..d99e8bf5 100644 --- a/spec/hydra/pcdm/models/collection_spec.rb +++ b/spec/hydra/pcdm/models/collection_spec.rb @@ -4,20 +4,22 @@ let(:collection1) { described_class.new } let(:collection2) { described_class.new } let(:collection3) { described_class.new } + let(:collection4) { described_class.new } let(:object1) { Hydra::PCDM::Object.new } let(:object2) { Hydra::PCDM::Object.new } + let(:object3) { Hydra::PCDM::Object.new } describe 'adding collections' do describe 'with acceptable inputs' do subject { described_class.new } it 'adds collections, sub-collections, and repeating collections' do - subject.child_collections << collection1 # first add - subject.child_collections << collection2 # second add to same collection - subject.child_collections << collection1 # repeat a collection - collection1.child_collections << collection3 # add sub-collection - expect(subject.child_collections).to eq [collection1, collection2, collection1] - expect(collection1.child_collections).to eq [collection3] + subject.collections << collection1 # first add + subject.collections << collection2 # second add to same collection + subject.collections << collection1 # repeat a collection + collection1.collections << collection3 # add sub-collection + expect(subject.collections).to eq [collection1, collection2, collection1] + expect(collection1.collections).to eq [collection3] end it 'adds an object to collection with collections and objects' do subject.members << collection1 @@ -26,18 +28,18 @@ subject.members << object2 subject.members << collection3 expect(subject.members).to eq [collection1, collection2, object1, object2, collection3] - expect(subject.child_collections).to eq [collection1, collection2, collection3] - expect(subject.child_objects).to eq [object1, object2] + expect(subject.collections).to eq [collection1, collection2, collection3] + expect(subject.objects).to eq [object1, object2] end end - describe '#parent_collection_ids' do + describe '#in_collection_ids' do it 'returns the IDs of the parent' do subject.members << object1 subject.members << collection1 subject.save - expect(object1.parent_collection_ids).to eq [subject.id] - expect(collection1.parent_collection_ids).to eq [subject.id] + expect(object1.in_collection_ids).to eq [subject.id] + expect(collection1.in_collection_ids).to eq [subject.id] end end @@ -51,13 +53,13 @@ class Kollection < ActiveFedora::Base let(:kollection1) { Kollection.new } it 'accepts implementing collection as a child' do - subject.child_collections << kollection1 - expect(subject.child_collections).to eq [kollection1] + subject.collections << kollection1 + expect(subject.collections).to eq [kollection1] end it 'accepts implementing collection as a parent' do - kollection1.child_collections << collection1 - expect(kollection1.child_collections).to eq [collection1] + kollection1.collections << collection1 + expect(kollection1.collections).to eq [collection1] end end @@ -70,13 +72,13 @@ class Cullection < Hydra::PCDM::Collection let(:cullection1) { Cullection.new } it 'accepts extending collection as a child' do - subject.child_collections << cullection1 - expect(subject.child_collections).to eq [cullection1] + subject.collections << cullection1 + expect(subject.collections).to eq [cullection1] end it 'accepts extending collection as a parent' do - cullection1.child_collections << collection1 - expect(cullection1.child_collections).to eq [collection1] + cullection1.collections << collection1 + expect(cullection1.collections).to eq [collection1] end end @@ -95,19 +97,19 @@ class Cullection < Hydra::PCDM::Collection let(:error_message2) { /undefined method `pcdm_collection\?' for .*/ } it 'raises an error when trying to aggregate Hydra::PCDM::Objects in collections aggregation' do - expect { collection1.child_collections << @object101 }.to raise_error(error_type1, error_message1) + expect { collection1.collections << @object101 }.to raise_error(error_type1, error_message1) end it 'raises an error when trying to aggregate Hydra::PCDM::Files in collections aggregation' do - expect { collection1.child_collections << @file101 }.to raise_error(error_type2, error_message2) + expect { collection1.collections << @file101 }.to raise_error(error_type2, error_message2) end it 'raises an error when trying to aggregate non-PCDM objects in collections aggregation' do - expect { collection1.child_collections << @non_pcdm_object }.to raise_error(error_type2, error_message2) + expect { collection1.collections << @non_pcdm_object }.to raise_error(error_type2, error_message2) end it 'raises an error when trying to aggregate AF::Base objects in collections aggregation' do - expect { collection1.child_collections << @af_base_object }.to raise_error(error_type2, error_message2) + expect { collection1.collections << @af_base_object }.to raise_error(error_type2, error_message2) end end end @@ -118,35 +120,35 @@ class Cullection < Hydra::PCDM::Collection context 'when the source collection is the same' do it 'raises an error' do - expect { subject.child_collections << subject }.to raise_error(error_type, error_message) + expect { subject.collections << subject }.to raise_error(error_type, error_message) end end before do - subject.child_collections << collection1 + subject.collections << collection1 end it 'raises and error' do - expect { collection1.child_collections << subject }.to raise_error(error_type, error_message) + expect { collection1.collections << subject }.to raise_error(error_type, error_message) end context 'with more ancestors' do before do - collection1.child_collections << collection2 + collection1.collections << collection2 end it 'raises an error' do - expect { collection2.child_collections << subject }.to raise_error(error_type, error_message) + expect { collection2.collections << subject }.to raise_error(error_type, error_message) end context 'with a more complicated example' do before do - collection2.child_collections << collection3 + collection2.collections << collection3 end it 'raises errors' do - expect { collection3.child_collections << subject }.to raise_error(error_type, error_message) - expect { collection3.child_collections << collection1 }.to raise_error(error_type, error_message) + expect { collection3.collections << subject }.to raise_error(error_type, error_message) + expect { collection3.collections << collection1 }.to raise_error(error_type, error_message) end end end @@ -159,20 +161,20 @@ class Cullection < Hydra::PCDM::Collection context 'when it is the only collection' do before do subject.members << collection1 - expect(subject.child_collections).to eq [collection1] + expect(subject.collections).to eq [collection1] end it 'removes collection while changes are in memory' do expect(subject.members.delete collection1).to eq [collection1] - expect(subject.child_collections).to eq [] + expect(subject.collections).to eq [] end it 'removes collection only when objects and all changes are in memory' do subject.members << object1 subject.members << object2 expect(subject.members.delete collection1).to eq [collection1] - expect(subject.child_collections).to eq [] - expect(subject.child_objects).to eq [object1, object2] + expect(subject.collections).to eq [] + expect(subject.objects).to eq [object1, object2] end end @@ -181,29 +183,29 @@ class Cullection < Hydra::PCDM::Collection subject.members << collection1 subject.members << collection2 subject.members << collection3 - expect(subject.child_collections).to eq [collection1, collection2, collection3] + expect(subject.collections).to eq [collection1, collection2, collection3] end it 'removes first collection when changes are in memory' do expect(subject.members.delete collection1).to eq [collection1] - expect(subject.child_collections).to eq [collection2, collection3] + expect(subject.collections).to eq [collection2, collection3] end it 'removes last collection when changes are in memory' do expect(subject.members.delete collection3).to eq [collection3] - expect(subject.child_collections).to eq [collection1, collection2] + expect(subject.collections).to eq [collection1, collection2] end it 'removes middle collection when changes are in memory' do expect(subject.members.delete collection2).to eq [collection2] - expect(subject.child_collections).to eq [collection1, collection3] + expect(subject.collections).to eq [collection1, collection3] end it 'removes middle collection when changes are saved' do - expect(subject.child_collections).to eq [collection1, collection2, collection3] + expect(subject.collections).to eq [collection1, collection2, collection3] subject.save expect(subject.members.delete collection2).to eq [collection2] - expect(subject.child_collections).to eq [collection1, collection3] + expect(subject.collections).to eq [collection1, collection3] end end context 'when collection is missing' do @@ -229,19 +231,19 @@ class Cullection < Hydra::PCDM::Collection describe 'adding objects' do context 'with acceptable inputs' do it 'adds objects, sub-collections, and repeating collections' do - subject.child_objects << object1 # first add - subject.child_objects << object2 # second add to same collection - subject.child_objects << object1 # repeat an object - expect(subject.child_objects).to eq [object1, object2, object1] + subject.objects << object1 # first add + subject.objects << object2 # second add to same collection + subject.objects << object1 # repeat an object + expect(subject.objects).to eq [object1, object2, object1] end context 'with collections and objects' do it 'adds an object to collection with collections and objects' do - subject.child_objects << object1 - subject.child_collections << collection1 - subject.child_collections << collection2 - subject.child_objects << object2 - expect(subject.child_objects).to eq [object1, object2] + subject.objects << object1 + subject.collections << collection1 + subject.collections << collection2 + subject.objects << object2 + expect(subject.objects).to eq [object1, object2] end end @@ -255,8 +257,8 @@ class Ahbject < ActiveFedora::Base let(:ahbject1) { Ahbject.new } it 'accepts implementing object as a child' do - subject.child_objects << ahbject1 - expect(subject.child_objects).to eq [ahbject1] + subject.objects << ahbject1 + expect(subject.objects).to eq [ahbject1] end end @@ -269,8 +271,8 @@ class Awbject < Hydra::PCDM::Object let(:awbject1) { Awbject.new } it 'accepts extending object as a child' do - subject.child_objects << awbject1 - expect(subject.child_objects).to eq [awbject1] + subject.objects << awbject1 + expect(subject.objects).to eq [awbject1] end end end @@ -289,19 +291,19 @@ class Awbject < Hydra::PCDM::Object let(:error_message2) { /undefined method `pcdm_object\?' for .*/ } it 'raises an error when trying to aggregate Hydra::PCDM::Collection in objects aggregation' do - expect { collection1.child_objects << collection2 }.to raise_error(error_type1, error_message1) + expect { collection1.objects << collection2 }.to raise_error(error_type1, error_message1) end it 'raises an error when trying to aggregate Hydra::PCDM::Files in objects aggregation' do - expect { collection1.child_objects << @file101 }.to raise_error(error_type2, error_message2) + expect { collection1.objects << @file101 }.to raise_error(error_type2, error_message2) end it 'raises an error when trying to aggregate non-PCDM objects in objects aggregation' do - expect { collection1.child_objects << @non_pcdm_object }.to raise_error(error_type2, error_message2) + expect { collection1.objects << @non_pcdm_object }.to raise_error(error_type2, error_message2) end it 'raises an error when trying to aggregate AF::Base objects in objects aggregation' do - expect { collection1.child_objects << @af_base_object }.to raise_error(error_type2, error_message2) + expect { collection1.objects << @af_base_object }.to raise_error(error_type2, error_message2) end end end @@ -310,21 +312,21 @@ class Awbject < Hydra::PCDM::Object describe 'removing objects' do context 'when it is the only object' do before do - subject.child_objects << object1 - expect(subject.child_objects).to eq [object1] + subject.objects << object1 + expect(subject.objects).to eq [object1] end it 'removes object while changes are in memory' do - expect(subject.child_objects.delete object1).to eq [object1] - expect(subject.child_objects).to eq [] + expect(subject.objects.delete object1).to eq [object1] + expect(subject.objects).to eq [] end it 'removes object only when collections and all changes are in memory' do - subject.child_collections << collection1 - subject.child_collections << collection2 - expect(subject.child_objects.delete object1).to eq [object1] - expect(subject.child_objects).to eq [] - expect(subject.child_collections).to eq [collection1, collection2] + subject.collections << collection1 + subject.collections << collection2 + expect(subject.objects.delete object1).to eq [object1] + expect(subject.objects).to eq [] + expect(subject.collections).to eq [collection1, collection2] end end @@ -332,31 +334,31 @@ class Awbject < Hydra::PCDM::Object let(:object3) { Hydra::PCDM::Object.new } before do - subject.child_objects << object1 - subject.child_objects << object2 - subject.child_objects << object3 - expect(subject.child_objects).to eq [object1, object2, object3] + subject.objects << object1 + subject.objects << object2 + subject.objects << object3 + expect(subject.objects).to eq [object1, object2, object3] end it 'removes first object when changes are in memory' do - expect(subject.child_objects.delete object1).to eq [object1] - expect(subject.child_objects).to eq [object2, object3] + expect(subject.objects.delete object1).to eq [object1] + expect(subject.objects).to eq [object2, object3] end it 'removes middle object when changes are in memory' do - expect(subject.child_objects.delete object2).to eq [object2] - expect(subject.child_objects).to eq [object1, object3] + expect(subject.objects.delete object2).to eq [object2] + expect(subject.objects).to eq [object1, object3] end it 'removes last object when changes are in memory' do - expect(subject.child_objects.delete object3).to eq [object3] - expect(subject.child_objects).to eq [object1, object2] + expect(subject.objects.delete object3).to eq [object3] + expect(subject.objects).to eq [object1, object2] end it 'removes middle object when changes are saved' do - expect(subject.child_objects.delete object2).to eq [object2] - expect(subject.child_objects).to eq [object1, object3] + expect(subject.objects.delete object2).to eq [object2] + expect(subject.objects).to eq [object1, object3] subject.save - expect(subject.reload.child_objects).to eq [object1, object3] + expect(subject.reload.objects).to eq [object1, object3] end end @@ -366,45 +368,45 @@ class Awbject < Hydra::PCDM::Object let(:object5) { Hydra::PCDM::Object.new } before do - subject.child_objects << object1 - subject.child_objects << object2 - subject.child_objects << object3 - subject.child_objects << object2 - subject.child_objects << object4 - subject.child_objects << object2 - subject.child_objects << object5 - expect(subject.child_objects).to eq [object1, object2, object3, object2, object4, object2, object5] + subject.objects << object1 + subject.objects << object2 + subject.objects << object3 + subject.objects << object2 + subject.objects << object4 + subject.objects << object2 + subject.objects << object5 + expect(subject.objects).to eq [object1, object2, object3, object2, object4, object2, object5] end # TODO: pending implementation of multiple objects it 'removes first occurrence when changes in memory' do - expect(subject.child_objects.delete object2).to eq [object2] - expect(subject.child_objects).to eq [object1, object3, object4, object5] + expect(subject.objects.delete object2).to eq [object2] + expect(subject.objects).to eq [object1, object3, object4, object5] end it 'removes last occurrence when changes in memory' do skip('pending resolution of AF-agg 46 and PCDM 102') do - expect(subject.child_objects.delete object2, -1).to eq object2 - expect(subject.child_objects).to eq [object1, object2, object3, object2, object4, object5] + expect(subject.objects.delete object2, -1).to eq object2 + expect(subject.objects).to eq [object1, object2, object3, object2, object4, object5] end end it 'removes nth occurrence when changes in memory' do skip('pending resolution of AF-agg 46 and PCDM 102') do - expect(subject.child_objects.delete object2, 2).to eq object2 - expect(subject.child_objects).to eq [object1, object2, object3, object4, object2, object5] + expect(subject.objects.delete object2, 2).to eq object2 + expect(subject.objects).to eq [object1, object2, object3, object4, object2, object5] end end it 'removes nth occurrence when changes are saved' do skip('pending resolution of AF-agg 46 and PCDM 102') do - expect(subject.child_objects).to eq [object1, object2, object3, object2, object4, object2, object5] + expect(subject.objects).to eq [object1, object2, object3, object2, object4, object2, object5] subject.save - expect(subject.reload.child_objects).to eq [object1, object2, object3, object2, object4, object2, object5] + expect(subject.reload.objects).to eq [object1, object2, object3, object2, object4, object2, object5] - expect(subject.child_objects.delete object2, 2).to eq object2 + expect(subject.objects.delete object2, 2).to eq object2 subject.save - expect(subject.reload.child_objects).to eq [object1, object2, object3, object4, object2, object5] + expect(subject.reload.objects).to eq [object1, object2, object3, object4, object2, object5] end end end @@ -413,20 +415,20 @@ class Awbject < Hydra::PCDM::Object let(:object3) { Hydra::PCDM::Object.new } it 'and 0 objects in collection should return empty array' do - expect(subject.child_objects.delete object1).to eq [] + expect(subject.objects.delete object1).to eq [] end it 'and multiple objects in collection should return empty array when changes are in memory' do - subject.child_objects << object1 - subject.child_objects << object2 - expect(subject.child_objects.delete object3).to eq [] + subject.objects << object1 + subject.objects << object2 + expect(subject.objects.delete object3).to eq [] end it 'returns empty array when changes are saved' do - subject.child_objects << object1 - subject.child_objects << object2 + subject.objects << object1 + subject.objects << object2 subject.save - expect(subject.reload.child_objects.delete object3).to eq [] + expect(subject.reload.objects.delete object3).to eq [] end end end @@ -527,14 +529,14 @@ class Awbject < Hydra::PCDM::Object end it 'removes related object only when objects & collections and all changes are in memory' do - subject.child_collections << collection1 - subject.child_collections << collection2 - subject.child_objects << object3 - subject.child_objects << object2 + subject.collections << collection1 + subject.collections << collection2 + subject.objects << object3 + subject.objects << object2 expect(subject.related_objects.delete object1).to eq [object1] expect(subject.related_objects).to eq [] - expect(subject.child_collections).to eq [collection1, collection2] - expect(subject.child_objects).to eq [object3, object2] + expect(subject.collections).to eq [collection1, collection2] + expect(subject.objects).to eq [object3, object2] end end @@ -623,59 +625,99 @@ class Awbject < Hydra::PCDM::Object end end - describe '#child_collections=' do + describe '#collections=' do it 'aggregates collections' do - collection1.child_collections = [collection2, collection3] - expect(collection1.child_collections).to eq [collection2, collection3] + collection1.collections = [collection2, collection3] + expect(collection1.collections).to eq [collection2, collection3] end end - describe '#child_objects=' do + describe '#collections<<' do + before do + collection1.collections = [collection2] + end + it 'aggregates collections' do + collection1.collections << collection3 + expect(collection1.collections).to eq [collection2, collection3] + end + end + + describe '#collections+=' do + before do + collection1.collections = [collection2] + end + it 'aggregates collections' do + collection1.collections += [collection3, collection4] + expect(collection1.collections).to eq [collection2, collection3, collection4] + end + end + + describe '#objects=' do it 'aggregates objects' do - collection1.child_objects = [object1, object2] - expect(collection1.child_objects).to eq [object1, object2] + collection1.objects = [object1, object2] + expect(collection1.objects).to eq [object1, object2] end end - describe '#child_collection_ids' do + describe '#objects<<' do + before do + collection1.objects = [object1] + end + it 'appends object to aggregated objects' do + collection1.objects << object2 + expect(collection1.objects).to eq [object1, object2] + end + end + + describe '#objects+=' do + before do + collection1.objects = [object1] + end + it 'appends object to aggregated objects' do + collection1.objects += [object2, object3] + expect(collection1.objects).to eq [object1, object2, object3] + end + end + + describe '#collection_ids' do let(:child1) { described_class.new(id: '1') } let(:child2) { described_class.new(id: '2') } let(:object) { described_class.new } - before { object.child_collections = [child1, child2] } + before { object.collections = [child1, child2] } - subject { object.child_collection_ids } + subject { object.collection_ids } it { is_expected.to eq %w(1 2) } end - describe 'child_collections and child_objects' do + describe 'collections and objects' do subject { described_class.new } it 'returns empty array when no members' do - expect(subject.child_collections).to eq [] - expect(subject.child_objects).to eq [] + expect(subject.collections).to eq [] + expect(subject.objects).to eq [] end - it 'child_collections should return empty array when only objects are aggregated' do + it 'collections should return empty array when only objects are aggregated' do subject.members << object1 subject.members << object2 - expect(subject.child_collections).to eq [] + expect(subject.collections).to eq [] end - it 'child_objects should return empty array when only collections are aggregated' do + it 'objects should return empty array when only collections are aggregated' do subject.members << collection1 subject.members << collection2 - expect(subject.child_objects).to eq [] + expect(subject.objects).to eq [] end context 'should only contain members of the correct type' do it 'returns only collections' do - subject.child_collections << collection1 + subject.collections << collection1 subject.members << collection2 - subject.child_objects << object1 + subject.objects << object1 subject.members << object2 - expect(subject.child_collections).to eq [collection1, collection2] - expect(subject.child_objects).to eq [object1, object2] + expect(subject.collections).to eq [collection1, collection2] + expect(subject.objects).to eq [object1, object2] expect(subject.members).to eq [collection1, collection2, object1, object2] end end @@ -688,8 +730,8 @@ class Awbject < Hydra::PCDM::Object @collection1 = described_class.new @collection2 = described_class.new @collection = described_class.new - @collection1.child_collections << @collection - @collection2.child_collections << @collection + @collection1.collections << @collection + @collection2.collections << @collection allow(@collection).to receive(:id).and_return('banana') proxies = [ build_proxy(container: @collection1), @@ -698,16 +740,16 @@ class Awbject < Hydra::PCDM::Object allow(ActiveFedora::Aggregation::Proxy).to receive(:where).with(proxyFor_ssim: @collection.id).and_return(proxies) end - describe 'parents' do - subject { @collection.parents } + describe 'member_of' do + subject { @collection.member_of } it 'finds all nodes that aggregate the object with hasMember' do expect(subject).to include(@collection1, @collection2) expect(subject.count).to eq 2 end end - describe 'parent_collections' do - subject { @collection.parent_collections } + describe 'in_collections' do + subject { @collection.in_collections } it 'finds collections that aggregate the object with hasMember' do expect(subject).to include(@collection1, @collection2) expect(subject.count).to eq 2 @@ -758,4 +800,19 @@ class Foo < ActiveFedora::Base it { is_expected.to eq IndexingStuff::AltIndexer } end end + + describe 'make sure deprecated methods still work' do + it 'deprecated methods should pass' do + expect(collection1.child_collections = [collection2]).to eq [collection2] + expect(collection1.child_collections << collection3).to eq [collection2, collection3] + expect(collection1.child_collections += [collection4]).to eq [collection2, collection3, collection4] + expect(collection1.child_objects = [object1]).to eq [object1] + expect(collection1.child_objects << object2).to eq [object1, object2] + expect(collection1.child_objects += [object3]).to eq [object1, object2, object3] + collection1.save # required until issue AF-Agg-75 is fixed + expect(collection2.parent_collections).to eq [collection1] + expect(collection2.parents).to eq [collection1] + expect(collection2.parent_collection_ids).to eq [collection1.id] + end + end end diff --git a/spec/hydra/pcdm/models/file_spec.rb b/spec/hydra/pcdm/models/file_spec.rb index 960304ff..0e0ef126 100644 --- a/spec/hydra/pcdm/models/file_spec.rb +++ b/spec/hydra/pcdm/models/file_spec.rb @@ -28,19 +28,21 @@ let(:content) { 'hello world' } let(:file) { described_class.new.tap { |ds| ds.content = content } } it 'saves technical metadata' do - file.file_name = 'picture.jpg' - file.file_size = content.length.to_s - file.date_created = date_created - file.has_mime_type = 'application/jpg' - file.date_modified = date_modified - file.byte_order = 'little-endian' - expect(file.save).to be true - expect(reloaded.file_name).to eq ['picture.jpg'] - expect(reloaded.file_size).to eq [content.length.to_s] - expect(reloaded.has_mime_type).to eq ['application/jpg'] - expect(reloaded.date_created).to eq [date_created] - expect(reloaded.date_modified).to eq [date_modified] - expect(reloaded.byte_order).to eq ['little-endian'] + skip('pending resolution of PCDM 182') do + file.file_name = 'picture.jpg' + file.file_size = content.length.to_s + file.date_created = date_created + file.has_mime_type = 'application/jpg' + file.date_modified = date_modified + file.byte_order = 'little-endian' + expect(file.save).to be true + expect(reloaded.file_name).to eq ['picture.jpg'] + expect(reloaded.file_size).to eq [content.length.to_s] + expect(reloaded.has_mime_type).to eq ['application/jpg'] + expect(reloaded.date_created).to eq [date_created] + expect(reloaded.date_modified).to eq [date_modified] + expect(reloaded.byte_order).to eq ['little-endian'] + end end it 'does not save server managed properties' do @@ -48,7 +50,7 @@ # complains that it's a server managed property. This test # is mostly to document this situation. file.file_hash = 'the-hash' - expect { file.save }.to raise_error(Ldp::BadRequest) + expect { file.save }.to raise_error(Ldp::Conflict, %r{Could not remove triple containing predicate http://www.loc.gov/premis/rdf/v1#hasMessageDigest to node .*}) end end diff --git a/spec/hydra/pcdm/models/object_spec.rb b/spec/hydra/pcdm/models/object_spec.rb index 489a4d84..e8e25e2e 100644 --- a/spec/hydra/pcdm/models/object_spec.rb +++ b/spec/hydra/pcdm/models/object_spec.rb @@ -1,18 +1,18 @@ require 'spec_helper' describe Hydra::PCDM::Object do - describe '#child_object_ids' do + describe '#object_ids' do let(:child1) { described_class.new(id: '1') } let(:child2) { described_class.new(id: '2') } let(:object) { described_class.new } - before { object.child_objects = [child1, child2] } + before { object.objects = [child1, child2] } - subject { object.child_object_ids } + subject { object.object_ids } it { is_expected.to eq %w(1 2) } end - describe '#child_objects=, +=, <<' do + describe '#objects=, +=, <<' do context 'with acceptable child objects' do let(:object1) { described_class.new } let(:object2) { described_class.new } @@ -21,27 +21,27 @@ let(:object5) { described_class.new } it 'empty when no objects have been added' do - expect(subject.child_objects).to eq [] + expect(subject.objects).to eq [] end it 'add objects' do - subject.child_objects = [object1, object2] - subject.child_objects << object3 - subject.child_objects += [object4, object5] - expect(subject.child_objects).to eq [object1, object2, object3, object4, object5] + subject.objects = [object1, object2] + subject.objects << object3 + subject.objects += [object4, object5] + expect(subject.objects).to eq [object1, object2, object3, object4, object5] end it 'allow sub-objects' do - subject.child_objects = [object1, object2] - object1.child_objects = [object3] - expect(subject.child_objects).to eq [object1, object2] - expect(object1.child_objects).to eq [object3] + subject.objects = [object1, object2] + object1.objects = [object3] + expect(subject.objects).to eq [object1, object2] + expect(object1.objects).to eq [object3] end it 'allow repeating objects' do - subject.child_objects = [object1, object2] - subject.child_objects << object1 - expect(subject.child_objects).to eq [object1, object2, object1] + subject.objects = [object1, object2] + subject.objects << object1 + expect(subject.objects).to eq [object1, object2, object1] end describe 'adding objects that are ancestors' do @@ -50,46 +50,46 @@ context 'when the source object is the same' do it 'raises an error' do - expect { object1.child_objects = [object1] }.to raise_error(error_type, error_message) - expect { object1.child_objects += [object1] }.to raise_error(error_type, error_message) - expect { object1.child_objects << [object1] }.to raise_error(error_type, error_message) + expect { object1.objects = [object1] }.to raise_error(error_type, error_message) + expect { object1.objects += [object1] }.to raise_error(error_type, error_message) + expect { object1.objects << [object1] }.to raise_error(error_type, error_message) end end before do - object1.child_objects = [object2] + object1.objects = [object2] end it 'raises an error' do - expect { object2.child_objects += [object1] }.to raise_error(error_type, error_message) - expect { object2.child_objects << [object1] }.to raise_error(error_type, error_message) - expect { object2.child_objects = [object1] }.to raise_error(error_type, error_message) + expect { object2.objects += [object1] }.to raise_error(error_type, error_message) + expect { object2.objects << [object1] }.to raise_error(error_type, error_message) + expect { object2.objects = [object1] }.to raise_error(error_type, error_message) end context 'with more ancestors' do before do - object2.child_objects = [object3] + object2.objects = [object3] end it 'raises an error' do - expect { object3.child_objects << [object1] }.to raise_error(error_type, error_message) - expect { object3.child_objects = [object1] }.to raise_error(error_type, error_message) - expect { object3.child_objects += [object1] }.to raise_error(error_type, error_message) + expect { object3.objects << [object1] }.to raise_error(error_type, error_message) + expect { object3.objects = [object1] }.to raise_error(error_type, error_message) + expect { object3.objects += [object1] }.to raise_error(error_type, error_message) end context 'with a more complicated example' do before do - object3.child_objects = [object4, object5] + object3.objects = [object4, object5] end it 'raises errors' do - expect { object4.child_objects = [object1] }.to raise_error(error_type, error_message) - expect { object4.child_objects += [object1] }.to raise_error(error_type, error_message) - expect { object4.child_objects << [object1] }.to raise_error(error_type, error_message) + expect { object4.objects = [object1] }.to raise_error(error_type, error_message) + expect { object4.objects += [object1] }.to raise_error(error_type, error_message) + expect { object4.objects << [object1] }.to raise_error(error_type, error_message) - expect { object4.child_objects = [object2] }.to raise_error(error_type, error_message) - expect { object4.child_objects += [object2] }.to raise_error(error_type, error_message) - expect { object4.child_objects << [object2] }.to raise_error(error_type, error_message) + expect { object4.objects = [object2] }.to raise_error(error_type, error_message) + expect { object4.objects += [object2] }.to raise_error(error_type, error_message) + expect { object4.objects << [object2] }.to raise_error(error_type, error_message) end end end @@ -111,27 +111,27 @@ let(:error_message2) { /undefined method `pcdm_object\?' for .*/ } it 'NOT aggregate Hydra::PCDM::Collection in objects aggregation' do - expect { @object101.child_objects = [@collection101] }.to raise_error(error_type1, error_message1) - expect { @object101.child_objects += [@collection101] }.to raise_error(error_type1, error_message1) - expect { @object101.child_objects << @collection101 }.to raise_error(error_type1, error_message1) + expect { @object101.objects = [@collection101] }.to raise_error(error_type1, error_message1) + expect { @object101.objects += [@collection101] }.to raise_error(error_type1, error_message1) + expect { @object101.objects << @collection101 }.to raise_error(error_type1, error_message1) end it 'NOT aggregate Hydra::PCDM::Files in objects aggregation' do - expect { @object101.child_objects += [@file1] }.to raise_error(error_type2, error_message2) - expect { @object101.child_objects << @file1 }.to raise_error(error_type2, error_message2) - expect { @object101.child_objects = [@file1] }.to raise_error(error_type2, error_message2) + expect { @object101.objects += [@file1] }.to raise_error(error_type2, error_message2) + expect { @object101.objects << @file1 }.to raise_error(error_type2, error_message2) + expect { @object101.objects = [@file1] }.to raise_error(error_type2, error_message2) end it 'NOT aggregate non-PCDM objects in objects aggregation' do - expect { @object101.child_objects << @non_pcdm_object }.to raise_error(error_type2, error_message2) - expect { @object101.child_objects = [@non_pcdm_object] }.to raise_error(error_type2, error_message2) - expect { @object101.child_objects += [@non_pcdm_object] }.to raise_error(error_type2, error_message2) + expect { @object101.objects << @non_pcdm_object }.to raise_error(error_type2, error_message2) + expect { @object101.objects = [@non_pcdm_object] }.to raise_error(error_type2, error_message2) + expect { @object101.objects += [@non_pcdm_object] }.to raise_error(error_type2, error_message2) end it 'NOT aggregate AF::Base objects in objects aggregation' do - expect { @object101.child_objects = [@af_base_object] }.to raise_error(error_type2, error_message2) - expect { @object101.child_objects += [@af_base_object] }.to raise_error(error_type2, error_message2) - expect { @object101.child_objects << @af_base_object }.to raise_error(error_type2, error_message2) + expect { @object101.objects = [@af_base_object] }.to raise_error(error_type2, error_message2) + expect { @object101.objects += [@af_base_object] }.to raise_error(error_type2, error_message2) + expect { @object101.objects << @af_base_object }.to raise_error(error_type2, error_message2) end end end @@ -278,21 +278,21 @@ allow(ActiveFedora::Aggregation::Proxy).to receive(:where).with(proxyFor_ssim: @object.id).and_return(proxies) end - describe 'parents' do - subject { @object.parents } + describe 'member_of' do + subject { @object.member_of } it 'finds all nodes that aggregate the object with hasMember' do expect(subject).to include(@collection1, @collection2, @parent_object) end end - describe 'parent_objects' do - subject { @object.parent_objects } + describe 'in_objects' do + subject { @object.in_objects } it 'finds objects that aggregate the object with hasMember' do expect(subject).to eq [@parent_object] end end - describe 'parent_collections' do - subject { @object.parent_collections } + describe 'in_collections' do + subject { @object.in_collections } it 'finds collections that aggregate the object with hasMember' do expect(subject).to include(@collection1, @collection2) expect(subject.count).to eq 2 @@ -490,94 +490,94 @@ def build_proxy(container:) context 'when it is the only object' do before do - subject.child_objects += [object1] - expect(subject.child_objects).to eq [object1] + subject.objects += [object1] + expect(subject.objects).to eq [object1] end it 'remove object while changes are in memory' do - expect(subject.child_objects.delete object1).to eq [object1] - expect(subject.child_objects).to eq [] + expect(subject.objects.delete object1).to eq [object1] + expect(subject.objects).to eq [] end end context 'when multiple objects' do before do - subject.child_objects += [object1, object2, object3] - expect(subject.child_objects).to eq [object1, object2, object3] + subject.objects += [object1, object2, object3] + expect(subject.objects).to eq [object1, object2, object3] end it 'remove first object when changes are in memory' do - expect(subject.child_objects.delete object1).to eq [object1] - expect(subject.child_objects).to eq [object2, object3] + expect(subject.objects.delete object1).to eq [object1] + expect(subject.objects).to eq [object2, object3] end it 'remove last object when changes are in memory' do - expect(subject.child_objects.delete object3).to eq [object3] - expect(subject.child_objects).to eq [object1, object2] + expect(subject.objects.delete object3).to eq [object3] + expect(subject.objects).to eq [object1, object2] end it 'remove middle object when changes are in memory' do - expect(subject.child_objects.delete object2).to eq [object2] - expect(subject.child_objects).to eq [object1, object3] + expect(subject.objects.delete object2).to eq [object2] + expect(subject.objects).to eq [object1, object3] end it 'remove middle object when changes are saved' do subject.save - expect(subject.child_objects).to eq [object1, object2, object3] - expect(subject.child_objects.delete object2).to eq [object2] - expect(subject.child_objects).to eq [object1, object3] + expect(subject.objects).to eq [object1, object2, object3] + expect(subject.objects.delete object2).to eq [object2] + expect(subject.objects).to eq [object1, object3] end end context 'when object repeats' do before do - subject.child_objects += [object1, object2, object3, object2, object3] - expect(subject.child_objects).to eq [object1, object2, object3, object2, object3] + subject.objects += [object1, object2, object3, object2, object3] + expect(subject.objects).to eq [object1, object2, object3, object2, object3] end it 'remove first occurrence when changes in memory' do - expect(subject.child_objects.delete object2).to eq [object2] - expect(subject.child_objects).to eq [object1, object3, object3] + expect(subject.objects.delete object2).to eq [object2] + expect(subject.objects).to eq [object1, object3, object3] end it 'remove last occurrence when changes in memory' do skip('pending resolution of AF-agg 46 and PCDM 102') do - expect(subject.child_objects.delete object2, -1).to eq object2 - expect(subject.child_objects).to eq [object1, object2, object3, object3] + expect(subject.objects.delete object2, -1).to eq object2 + expect(subject.objects).to eq [object1, object2, object3, object3] end end it 'remove nth occurrence when changes in memory' do skip('pending resolution of AF-agg 46 and PCDM 102') do - expect(subject.child_objects.delete object2, 2).to eq object2 - expect(subject.child_objects).to eq [object1, object2, object3, object3] + expect(subject.objects.delete object2, 2).to eq object2 + expect(subject.objects).to eq [object1, object2, object3, object3] end end it 'remove nth occurrence when changes are saved' do skip('pending resolution of AF-agg 46 and PCDM 102') do - expect(subject.child_objects).to eq [object1, object2, object3, object2, object3] - expect(subject.child_objects).to eq [object1, object2, object3, object2, object3] + expect(subject.objects).to eq [object1, object2, object3, object2, object3] + expect(subject.objects).to eq [object1, object2, object3, object2, object3] - expect(subject.child_objects.delete object2, 2).to eq object2 + expect(subject.objects.delete object2, 2).to eq object2 subject.save - expect(subject.child_objects).to eq [object1, object2, object3, object2, object3] + expect(subject.objects).to eq [object1, object2, object3, object2, object3] end end end context 'when object is missing' do it 'and 0 objects in object return empty array' do - expect(subject.child_objects.delete object1).to eq [] + expect(subject.objects.delete object1).to eq [] end it 'and multiple objects in object return empty array when changes are in memory' do - subject.child_objects += [object1, object2] - expect(subject.child_objects.delete object3).to eq [] + subject.objects += [object1, object2] + expect(subject.objects.delete object3).to eq [] end it 'return empty array when changes are saved' do - subject.child_objects += [object1, object2] - expect(subject.child_objects.delete object3).to eq [] + subject.objects += [object1, object2] + expect(subject.objects.delete object3).to eq [] end end end @@ -685,4 +685,20 @@ class Foo < ActiveFedora::Base it { is_expected.to eq IndexingStuff::AltIndexer } end end + + describe 'make sure deprecated methods still work' do + let(:object1) { described_class.new } + let(:object2) { described_class.new } + let(:object3) { described_class.new } + let(:object4) { described_class.new } + + it 'deprecated methods should pass' do + expect(object1.child_objects = [object2]).to eq [object2] + expect(object1.child_objects << object3).to eq [object2, object3] + expect(object1.child_objects += [object4]).to eq [object2, object3, object4] + object1.save # required until issue AF-Agg-75 is fixed + expect(object2.parent_objects).to eq [object1] + expect(object2.parents).to eq [object1] + end + end end diff --git a/spec/hydra/pcdm/object_indexer_spec.rb b/spec/hydra/pcdm/object_indexer_spec.rb index d62cf175..435d10c1 100644 --- a/spec/hydra/pcdm/object_indexer_spec.rb +++ b/spec/hydra/pcdm/object_indexer_spec.rb @@ -7,14 +7,14 @@ let(:indexer) { described_class.new(object) } before do - allow(object).to receive(:child_object_ids).and_return([child_object1.id, child_object2.id]) + allow(object).to receive(:object_ids).and_return([child_object1.id, child_object2.id]) end describe '#generate_solr_document' do subject { indexer.generate_solr_document } it 'has fields' do - expect(subject['child_object_ids_ssim']).to eq %w(123 456) + expect(subject['object_ids_ssim']).to eq %w(123 456) end end end