hydra-pcdm 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile +0 -4
- data/README.md +2 -2
- data/hydra-pcdm.gemspec +2 -1
- data/lib/hydra/pcdm.rb +21 -30
- data/lib/hydra/pcdm/ancestor_checker.rb +18 -0
- data/lib/hydra/pcdm/collection_indexer.rb +2 -2
- data/lib/hydra/pcdm/deep_member_iterator.rb +31 -0
- data/lib/hydra/pcdm/models/concerns/collection_behavior.rb +20 -57
- data/lib/hydra/pcdm/models/concerns/object_behavior.rb +12 -37
- data/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb +34 -0
- data/lib/hydra/pcdm/object_indexer.rb +1 -1
- data/lib/hydra/pcdm/services/file/get_mime_type.rb +1 -1
- data/lib/hydra/pcdm/validators.rb +8 -0
- data/lib/hydra/pcdm/validators/ancestor_validator.rb +26 -0
- data/lib/hydra/pcdm/validators/composite_validator.rb +17 -0
- data/lib/hydra/pcdm/validators/pcdm_object_validator.rb +9 -0
- data/lib/hydra/pcdm/validators/pcdm_validator.rb +9 -0
- data/lib/hydra/pcdm/version.rb +1 -1
- data/lib/hydra/pcdm/vocab/pcdm_terms.rb +1 -1
- data/spec/hydra/pcdm/ancestor_checker_spec.rb +29 -0
- data/spec/hydra/pcdm/collection_indexer_spec.rb +11 -11
- data/spec/hydra/pcdm/deep_member_iterator_spec.rb +52 -0
- data/spec/hydra/pcdm/models/collection_spec.rb +691 -17
- data/spec/hydra/pcdm/models/file_spec.rb +16 -0
- data/spec/hydra/pcdm/models/object_spec.rb +576 -27
- data/spec/hydra/pcdm/object_indexer_spec.rb +6 -6
- data/spec/spec_helper.rb +8 -1
- metadata +31 -52
- data/lib/hydra/pcdm/services/collection/add_collection.rb +0 -20
- data/lib/hydra/pcdm/services/collection/add_object.rb +0 -19
- data/lib/hydra/pcdm/services/collection/add_related_object.rb +0 -21
- data/lib/hydra/pcdm/services/collection/get_collections.rb +0 -18
- data/lib/hydra/pcdm/services/collection/get_objects.rb +0 -18
- data/lib/hydra/pcdm/services/collection/get_related_objects.rb +0 -17
- data/lib/hydra/pcdm/services/collection/remove_collection.rb +0 -36
- data/lib/hydra/pcdm/services/collection/remove_object.rb +0 -43
- data/lib/hydra/pcdm/services/collection/remove_related_object.rb +0 -36
- data/lib/hydra/pcdm/services/object/add_object.rb +0 -20
- data/lib/hydra/pcdm/services/object/add_related_object.rb +0 -21
- data/lib/hydra/pcdm/services/object/get_objects.rb +0 -18
- data/lib/hydra/pcdm/services/object/get_related_objects.rb +0 -17
- data/lib/hydra/pcdm/services/object/remove_object.rb +0 -43
- data/lib/hydra/pcdm/services/object/remove_related_object.rb +0 -36
- data/spec/hydra/pcdm/services/collection/add_collection_spec.rb +0 -197
- data/spec/hydra/pcdm/services/collection/add_object_spec.rb +0 -132
- data/spec/hydra/pcdm/services/collection/add_related_object_spec.rb +0 -94
- data/spec/hydra/pcdm/services/collection/get_collections_spec.rb +0 -40
- data/spec/hydra/pcdm/services/collection/get_objects_spec.rb +0 -40
- data/spec/hydra/pcdm/services/collection/get_related_objects_spec.rb +0 -37
- data/spec/hydra/pcdm/services/collection/remove_collection_spec.rb +0 -143
- data/spec/hydra/pcdm/services/collection/remove_object_spec.rb +0 -180
- data/spec/hydra/pcdm/services/collection/remove_related_object_spec.rb +0 -146
- data/spec/hydra/pcdm/services/file/add_type_spec.rb +0 -19
- data/spec/hydra/pcdm/services/object/add_object_spec.rb +0 -186
- data/spec/hydra/pcdm/services/object/add_related_object_spec.rb +0 -94
- data/spec/hydra/pcdm/services/object/get_objects_spec.rb +0 -33
- data/spec/hydra/pcdm/services/object/get_related_objects_spec.rb +0 -39
- data/spec/hydra/pcdm/services/object/remove_object_spec.rb +0 -158
- data/spec/hydra/pcdm/services/object/remove_related_object_spec.rb +0 -126
@@ -1,21 +0,0 @@
|
|
1
|
-
module Hydra::PCDM
|
2
|
-
class AddRelatedObjectToObject
|
3
|
-
|
4
|
-
##
|
5
|
-
# Add a related object to an object.
|
6
|
-
#
|
7
|
-
# @param [Hydra::PCDM::Object] :parent_object to which to add the related object
|
8
|
-
# @param [Hydra::PCDM::Object] :child_related_object being added
|
9
|
-
#
|
10
|
-
# @return [Hydra::PCDM::Object] the updated pcdm object
|
11
|
-
|
12
|
-
def self.call( parent_object, child_related_object )
|
13
|
-
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
|
14
|
-
raise ArgumentError, "child_related_object must be a pcdm object" unless Hydra::PCDM.object? child_related_object
|
15
|
-
|
16
|
-
# parent_object.related_objects = parent_object.related_objects + child_related_object
|
17
|
-
parent_object.related_objects << child_related_object
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Hydra::PCDM
|
2
|
-
class GetObjectsFromObject
|
3
|
-
|
4
|
-
##
|
5
|
-
# Get member objects from an object in order.
|
6
|
-
#
|
7
|
-
# @param [Hydra::PCDM::Object] :parent_object in which the child objects are members
|
8
|
-
#
|
9
|
-
# @return [Array<Hydra::PCDM::Object>] all member objects
|
10
|
-
|
11
|
-
def self.call( parent_object )
|
12
|
-
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
|
13
|
-
|
14
|
-
parent_object.objects
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Hydra::PCDM
|
2
|
-
class GetRelatedObjectsFromObject
|
3
|
-
|
4
|
-
##
|
5
|
-
# Get related objects from an object.
|
6
|
-
#
|
7
|
-
# @param [Hydra::PCDM::Object] :parent_object to which the child objects are related
|
8
|
-
#
|
9
|
-
# @return [Array<Hydra::PCDM::Object>] all related objects
|
10
|
-
|
11
|
-
def self.call( parent_object )
|
12
|
-
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
|
13
|
-
parent_object.related_objects.to_a
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Hydra::PCDM
|
2
|
-
class RemoveObjectFromObject
|
3
|
-
|
4
|
-
##
|
5
|
-
# Remove an object from an object.
|
6
|
-
#
|
7
|
-
# @param [Hydra::PCDM::Object] :parent_object from which to remove object
|
8
|
-
# @param [Hydra::PCDM::Object] :child_object being removed
|
9
|
-
# @param [Fixnum] :nth_occurrence remove nth occurrence of this object in the list (default=1)
|
10
|
-
#
|
11
|
-
# @return [Hydra::PCDM::Object] the updated pcdm object
|
12
|
-
|
13
|
-
def self.call( parent_object, child_object, nth_occurrence=1 )
|
14
|
-
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
|
15
|
-
raise ArgumentError, "child_object must be a pcdm object" unless Hydra::PCDM.object? child_object
|
16
|
-
|
17
|
-
|
18
|
-
# TODO FIX when members is empty, members.delete raises ActiveFedora::ObjectNotFoundError "Can't reload an object that hasn't been saved" (activefedora-aggregation issue #35)
|
19
|
-
|
20
|
-
# TODO members.delete should... (issue #103)(activefedora-aggregation issue #34)
|
21
|
-
# * return child_object when successful delete (not Array [child_object])
|
22
|
-
# * return nil if child_object does not exist in parent_object
|
23
|
-
# * raise error for any other problems
|
24
|
-
|
25
|
-
# TODO Per issue #103, uncomment the following line when (activefedora-aggregation issue #34) is resolved
|
26
|
-
# parent_object.members.delete child_object
|
27
|
-
|
28
|
-
# TODO Per issue #103, remove the following lines when (activefedora-aggregation issue #34) is resolved
|
29
|
-
return nil unless parent_object.members.include? child_object
|
30
|
-
removed_object = parent_object.members.delete child_object
|
31
|
-
removed_object = removed_object.first if removed_object.is_a? Array
|
32
|
-
removed_object
|
33
|
-
# END WORK-AROUND
|
34
|
-
|
35
|
-
|
36
|
-
# TODO -- The same object may be in the list multiple times. (issue #102)
|
37
|
-
# * How to remove nth occurrence?
|
38
|
-
# * Default to removing 1st occurrence from the beginning of the list.
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Hydra::PCDM
|
2
|
-
class RemoveRelatedObjectFromObject
|
3
|
-
|
4
|
-
##
|
5
|
-
# Remove an object from an object.
|
6
|
-
#
|
7
|
-
# @param [Hydra::PCDM::Object] :parent_object from which to remove the related object
|
8
|
-
# @param [Hydra::PCDM::Object] :child_related_object being removed
|
9
|
-
#
|
10
|
-
# @return [Hydra::PCDM::Collection] the updated pcdm collection
|
11
|
-
|
12
|
-
def self.call( parent_object, child_related_object )
|
13
|
-
raise ArgumentError, "parent_object must be a pcdm object" unless Hydra::PCDM.object? parent_object
|
14
|
-
raise ArgumentError, "child_related_object must be a pcdm object" unless Hydra::PCDM.object? child_related_object
|
15
|
-
|
16
|
-
|
17
|
-
# TODO FIX when related_objects is empty, related_objects.delete raises ActiveFedora::ObjectNotFoundError "Can't reload an object that hasn't been saved" (activefedora-aggregation issue #805)
|
18
|
-
|
19
|
-
# TODO related_objects.delete should... (issue #103)(activefedora-aggregation issue #805)
|
20
|
-
# * return child_related_object when successful delete (not Array [child_related_object])
|
21
|
-
# * return nil if child_related_object does not exist in parent_object
|
22
|
-
# * raise error for any other problems
|
23
|
-
|
24
|
-
# TODO Per issue #103, uncomment the following line when (activefedora issue #805) is resolved
|
25
|
-
# parent_object.related_objects.delete child_related_object
|
26
|
-
|
27
|
-
# TODO Per issue #103, remove the following lines when (activefedora issue #805) is resolved
|
28
|
-
return nil unless Hydra::PCDM::GetRelatedObjectsFromObject.call( parent_object ).include? child_related_object
|
29
|
-
removed_related_object = parent_object.related_objects.delete child_related_object
|
30
|
-
removed_related_object = removed_related_object.first if removed_related_object.is_a? Array
|
31
|
-
removed_related_object
|
32
|
-
# END WORK-AROUND
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
@@ -1,197 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::PCDM::AddCollectionToCollection do
|
4
|
-
|
5
|
-
subject { Hydra::PCDM::Collection.create }
|
6
|
-
|
7
|
-
describe '#call' do
|
8
|
-
context 'with acceptable collections' do
|
9
|
-
let(:collection1) { Hydra::PCDM::Collection.create }
|
10
|
-
let(:collection2) { Hydra::PCDM::Collection.create }
|
11
|
-
let(:collection3) { Hydra::PCDM::Collection.create }
|
12
|
-
let(:collection4) { Hydra::PCDM::Collection.create }
|
13
|
-
let(:object1) { Hydra::PCDM::Object.create }
|
14
|
-
let(:object2) { Hydra::PCDM::Object.create }
|
15
|
-
|
16
|
-
it 'should add a collection to empty collection' do
|
17
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
18
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should add a collection to collection with collections' do
|
22
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
23
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
24
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1,collection2]
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should aggregate collections in a sub-collection of a collection' do
|
28
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
29
|
-
Hydra::PCDM::AddCollectionToCollection.call( collection1, collection2 )
|
30
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1]
|
31
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( collection1 ) ).to eq [collection2]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'should allow collections to repeat' do
|
35
|
-
skip 'skipping this test because issue #94 needs to be addressed' do
|
36
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
37
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
38
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
39
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1,collection2,collection1]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
context 'with collections and objects' do
|
44
|
-
before do
|
45
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
46
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
47
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
48
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
49
|
-
subject.save
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should add an object to collection with collections and objects' do
|
53
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection3 )
|
54
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [collection1,collection2,collection3]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "adding collections that are ancestors" do
|
59
|
-
let(:error_message) { "a collection can't be an ancestor of itself" }
|
60
|
-
|
61
|
-
context "when the source collection is the same" do
|
62
|
-
it "raises an error" do
|
63
|
-
|
64
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, subject ) }.to raise_error(ArgumentError, error_message)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
before do
|
69
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
70
|
-
subject.save
|
71
|
-
end
|
72
|
-
|
73
|
-
it "raises and error" do
|
74
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection1, subject ) }.to raise_error(ArgumentError, error_message)
|
75
|
-
end
|
76
|
-
|
77
|
-
context "with more ancestors" do
|
78
|
-
before do
|
79
|
-
Hydra::PCDM::AddCollectionToCollection.call( collection1, collection2 )
|
80
|
-
collection2.save
|
81
|
-
end
|
82
|
-
|
83
|
-
it "raises an error" do
|
84
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection2, subject ) }.to raise_error(ArgumentError, error_message)
|
85
|
-
end
|
86
|
-
|
87
|
-
context "with a more complicated example" do
|
88
|
-
before do
|
89
|
-
Hydra::PCDM::AddCollectionToCollection.call( collection2, collection3 )
|
90
|
-
Hydra::PCDM::AddCollectionToCollection.call( collection2, collection4 )
|
91
|
-
collection2.save
|
92
|
-
end
|
93
|
-
|
94
|
-
it "raises errors" do
|
95
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection3, subject ) }.to raise_error(ArgumentError, error_message)
|
96
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( collection3, collection1 ) }.to raise_error(ArgumentError, error_message)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe 'aggregates collections that implement Hydra::PCDM' do
|
103
|
-
before do
|
104
|
-
class Kollection < ActiveFedora::Base
|
105
|
-
include Hydra::PCDM::CollectionBehavior
|
106
|
-
end
|
107
|
-
end
|
108
|
-
after { Object.send(:remove_const, :Kollection) }
|
109
|
-
let(:kollection1) { Kollection.create }
|
110
|
-
|
111
|
-
it 'should accept implementing collection as a child' do
|
112
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, kollection1 )
|
113
|
-
subject.save
|
114
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [kollection1]
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'should accept implementing collection as a parent' do
|
118
|
-
Hydra::PCDM::AddCollectionToCollection.call( kollection1, collection1 )
|
119
|
-
subject.save
|
120
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( kollection1 ) ).to eq [collection1]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe 'aggregates collections that extend Hydra::PCDM' do
|
125
|
-
before do
|
126
|
-
class Cullection < Hydra::PCDM::Collection
|
127
|
-
end
|
128
|
-
end
|
129
|
-
after { Object.send(:remove_const, :Cullection) }
|
130
|
-
let(:cullection1) { Cullection.create }
|
131
|
-
|
132
|
-
it 'should accept extending collection as a child' do
|
133
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, cullection1 )
|
134
|
-
subject.save
|
135
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( subject ) ).to eq [cullection1]
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should accept extending collection as a parent' do
|
139
|
-
Hydra::PCDM::AddCollectionToCollection.call( cullection1, collection1 )
|
140
|
-
subject.save
|
141
|
-
expect( Hydra::PCDM::GetCollectionsFromCollection.call( cullection1 ) ).to eq [collection1]
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context 'with unacceptable collections' do
|
147
|
-
let(:object1) { Hydra::PCDM::Object.create }
|
148
|
-
let(:file1) { Hydra::PCDM::File.new }
|
149
|
-
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
150
|
-
let(:af_base_object) { ActiveFedora::Base.create }
|
151
|
-
|
152
|
-
let(:error_message) { 'child_collection must be a pcdm collection' }
|
153
|
-
|
154
|
-
it 'should NOT aggregate Hydra::PCDM::Objects in collections aggregation' do
|
155
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, object1 ) }.to raise_error(ArgumentError,error_message)
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'should NOT aggregate Hydra::PCDM::Files in collections aggregation' do
|
159
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, file1 ) }.to raise_error(ArgumentError,error_message)
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should NOT aggregate non-PCDM objects in collections aggregation' do
|
163
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should NOT aggregate AF::Base objects in collections aggregation' do
|
167
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'with unacceptable parent collection' do
|
172
|
-
let(:collection2) { Hydra::PCDM::Collection.create }
|
173
|
-
let(:object1) { Hydra::PCDM::Object.create }
|
174
|
-
let(:file1) { Hydra::PCDM::File.new }
|
175
|
-
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
176
|
-
let(:af_base_object) { ActiveFedora::Base.create }
|
177
|
-
|
178
|
-
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
179
|
-
|
180
|
-
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
181
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( object1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
185
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( file1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should NOT accept non-PCDM objects as parent collection' do
|
189
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( non_PCDM_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'should NOT accept AF::Base objects as parent collection' do
|
193
|
-
expect{ Hydra::PCDM::AddCollectionToCollection.call( af_base_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::PCDM::AddObjectToCollection do
|
4
|
-
|
5
|
-
let(:subject) { Hydra::PCDM::Collection.create }
|
6
|
-
|
7
|
-
describe '#call' do
|
8
|
-
context 'with acceptable objects' do
|
9
|
-
let(:object1) { Hydra::PCDM::Object.create }
|
10
|
-
let(:object2) { Hydra::PCDM::Object.create }
|
11
|
-
let(:object3) { Hydra::PCDM::Object.create }
|
12
|
-
let(:collection1) { Hydra::PCDM::Collection.create }
|
13
|
-
let(:collection2) { Hydra::PCDM::Collection.create }
|
14
|
-
|
15
|
-
it 'should add an object to empty collection' do
|
16
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
17
|
-
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1]
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should add an object to collection with objects' do
|
21
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
22
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
23
|
-
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1,object2]
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should allow objects to repeat' do
|
27
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
28
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
29
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
30
|
-
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1,object2,object1]
|
31
|
-
end
|
32
|
-
|
33
|
-
context 'with collections and objects' do
|
34
|
-
before do
|
35
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection1 )
|
36
|
-
Hydra::PCDM::AddCollectionToCollection.call( subject, collection2 )
|
37
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object1 )
|
38
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object2 )
|
39
|
-
subject.save
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should add an object to collection with collections and objects' do
|
43
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, object3 )
|
44
|
-
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [object1,object2,object3]
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'aggregates objects that implement Hydra::PCDM' do
|
49
|
-
before do
|
50
|
-
class Ahbject < ActiveFedora::Base
|
51
|
-
include Hydra::PCDM::ObjectBehavior
|
52
|
-
end
|
53
|
-
end
|
54
|
-
after { Object.send(:remove_const, :Ahbject) }
|
55
|
-
let(:ahbject1) { Ahbject.create }
|
56
|
-
|
57
|
-
it 'should accept implementing object as a child' do
|
58
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, ahbject1 )
|
59
|
-
subject.save
|
60
|
-
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [ahbject1]
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'aggregates objects that extend Hydra::PCDM' do
|
66
|
-
before do
|
67
|
-
class Awbject < Hydra::PCDM::Object
|
68
|
-
end
|
69
|
-
end
|
70
|
-
after { Object.send(:remove_const, :Awbject) }
|
71
|
-
let(:awbject1) { Awbject.create }
|
72
|
-
|
73
|
-
it 'should accept extending object as a child' do
|
74
|
-
Hydra::PCDM::AddObjectToCollection.call( subject, awbject1 )
|
75
|
-
subject.save
|
76
|
-
expect( Hydra::PCDM::GetObjectsFromCollection.call( subject ) ).to eq [awbject1]
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context 'with unacceptable objects' do
|
82
|
-
let(:collection1) { Hydra::PCDM::Collection.create }
|
83
|
-
let(:file1) { Hydra::PCDM::File.new }
|
84
|
-
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
85
|
-
let(:af_base_object) { ActiveFedora::Base.create }
|
86
|
-
|
87
|
-
let(:error_message) { 'child_object must be a pcdm object' }
|
88
|
-
|
89
|
-
it 'should NOT aggregate Hydra::PCDM::Collection in objects aggregation' do
|
90
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, collection1 ) }.to raise_error(ArgumentError,error_message)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should NOT aggregate Hydra::PCDM::Files in objects aggregation' do
|
94
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, file1 ) }.to raise_error(ArgumentError,error_message)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'should NOT aggregate non-PCDM objects in objects aggregation' do
|
98
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, non_PCDM_object ) }.to raise_error(ArgumentError,error_message)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should NOT aggregate AF::Base objects in objects aggregation' do
|
102
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( subject, af_base_object ) }.to raise_error(ArgumentError,error_message)
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context 'with unacceptable parent collection' do
|
107
|
-
let(:collection2) { Hydra::PCDM::Collection.create }
|
108
|
-
let(:object1) { Hydra::PCDM::Object.create }
|
109
|
-
let(:file1) { Hydra::PCDM::File.new }
|
110
|
-
let(:non_PCDM_object) { "I'm not a PCDM object" }
|
111
|
-
let(:af_base_object) { ActiveFedora::Base.create }
|
112
|
-
|
113
|
-
let(:error_message) { 'parent_collection must be a pcdm collection' }
|
114
|
-
|
115
|
-
it 'should NOT accept Hydra::PCDM::Objects as parent collection' do
|
116
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( object1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'should NOT accept Hydra::PCDM::Files as parent collection' do
|
120
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( file1, collection2 ) }.to raise_error(ArgumentError,error_message)
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should NOT accept non-PCDM objects as parent collection' do
|
124
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( non_PCDM_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should NOT accept AF::Base objects as parent collection' do
|
128
|
-
expect{ Hydra::PCDM::AddObjectToCollection.call( af_base_object, collection2 ) }.to raise_error(ArgumentError,error_message)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|