hydra-pcdm 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +38 -0
- data/Gemfile +6 -3
- data/README.md +31 -38
- data/Rakefile +14 -4
- data/hydra-pcdm.gemspec +10 -10
- data/lib/hydra/pcdm.rb +13 -12
- data/lib/hydra/pcdm/collection_indexer.rb +2 -4
- data/lib/hydra/pcdm/deep_member_iterator.rb +1 -1
- data/lib/hydra/pcdm/models/collection.rb +0 -1
- data/lib/hydra/pcdm/models/concerns/collection_behavior.rb +18 -5
- data/lib/hydra/pcdm/models/concerns/object_behavior.rb +13 -17
- data/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb +50 -9
- data/lib/hydra/pcdm/models/file.rb +7 -7
- data/lib/hydra/pcdm/models/object.rb +0 -1
- data/lib/hydra/pcdm/object_indexer.rb +1 -2
- data/lib/hydra/pcdm/services/file/add_type.rb +1 -3
- data/lib/hydra/pcdm/services/file/get_mime_type.rb +2 -4
- data/lib/hydra/pcdm/validators/ancestor_validator.rb +3 -11
- data/lib/hydra/pcdm/validators/pcdm_object_validator.rb +2 -2
- data/lib/hydra/pcdm/validators/pcdm_validator.rb +2 -2
- data/lib/hydra/pcdm/version.rb +1 -1
- data/lib/hydra/pcdm/vocab/pcdm_terms.rb +81 -80
- data/lib/hydra/pcdm/vocab/sweet_jpl_terms.rb +12 -0
- data/spec/hydra/pcdm/ancestor_checker_spec.rb +7 -7
- data/spec/hydra/pcdm/collection_indexer_spec.rb +12 -13
- data/spec/hydra/pcdm/deep_member_iterator_spec.rb +16 -16
- data/spec/hydra/pcdm/models/collection_spec.rb +375 -313
- data/spec/hydra/pcdm/models/file_spec.rb +38 -38
- data/spec/hydra/pcdm/models/object_spec.rb +270 -256
- data/spec/hydra/pcdm/object_indexer_spec.rb +4 -4
- data/spec/hydra/pcdm/services/file/get_mime_type_spec.rb +10 -12
- data/spec/hydra/pcdm_spec.rb +21 -26
- metadata +19 -5
- data/lib/hydra/pcdm/vocab/ebucore_terms.rb +0 -33
- data/lib/hydra/pcdm/vocab/sweetjpl_terms.rb +0 -10
@@ -4,45 +4,45 @@ RSpec.describe Hydra::PCDM::DeepMemberIterator do
|
|
4
4
|
subject { described_class.new(record) }
|
5
5
|
let(:record) { instance_double(Hydra::PCDM::Object, members: members) }
|
6
6
|
let(:members) { [] }
|
7
|
-
describe
|
8
|
-
context
|
9
|
-
it
|
7
|
+
describe '#each' do
|
8
|
+
context 'with no members' do
|
9
|
+
it 'returns an empty array' do
|
10
10
|
expect(subject.to_a).to eq []
|
11
11
|
end
|
12
12
|
end
|
13
|
-
context
|
14
|
-
let(:members) { [
|
15
|
-
it
|
13
|
+
context 'with a member' do
|
14
|
+
let(:members) { [instance_double(Hydra::PCDM::Object, members: [])] }
|
15
|
+
it 'returns that member' do
|
16
16
|
expect(subject.to_a).to eq members
|
17
17
|
end
|
18
18
|
end
|
19
|
-
context
|
19
|
+
context 'with deep members' do
|
20
20
|
let(:member_1) { instance_double(Hydra::PCDM::Object, members: [member_3]) }
|
21
21
|
let(:member_2) { instance_double(Hydra::PCDM::Object, members: [member_4]) }
|
22
22
|
let(:member_3) { instance_double(Hydra::PCDM::Object, members: []) }
|
23
23
|
let(:member_4) { instance_double(Hydra::PCDM::Object, members: []) }
|
24
|
-
let(:members) { [
|
25
|
-
it
|
24
|
+
let(:members) { [member_1, member_2] }
|
25
|
+
it 'does a breadth first iteration of members' do
|
26
26
|
expect(subject.to_a).to eq [member_1, member_2, member_3, member_4]
|
27
27
|
end
|
28
28
|
end
|
29
|
-
context
|
29
|
+
context 'with n levels deep' do
|
30
30
|
let(:member_1) { instance_double(Hydra::PCDM::Object, members: [member_2]) }
|
31
31
|
let(:member_2) { instance_double(Hydra::PCDM::Object, members: [member_3]) }
|
32
32
|
let(:member_3) { instance_double(Hydra::PCDM::Object, members: []) }
|
33
|
-
let(:members) { [
|
34
|
-
it
|
33
|
+
let(:members) { [member_1] }
|
34
|
+
it 'traverses it' do
|
35
35
|
expect(subject.to_a).to eq [member_1, member_2, member_3]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
describe
|
40
|
-
context
|
39
|
+
describe '.include?' do
|
40
|
+
context 'with n levels deep' do
|
41
41
|
let(:member_1) { instance_double(Hydra::PCDM::Object, members: [member_2]) }
|
42
42
|
let(:member_2) { instance_double(Hydra::PCDM::Object, members: [member_3]) }
|
43
43
|
let(:member_3) { instance_double(Hydra::PCDM::Object, members: []) }
|
44
|
-
let(:members) { [
|
45
|
-
it
|
44
|
+
let(:members) { [member_1] }
|
45
|
+
it 'does not go any deeper than necessary' do
|
46
46
|
expect(subject).to include(member_2)
|
47
47
|
expect(member_2).not_to have_received(:members)
|
48
48
|
expect(member_3).not_to have_received(:members)
|
@@ -1,34 +1,45 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::PCDM::Collection do
|
4
|
-
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
4
|
+
let(:collection1) { described_class.new }
|
5
|
+
let(:collection2) { described_class.new }
|
6
|
+
let(:collection3) { described_class.new }
|
7
|
+
let(:collection4) { described_class.new }
|
8
8
|
|
9
9
|
let(:object1) { Hydra::PCDM::Object.new }
|
10
10
|
let(:object2) { Hydra::PCDM::Object.new }
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
subject.
|
18
|
-
subject.
|
19
|
-
|
20
|
-
|
21
|
-
expect(
|
22
|
-
|
23
|
-
|
11
|
+
let(:object3) { Hydra::PCDM::Object.new }
|
12
|
+
|
13
|
+
describe 'adding collections' do
|
14
|
+
describe 'with acceptable inputs' do
|
15
|
+
subject { described_class.new }
|
16
|
+
it 'adds collections, sub-collections, and repeating collections' do
|
17
|
+
subject.collections << collection1 # first add
|
18
|
+
subject.collections << collection2 # second add to same collection
|
19
|
+
subject.collections << collection1 # repeat a collection
|
20
|
+
collection1.collections << collection3 # add sub-collection
|
21
|
+
expect(subject.collections).to eq [collection1, collection2, collection1]
|
22
|
+
expect(collection1.collections).to eq [collection3]
|
23
|
+
end
|
24
|
+
it 'adds an object to collection with collections and objects' do
|
24
25
|
subject.members << collection1
|
25
26
|
subject.members << collection2
|
26
27
|
subject.members << object1
|
27
28
|
subject.members << object2
|
28
29
|
subject.members << collection3
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
30
|
+
expect(subject.members).to eq [collection1, collection2, object1, object2, collection3]
|
31
|
+
expect(subject.collections).to eq [collection1, collection2, collection3]
|
32
|
+
expect(subject.objects).to eq [object1, object2]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#in_collection_ids' do
|
37
|
+
it 'returns the IDs of the parent' do
|
38
|
+
subject.members << object1
|
39
|
+
subject.members << collection1
|
40
|
+
subject.save
|
41
|
+
expect(object1.in_collection_ids).to eq [subject.id]
|
42
|
+
expect(collection1.in_collection_ids).to eq [subject.id]
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
@@ -40,15 +51,15 @@ describe Hydra::PCDM::Collection do
|
|
40
51
|
end
|
41
52
|
after { Object.send(:remove_const, :Kollection) }
|
42
53
|
let(:kollection1) { Kollection.new }
|
43
|
-
|
44
|
-
it '
|
45
|
-
subject.
|
46
|
-
expect(
|
54
|
+
|
55
|
+
it 'accepts implementing collection as a child' do
|
56
|
+
subject.collections << kollection1
|
57
|
+
expect(subject.collections).to eq [kollection1]
|
47
58
|
end
|
48
|
-
|
49
|
-
it '
|
50
|
-
kollection1.
|
51
|
-
expect(
|
59
|
+
|
60
|
+
it 'accepts implementing collection as a parent' do
|
61
|
+
kollection1.collections << collection1
|
62
|
+
expect(kollection1.collections).to eq [collection1]
|
52
63
|
end
|
53
64
|
end
|
54
65
|
|
@@ -59,15 +70,15 @@ describe Hydra::PCDM::Collection do
|
|
59
70
|
end
|
60
71
|
after { Object.send(:remove_const, :Cullection) }
|
61
72
|
let(:cullection1) { Cullection.new }
|
62
|
-
|
63
|
-
it '
|
64
|
-
subject.
|
65
|
-
expect(
|
73
|
+
|
74
|
+
it 'accepts extending collection as a child' do
|
75
|
+
subject.collections << cullection1
|
76
|
+
expect(subject.collections).to eq [cullection1]
|
66
77
|
end
|
67
|
-
|
68
|
-
it '
|
69
|
-
cullection1.
|
70
|
-
expect(
|
78
|
+
|
79
|
+
it 'accepts extending collection as a parent' do
|
80
|
+
cullection1.collections << collection1
|
81
|
+
expect(cullection1.collections).to eq [collection1]
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
@@ -75,96 +86,95 @@ describe Hydra::PCDM::Collection do
|
|
75
86
|
before(:all) do
|
76
87
|
@object101 = Hydra::PCDM::Object.new
|
77
88
|
@file101 = Hydra::PCDM::File.new
|
78
|
-
@
|
89
|
+
@non_pcdm_object = "I'm not a PCDM object"
|
79
90
|
@af_base_object = ActiveFedora::Base.new
|
80
91
|
end
|
81
|
-
|
92
|
+
|
82
93
|
context 'that are unacceptable child collections' do
|
83
94
|
let(:error_type1) { ArgumentError }
|
84
95
|
let(:error_message1) { 'Hydra::PCDM::Object with ID: was expected to pcdm_collection?, but it was false' }
|
85
96
|
let(:error_type2) { NoMethodError }
|
86
97
|
let(:error_message2) { /undefined method `pcdm_collection\?' for .*/ }
|
87
|
-
|
88
|
-
it '
|
89
|
-
expect{ collection1.
|
98
|
+
|
99
|
+
it 'raises an error when trying to aggregate Hydra::PCDM::Objects in collections aggregation' do
|
100
|
+
expect { collection1.collections << @object101 }.to raise_error(error_type1, error_message1)
|
90
101
|
end
|
91
|
-
|
92
|
-
it '
|
93
|
-
expect{ collection1.
|
102
|
+
|
103
|
+
it 'raises an error when trying to aggregate Hydra::PCDM::Files in collections aggregation' do
|
104
|
+
expect { collection1.collections << @file101 }.to raise_error(error_type2, error_message2)
|
94
105
|
end
|
95
|
-
|
96
|
-
it '
|
97
|
-
expect{ collection1.
|
106
|
+
|
107
|
+
it 'raises an error when trying to aggregate non-PCDM objects in collections aggregation' do
|
108
|
+
expect { collection1.collections << @non_pcdm_object }.to raise_error(error_type2, error_message2)
|
98
109
|
end
|
99
|
-
|
100
|
-
it '
|
101
|
-
expect{ collection1.
|
110
|
+
|
111
|
+
it 'raises an error when trying to aggregate AF::Base objects in collections aggregation' do
|
112
|
+
expect { collection1.collections << @af_base_object }.to raise_error(error_type2, error_message2)
|
102
113
|
end
|
103
114
|
end
|
104
115
|
end
|
105
116
|
|
106
|
-
describe
|
117
|
+
describe 'adding collections that are ancestors' do
|
107
118
|
let(:error_type) { ArgumentError }
|
108
119
|
let(:error_message) { 'Hydra::PCDM::Collection with ID: failed to pass AncestorChecker validation' }
|
109
|
-
|
110
|
-
context
|
111
|
-
it
|
112
|
-
expect{ subject.
|
120
|
+
|
121
|
+
context 'when the source collection is the same' do
|
122
|
+
it 'raises an error' do
|
123
|
+
expect { subject.collections << subject }.to raise_error(error_type, error_message)
|
113
124
|
end
|
114
125
|
end
|
115
|
-
|
126
|
+
|
116
127
|
before do
|
117
|
-
subject.
|
128
|
+
subject.collections << collection1
|
118
129
|
end
|
119
|
-
|
120
|
-
it
|
121
|
-
expect{ collection1.
|
130
|
+
|
131
|
+
it 'raises and error' do
|
132
|
+
expect { collection1.collections << subject }.to raise_error(error_type, error_message)
|
122
133
|
end
|
123
|
-
|
124
|
-
context
|
134
|
+
|
135
|
+
context 'with more ancestors' do
|
125
136
|
before do
|
126
|
-
collection1.
|
137
|
+
collection1.collections << collection2
|
127
138
|
end
|
128
|
-
|
129
|
-
it
|
130
|
-
expect{ collection2.
|
139
|
+
|
140
|
+
it 'raises an error' do
|
141
|
+
expect { collection2.collections << subject }.to raise_error(error_type, error_message)
|
131
142
|
end
|
132
|
-
|
133
|
-
context
|
143
|
+
|
144
|
+
context 'with a more complicated example' do
|
134
145
|
before do
|
135
|
-
collection2.
|
146
|
+
collection2.collections << collection3
|
136
147
|
end
|
137
|
-
|
138
|
-
it
|
139
|
-
expect{ collection3.
|
140
|
-
expect{ collection3.
|
148
|
+
|
149
|
+
it 'raises errors' do
|
150
|
+
expect { collection3.collections << subject }.to raise_error(error_type, error_message)
|
151
|
+
expect { collection3.collections << collection1 }.to raise_error(error_type, error_message)
|
141
152
|
end
|
142
153
|
end
|
143
154
|
end
|
144
155
|
end
|
145
156
|
end
|
146
157
|
|
147
|
-
describe
|
148
|
-
subject {
|
158
|
+
describe 'removing collections' do
|
159
|
+
subject { described_class.new }
|
149
160
|
|
150
161
|
context 'when it is the only collection' do
|
151
|
-
|
152
162
|
before do
|
153
163
|
subject.members << collection1
|
154
|
-
expect(
|
164
|
+
expect(subject.collections).to eq [collection1]
|
155
165
|
end
|
156
166
|
|
157
|
-
it '
|
158
|
-
expect(
|
159
|
-
expect(
|
167
|
+
it 'removes collection while changes are in memory' do
|
168
|
+
expect(subject.members.delete collection1).to eq [collection1]
|
169
|
+
expect(subject.collections).to eq []
|
160
170
|
end
|
161
171
|
|
162
|
-
it '
|
172
|
+
it 'removes collection only when objects and all changes are in memory' do
|
163
173
|
subject.members << object1
|
164
174
|
subject.members << object2
|
165
|
-
expect(
|
166
|
-
expect(
|
167
|
-
expect(
|
175
|
+
expect(subject.members.delete collection1).to eq [collection1]
|
176
|
+
expect(subject.collections).to eq []
|
177
|
+
expect(subject.objects).to eq [object1, object2]
|
168
178
|
end
|
169
179
|
end
|
170
180
|
|
@@ -173,67 +183,67 @@ describe Hydra::PCDM::Collection do
|
|
173
183
|
subject.members << collection1
|
174
184
|
subject.members << collection2
|
175
185
|
subject.members << collection3
|
176
|
-
expect(
|
186
|
+
expect(subject.collections).to eq [collection1, collection2, collection3]
|
177
187
|
end
|
178
188
|
|
179
|
-
it '
|
180
|
-
expect(
|
181
|
-
expect(
|
189
|
+
it 'removes first collection when changes are in memory' do
|
190
|
+
expect(subject.members.delete collection1).to eq [collection1]
|
191
|
+
expect(subject.collections).to eq [collection2, collection3]
|
182
192
|
end
|
183
193
|
|
184
|
-
it '
|
185
|
-
expect(
|
186
|
-
expect(
|
194
|
+
it 'removes last collection when changes are in memory' do
|
195
|
+
expect(subject.members.delete collection3).to eq [collection3]
|
196
|
+
expect(subject.collections).to eq [collection1, collection2]
|
187
197
|
end
|
188
198
|
|
189
|
-
it '
|
190
|
-
expect(
|
191
|
-
expect(
|
199
|
+
it 'removes middle collection when changes are in memory' do
|
200
|
+
expect(subject.members.delete collection2).to eq [collection2]
|
201
|
+
expect(subject.collections).to eq [collection1, collection3]
|
192
202
|
end
|
193
203
|
|
194
|
-
it '
|
195
|
-
expect(
|
204
|
+
it 'removes middle collection when changes are saved' do
|
205
|
+
expect(subject.collections).to eq [collection1, collection2, collection3]
|
196
206
|
subject.save
|
197
|
-
expect(
|
198
|
-
expect(
|
207
|
+
expect(subject.members.delete collection2).to eq [collection2]
|
208
|
+
expect(subject.collections).to eq [collection1, collection3]
|
199
209
|
end
|
200
210
|
end
|
201
211
|
context 'when collection is missing' do
|
202
212
|
it 'and 0 sub-collections should return empty array' do
|
203
|
-
expect(
|
213
|
+
expect(subject.members.delete collection1).to eq []
|
204
214
|
end
|
205
215
|
|
206
216
|
it 'and multiple sub-collections should return empty array when changes are in memory' do
|
207
217
|
subject.members << collection1
|
208
218
|
subject.members << collection3
|
209
|
-
expect(
|
219
|
+
expect(subject.members.delete collection2).to eq []
|
210
220
|
end
|
211
221
|
|
212
|
-
it '
|
222
|
+
it 'returns empty array when changes are saved' do
|
213
223
|
subject.members << collection1
|
214
224
|
subject.members << collection3
|
215
225
|
subject.save
|
216
|
-
expect(
|
226
|
+
expect(subject.members.delete collection2).to eq []
|
217
227
|
end
|
218
228
|
end
|
219
229
|
end
|
220
230
|
|
221
|
-
describe
|
231
|
+
describe 'adding objects' do
|
222
232
|
context 'with acceptable inputs' do
|
223
|
-
it '
|
224
|
-
subject.
|
225
|
-
subject.
|
226
|
-
subject.
|
227
|
-
expect(
|
233
|
+
it 'adds objects, sub-collections, and repeating collections' do
|
234
|
+
subject.objects << object1 # first add
|
235
|
+
subject.objects << object2 # second add to same collection
|
236
|
+
subject.objects << object1 # repeat an object
|
237
|
+
expect(subject.objects).to eq [object1, object2, object1]
|
228
238
|
end
|
229
239
|
|
230
240
|
context 'with collections and objects' do
|
231
|
-
it '
|
232
|
-
subject.
|
233
|
-
subject.
|
234
|
-
subject.
|
235
|
-
subject.
|
236
|
-
expect(
|
241
|
+
it 'adds an object to collection with collections and objects' do
|
242
|
+
subject.objects << object1
|
243
|
+
subject.collections << collection1
|
244
|
+
subject.collections << collection2
|
245
|
+
subject.objects << object2
|
246
|
+
expect(subject.objects).to eq [object1, object2]
|
237
247
|
end
|
238
248
|
end
|
239
249
|
|
@@ -246,11 +256,10 @@ describe Hydra::PCDM::Collection do
|
|
246
256
|
after { Object.send(:remove_const, :Ahbject) }
|
247
257
|
let(:ahbject1) { Ahbject.new }
|
248
258
|
|
249
|
-
it '
|
250
|
-
subject.
|
251
|
-
expect(
|
259
|
+
it 'accepts implementing object as a child' do
|
260
|
+
subject.objects << ahbject1
|
261
|
+
expect(subject.objects).to eq [ahbject1]
|
252
262
|
end
|
253
|
-
|
254
263
|
end
|
255
264
|
|
256
265
|
describe 'aggregates objects that extend Hydra::PCDM' do
|
@@ -261,9 +270,9 @@ describe Hydra::PCDM::Collection do
|
|
261
270
|
after { Object.send(:remove_const, :Awbject) }
|
262
271
|
let(:awbject1) { Awbject.new }
|
263
272
|
|
264
|
-
it '
|
265
|
-
subject.
|
266
|
-
expect(
|
273
|
+
it 'accepts extending object as a child' do
|
274
|
+
subject.objects << awbject1
|
275
|
+
expect(subject.objects).to eq [awbject1]
|
267
276
|
end
|
268
277
|
end
|
269
278
|
end
|
@@ -271,7 +280,7 @@ describe Hydra::PCDM::Collection do
|
|
271
280
|
context 'with unacceptable inputs' do
|
272
281
|
before(:all) do
|
273
282
|
@file101 = Hydra::PCDM::File.new
|
274
|
-
@
|
283
|
+
@non_pcdm_object = "I'm not a PCDM object"
|
275
284
|
@af_base_object = ActiveFedora::Base.new
|
276
285
|
end
|
277
286
|
|
@@ -281,43 +290,43 @@ describe Hydra::PCDM::Collection do
|
|
281
290
|
let(:error_type2) { NoMethodError }
|
282
291
|
let(:error_message2) { /undefined method `pcdm_object\?' for .*/ }
|
283
292
|
|
284
|
-
it '
|
285
|
-
expect{ collection1.
|
293
|
+
it 'raises an error when trying to aggregate Hydra::PCDM::Collection in objects aggregation' do
|
294
|
+
expect { collection1.objects << collection2 }.to raise_error(error_type1, error_message1)
|
286
295
|
end
|
287
296
|
|
288
|
-
it '
|
289
|
-
expect{ collection1.
|
297
|
+
it 'raises an error when trying to aggregate Hydra::PCDM::Files in objects aggregation' do
|
298
|
+
expect { collection1.objects << @file101 }.to raise_error(error_type2, error_message2)
|
290
299
|
end
|
291
300
|
|
292
|
-
it '
|
293
|
-
expect{ collection1.
|
301
|
+
it 'raises an error when trying to aggregate non-PCDM objects in objects aggregation' do
|
302
|
+
expect { collection1.objects << @non_pcdm_object }.to raise_error(error_type2, error_message2)
|
294
303
|
end
|
295
304
|
|
296
|
-
it '
|
297
|
-
expect{ collection1.
|
305
|
+
it 'raises an error when trying to aggregate AF::Base objects in objects aggregation' do
|
306
|
+
expect { collection1.objects << @af_base_object }.to raise_error(error_type2, error_message2)
|
298
307
|
end
|
299
308
|
end
|
300
309
|
end
|
301
310
|
end
|
302
311
|
|
303
|
-
describe
|
312
|
+
describe 'removing objects' do
|
304
313
|
context 'when it is the only object' do
|
305
314
|
before do
|
306
|
-
subject.
|
307
|
-
expect(
|
315
|
+
subject.objects << object1
|
316
|
+
expect(subject.objects).to eq [object1]
|
308
317
|
end
|
309
318
|
|
310
|
-
it '
|
311
|
-
expect(
|
312
|
-
expect(
|
319
|
+
it 'removes object while changes are in memory' do
|
320
|
+
expect(subject.objects.delete object1).to eq [object1]
|
321
|
+
expect(subject.objects).to eq []
|
313
322
|
end
|
314
323
|
|
315
|
-
it '
|
316
|
-
subject.
|
317
|
-
subject.
|
318
|
-
expect(
|
319
|
-
expect(
|
320
|
-
expect(
|
324
|
+
it 'removes object only when collections and all changes are in memory' do
|
325
|
+
subject.collections << collection1
|
326
|
+
subject.collections << collection2
|
327
|
+
expect(subject.objects.delete object1).to eq [object1]
|
328
|
+
expect(subject.objects).to eq []
|
329
|
+
expect(subject.collections).to eq [collection1, collection2]
|
321
330
|
end
|
322
331
|
end
|
323
332
|
|
@@ -325,31 +334,31 @@ describe Hydra::PCDM::Collection do
|
|
325
334
|
let(:object3) { Hydra::PCDM::Object.new }
|
326
335
|
|
327
336
|
before do
|
328
|
-
subject.
|
329
|
-
subject.
|
330
|
-
subject.
|
331
|
-
expect(
|
337
|
+
subject.objects << object1
|
338
|
+
subject.objects << object2
|
339
|
+
subject.objects << object3
|
340
|
+
expect(subject.objects).to eq [object1, object2, object3]
|
332
341
|
end
|
333
342
|
|
334
|
-
it '
|
335
|
-
expect(
|
336
|
-
expect(
|
343
|
+
it 'removes first object when changes are in memory' do
|
344
|
+
expect(subject.objects.delete object1).to eq [object1]
|
345
|
+
expect(subject.objects).to eq [object2, object3]
|
337
346
|
end
|
338
347
|
|
339
|
-
it '
|
340
|
-
expect(
|
341
|
-
expect(
|
348
|
+
it 'removes middle object when changes are in memory' do
|
349
|
+
expect(subject.objects.delete object2).to eq [object2]
|
350
|
+
expect(subject.objects).to eq [object1, object3]
|
342
351
|
end
|
343
352
|
|
344
|
-
it '
|
345
|
-
expect(
|
346
|
-
expect(
|
353
|
+
it 'removes last object when changes are in memory' do
|
354
|
+
expect(subject.objects.delete object3).to eq [object3]
|
355
|
+
expect(subject.objects).to eq [object1, object2]
|
347
356
|
end
|
348
|
-
it '
|
349
|
-
expect(
|
350
|
-
expect(
|
357
|
+
it 'removes middle object when changes are saved' do
|
358
|
+
expect(subject.objects.delete object2).to eq [object2]
|
359
|
+
expect(subject.objects).to eq [object1, object3]
|
351
360
|
subject.save
|
352
|
-
expect(
|
361
|
+
expect(subject.reload.objects).to eq [object1, object3]
|
353
362
|
end
|
354
363
|
end
|
355
364
|
|
@@ -359,45 +368,45 @@ describe Hydra::PCDM::Collection do
|
|
359
368
|
let(:object5) { Hydra::PCDM::Object.new }
|
360
369
|
|
361
370
|
before do
|
362
|
-
subject.
|
363
|
-
subject.
|
364
|
-
subject.
|
365
|
-
subject.
|
366
|
-
subject.
|
367
|
-
subject.
|
368
|
-
subject.
|
369
|
-
expect(
|
371
|
+
subject.objects << object1
|
372
|
+
subject.objects << object2
|
373
|
+
subject.objects << object3
|
374
|
+
subject.objects << object2
|
375
|
+
subject.objects << object4
|
376
|
+
subject.objects << object2
|
377
|
+
subject.objects << object5
|
378
|
+
expect(subject.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
|
370
379
|
end
|
371
380
|
|
372
|
-
# TODO pending implementation of multiple objects
|
381
|
+
# TODO: pending implementation of multiple objects
|
373
382
|
|
374
|
-
it '
|
375
|
-
expect(
|
376
|
-
expect(
|
383
|
+
it 'removes first occurrence when changes in memory' do
|
384
|
+
expect(subject.objects.delete object2).to eq [object2]
|
385
|
+
expect(subject.objects).to eq [object1, object3, object4, object5]
|
377
386
|
end
|
378
387
|
|
379
|
-
it '
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
388
|
+
it 'removes last occurrence when changes in memory' do
|
389
|
+
skip('pending resolution of AF-agg 46 and PCDM 102') do
|
390
|
+
expect(subject.objects.delete object2, -1).to eq object2
|
391
|
+
expect(subject.objects).to eq [object1, object2, object3, object2, object4, object5]
|
392
|
+
end
|
384
393
|
end
|
385
394
|
|
386
|
-
it '
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
395
|
+
it 'removes nth occurrence when changes in memory' do
|
396
|
+
skip('pending resolution of AF-agg 46 and PCDM 102') do
|
397
|
+
expect(subject.objects.delete object2, 2).to eq object2
|
398
|
+
expect(subject.objects).to eq [object1, object2, object3, object4, object2, object5]
|
399
|
+
end
|
391
400
|
end
|
392
|
-
it '
|
393
|
-
skip(
|
394
|
-
expect(
|
401
|
+
it 'removes nth occurrence when changes are saved' do
|
402
|
+
skip('pending resolution of AF-agg 46 and PCDM 102') do
|
403
|
+
expect(subject.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
|
395
404
|
subject.save
|
396
|
-
expect(
|
405
|
+
expect(subject.reload.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
|
397
406
|
|
398
|
-
expect(
|
407
|
+
expect(subject.objects.delete object2, 2).to eq object2
|
399
408
|
subject.save
|
400
|
-
expect(
|
409
|
+
expect(subject.reload.objects).to eq [object1, object2, object3, object4, object2, object5]
|
401
410
|
end
|
402
411
|
end
|
403
412
|
end
|
@@ -406,129 +415,128 @@ describe Hydra::PCDM::Collection do
|
|
406
415
|
let(:object3) { Hydra::PCDM::Object.new }
|
407
416
|
|
408
417
|
it 'and 0 objects in collection should return empty array' do
|
409
|
-
expect(
|
418
|
+
expect(subject.objects.delete object1).to eq []
|
410
419
|
end
|
411
420
|
|
412
421
|
it 'and multiple objects in collection should return empty array when changes are in memory' do
|
413
|
-
subject.
|
414
|
-
subject.
|
415
|
-
expect(
|
422
|
+
subject.objects << object1
|
423
|
+
subject.objects << object2
|
424
|
+
expect(subject.objects.delete object3).to eq []
|
416
425
|
end
|
417
426
|
|
418
|
-
it '
|
419
|
-
subject.
|
420
|
-
subject.
|
427
|
+
it 'returns empty array when changes are saved' do
|
428
|
+
subject.objects << object1
|
429
|
+
subject.objects << object2
|
421
430
|
subject.save
|
422
|
-
expect(
|
431
|
+
expect(subject.reload.objects.delete object3).to eq []
|
423
432
|
end
|
424
433
|
end
|
425
434
|
end
|
426
435
|
|
427
|
-
describe
|
436
|
+
describe 'add related objects' do
|
428
437
|
context 'with acceptable collections' do
|
429
|
-
|
430
|
-
it 'should add objects to the related object set' do
|
438
|
+
it 'adds objects to the related object set' do
|
431
439
|
collection1.related_objects << object1 # first add
|
432
440
|
collection1.related_objects << object2 # second add to same collection
|
433
441
|
collection1.save
|
434
442
|
related_objects = collection1.reload.related_objects
|
435
|
-
expect(
|
436
|
-
expect(
|
437
|
-
expect(
|
443
|
+
expect(related_objects.include? object1).to be true
|
444
|
+
expect(related_objects.include? object2).to be true
|
445
|
+
expect(related_objects.size).to eq 2
|
438
446
|
end
|
439
447
|
|
440
|
-
it '
|
441
|
-
expect(
|
448
|
+
it 'is empty when no related objects' do
|
449
|
+
expect(collection1.related_objects).to eq []
|
442
450
|
end
|
443
451
|
|
444
|
-
it '
|
452
|
+
it 'does not repeat objects in the related object set' do
|
445
453
|
skip 'pending resolution of ActiveFedora issue #853' do
|
446
454
|
collection1.related_objects << object1 # first add
|
447
455
|
collection1.related_objects << object2 # second add to same collection
|
448
456
|
collection1.related_objects << object1 # repeat an object replaces the object
|
449
457
|
related_objects = collection1.related_objects
|
450
|
-
expect(
|
451
|
-
expect(
|
452
|
-
expect(
|
458
|
+
expect(related_objects.include? object1).to be true
|
459
|
+
expect(related_objects.include? object2).to be true
|
460
|
+
expect(related_objects.size).to eq 2
|
453
461
|
end
|
454
462
|
end
|
455
463
|
end
|
456
464
|
context 'with unacceptable inputs' do
|
457
465
|
before(:all) do
|
458
466
|
@file101 = Hydra::PCDM::File.new
|
459
|
-
@
|
467
|
+
@non_pcdm_object = "I'm not a PCDM object"
|
460
468
|
@af_base_object = ActiveFedora::Base.new
|
461
469
|
end
|
462
470
|
|
463
471
|
context 'with unacceptable related objects' do
|
464
|
-
it '
|
465
|
-
expect{ collection2.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch
|
472
|
+
it 'raises an error when trying to aggregate Hydra::PCDM::Collection in objects aggregation' do
|
473
|
+
expect { collection2.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.* is not a PCDM object/)
|
466
474
|
end
|
467
475
|
|
468
|
-
it '
|
469
|
-
expect{ collection2.related_objects << @file101 }.to raise_error(ActiveFedora::AssociationTypeMismatch
|
476
|
+
it 'raises an error when trying to aggregate Hydra::PCDM::Files in objects aggregation' do
|
477
|
+
expect { collection2.related_objects << @file101 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base\(#\d+\) expected, got Hydra::PCDM::File\(#\d+\)/)
|
470
478
|
end
|
471
479
|
|
472
|
-
it '
|
473
|
-
expect{ collection2.related_objects << @
|
480
|
+
it 'raises an error when trying to aggregate non-PCDM objects in objects aggregation' do
|
481
|
+
expect { collection2.related_objects << @non_pcdm_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base\(#\d+\) expected, got String\(#\d+\)/)
|
474
482
|
end
|
475
483
|
|
476
|
-
it '
|
477
|
-
expect{ collection2.related_objects << @af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch
|
484
|
+
it 'raises an error when trying to aggregate AF::Base objects in objects aggregation' do
|
485
|
+
expect { collection2.related_objects << @af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base:.*> is not a PCDM object/)
|
478
486
|
end
|
479
487
|
end
|
480
488
|
|
481
489
|
context 'with unacceptable parent object' do
|
482
|
-
it '
|
483
|
-
expect{ @file1.related_objects << object1 }.to raise_error(NoMethodError)
|
490
|
+
it 'raises an error when trying to accept Hydra::PCDM::Files as parent object' do
|
491
|
+
expect { @file1.related_objects << object1 }.to raise_error(NoMethodError)
|
484
492
|
end
|
485
493
|
|
486
|
-
it '
|
487
|
-
expect{ @
|
494
|
+
it 'raises an error when trying to accept non-PCDM objects as parent object' do
|
495
|
+
expect { @non_pcdm_object.related_objects << object1 }.to raise_error(NoMethodError)
|
488
496
|
end
|
489
497
|
|
490
|
-
it '
|
491
|
-
expect{ @af_base_object.related_objects << object1 }.to raise_error(NoMethodError)
|
498
|
+
it 'raises an error when trying to accept AF::Base objects as parent object' do
|
499
|
+
expect { @af_base_object.related_objects << object1 }.to raise_error(NoMethodError)
|
492
500
|
end
|
493
501
|
|
494
502
|
it 'Hydra::PCDM::File should NOT have related files' do
|
495
|
-
expect{ @file1.related_objects }.to raise_error(NoMethodError)
|
503
|
+
expect { @file1.related_objects }.to raise_error(NoMethodError)
|
496
504
|
end
|
497
505
|
|
498
506
|
it 'Non-PCDM objects should should NOT have related objects' do
|
499
|
-
expect{ @
|
507
|
+
expect { @non_pcdm_object.related_objects }.to raise_error(NoMethodError)
|
500
508
|
end
|
501
509
|
|
502
510
|
it 'AF::Base should NOT have related_objects' do
|
503
|
-
expect{ @af_base_object.related_objects }.to raise_error(NoMethodError)
|
511
|
+
expect { @af_base_object.related_objects }.to raise_error(NoMethodError)
|
504
512
|
end
|
505
513
|
end
|
506
514
|
end
|
507
515
|
end
|
508
516
|
|
509
|
-
describe
|
517
|
+
describe 'remove related objects' do
|
510
518
|
context 'when it is the only related object' do
|
511
519
|
let(:object3) { Hydra::PCDM::Object.new }
|
512
520
|
|
513
521
|
before do
|
514
522
|
subject.related_objects << object1
|
515
|
-
expect(
|
523
|
+
expect(subject.related_objects).to eq [object1]
|
516
524
|
end
|
517
525
|
|
518
|
-
it '
|
519
|
-
expect(
|
520
|
-
expect(
|
526
|
+
it 'removes related object while changes are in memory' do
|
527
|
+
expect(subject.related_objects.delete object1).to eq [object1]
|
528
|
+
expect(subject.related_objects).to eq []
|
521
529
|
end
|
522
530
|
|
523
|
-
it '
|
524
|
-
subject.
|
525
|
-
subject.
|
526
|
-
subject.
|
527
|
-
subject.
|
528
|
-
expect(
|
529
|
-
expect(
|
530
|
-
expect(
|
531
|
-
expect(
|
531
|
+
it 'removes related object only when objects & collections and all changes are in memory' do
|
532
|
+
subject.collections << collection1
|
533
|
+
subject.collections << collection2
|
534
|
+
subject.objects << object3
|
535
|
+
subject.objects << object2
|
536
|
+
expect(subject.related_objects.delete object1).to eq [object1]
|
537
|
+
expect(subject.related_objects).to eq []
|
538
|
+
expect(subject.collections).to eq [collection1, collection2]
|
539
|
+
expect(subject.objects).to eq [object3, object2]
|
532
540
|
end
|
533
541
|
end
|
534
542
|
|
@@ -539,58 +547,58 @@ describe Hydra::PCDM::Collection do
|
|
539
547
|
subject.related_objects << object1
|
540
548
|
subject.related_objects << object2
|
541
549
|
subject.related_objects << object3
|
542
|
-
expect(
|
550
|
+
expect(subject.related_objects).to eq [object1, object2, object3]
|
543
551
|
end
|
544
552
|
|
545
|
-
it '
|
546
|
-
expect(
|
547
|
-
expect(
|
553
|
+
it 'removes first related object when changes are in memory' do
|
554
|
+
expect(subject.related_objects.delete object1).to eq [object1]
|
555
|
+
expect(subject.related_objects).to eq [object2, object3]
|
548
556
|
end
|
549
557
|
|
550
|
-
it '
|
551
|
-
expect(
|
552
|
-
expect(
|
558
|
+
it 'removes last related object when changes are in memory' do
|
559
|
+
expect(subject.related_objects.delete object3).to eq [object3]
|
560
|
+
expect(subject.related_objects).to eq [object1, object2]
|
553
561
|
end
|
554
562
|
|
555
|
-
it '
|
556
|
-
expect(
|
557
|
-
expect(
|
563
|
+
it 'removes middle related object when changes are in memory' do
|
564
|
+
expect(subject.related_objects.delete object2).to eq [object2]
|
565
|
+
expect(subject.related_objects).to eq [object1, object3]
|
558
566
|
end
|
559
567
|
|
560
|
-
it '
|
561
|
-
expect(
|
562
|
-
expect(
|
568
|
+
it 'removes middle related object when changes are saved' do
|
569
|
+
expect(subject.related_objects).to eq [object1, object2, object3]
|
570
|
+
expect(subject.related_objects.delete object2).to eq [object2]
|
563
571
|
subject.save
|
564
|
-
expect(
|
572
|
+
expect(subject.reload.related_objects).to eq [object1, object3]
|
565
573
|
end
|
566
574
|
end
|
567
575
|
|
568
576
|
context 'when related object is missing' do
|
569
577
|
let(:object3) { Hydra::PCDM::Object.new }
|
570
578
|
|
571
|
-
it '
|
572
|
-
expect(
|
579
|
+
it 'returns empty array when 0 related objects and 0 collections and objects' do
|
580
|
+
expect(subject.related_objects.delete object1).to eq []
|
573
581
|
end
|
574
582
|
|
575
|
-
it '
|
583
|
+
it 'returns empty array when 0 related objects, but has collections and objects and changes in memory' do
|
576
584
|
subject.members << collection1
|
577
585
|
subject.members << collection2
|
578
586
|
subject.members << object1
|
579
587
|
subject.members << object2
|
580
|
-
expect(
|
588
|
+
expect(subject.related_objects.delete object1).to eq []
|
581
589
|
end
|
582
590
|
|
583
|
-
it '
|
591
|
+
it 'returns empty array when other related objects and changes are in memory' do
|
584
592
|
subject.related_objects << object1
|
585
593
|
subject.related_objects << object3
|
586
|
-
expect(
|
594
|
+
expect(subject.related_objects.delete object2).to eq []
|
587
595
|
end
|
588
596
|
|
589
|
-
it '
|
597
|
+
it 'returns empty array when changes are saved' do
|
590
598
|
subject.related_objects << object1
|
591
599
|
subject.related_objects << object3
|
592
600
|
subject.save
|
593
|
-
expect(
|
601
|
+
expect(subject.reload.related_objects.delete object2).to eq []
|
594
602
|
end
|
595
603
|
end
|
596
604
|
end
|
@@ -598,112 +606,151 @@ describe Hydra::PCDM::Collection do
|
|
598
606
|
context 'with unacceptable inputs' do
|
599
607
|
before(:all) do
|
600
608
|
@file101 = Hydra::PCDM::File.new
|
601
|
-
@
|
609
|
+
@non_pcdm_object = "I'm not a PCDM object"
|
602
610
|
@af_base_object = ActiveFedora::Base.new
|
603
611
|
end
|
604
612
|
|
605
613
|
context 'that are unacceptable parent collections' do
|
606
|
-
it '
|
607
|
-
expect{ @file101.related_objects.delete object1 }.to raise_error(NoMethodError)
|
614
|
+
it 'raises an error when trying to accept Hydra::PCDM::Files as parent collection' do
|
615
|
+
expect { @file101.related_objects.delete object1 }.to raise_error(NoMethodError)
|
608
616
|
end
|
609
617
|
|
610
|
-
it '
|
611
|
-
expect{ @
|
618
|
+
it 'raises an error when trying to accept non-PCDM objects as parent collection' do
|
619
|
+
expect { @non_pcdm_object.related_objects.delete object1 }.to raise_error(NoMethodError)
|
612
620
|
end
|
613
621
|
|
614
|
-
it '
|
615
|
-
expect{ @af_base_object.related_objects.delete object1 }.to raise_error(NoMethodError)
|
622
|
+
it 'raises an error when trying to accept AF::Base objects as parent collection' do
|
623
|
+
expect { @af_base_object.related_objects.delete object1 }.to raise_error(NoMethodError)
|
616
624
|
end
|
617
625
|
end
|
618
626
|
end
|
619
627
|
|
620
|
-
describe '#
|
621
|
-
it '
|
622
|
-
collection1.
|
623
|
-
expect(collection1.
|
628
|
+
describe '#collections=' do
|
629
|
+
it 'aggregates collections' do
|
630
|
+
collection1.collections = [collection2, collection3]
|
631
|
+
expect(collection1.collections).to eq [collection2, collection3]
|
632
|
+
end
|
633
|
+
end
|
634
|
+
|
635
|
+
describe '#collections<<' do
|
636
|
+
before do
|
637
|
+
collection1.collections = [collection2]
|
638
|
+
end
|
639
|
+
it 'aggregates collections' do
|
640
|
+
collection1.collections << collection3
|
641
|
+
expect(collection1.collections).to eq [collection2, collection3]
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
645
|
+
describe '#collections+=' do
|
646
|
+
before do
|
647
|
+
collection1.collections = [collection2]
|
648
|
+
end
|
649
|
+
it 'aggregates collections' do
|
650
|
+
collection1.collections += [collection3, collection4]
|
651
|
+
expect(collection1.collections).to eq [collection2, collection3, collection4]
|
624
652
|
end
|
625
653
|
end
|
626
654
|
|
627
|
-
describe '#
|
628
|
-
it '
|
629
|
-
collection1.
|
630
|
-
expect(collection1.
|
655
|
+
describe '#objects=' do
|
656
|
+
it 'aggregates objects' do
|
657
|
+
collection1.objects = [object1, object2]
|
658
|
+
expect(collection1.objects).to eq [object1, object2]
|
631
659
|
end
|
632
660
|
end
|
633
661
|
|
634
|
-
describe
|
662
|
+
describe '#objects<<' do
|
663
|
+
before do
|
664
|
+
collection1.objects = [object1]
|
665
|
+
end
|
666
|
+
it 'appends object to aggregated objects' do
|
667
|
+
collection1.objects << object2
|
668
|
+
expect(collection1.objects).to eq [object1, object2]
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
672
|
+
describe '#objects+=' do
|
673
|
+
before do
|
674
|
+
collection1.objects = [object1]
|
675
|
+
end
|
676
|
+
it 'appends object to aggregated objects' do
|
677
|
+
collection1.objects += [object2, object3]
|
678
|
+
expect(collection1.objects).to eq [object1, object2, object3]
|
679
|
+
end
|
680
|
+
end
|
681
|
+
|
682
|
+
describe '#collection_ids' do
|
635
683
|
let(:child1) { described_class.new(id: '1') }
|
636
684
|
let(:child2) { described_class.new(id: '2') }
|
637
685
|
let(:object) { described_class.new }
|
638
|
-
before { object.
|
686
|
+
before { object.collections = [child1, child2] }
|
639
687
|
|
640
|
-
subject { object.
|
688
|
+
subject { object.collection_ids }
|
641
689
|
|
642
|
-
it { is_expected.to eq
|
690
|
+
it { is_expected.to eq %w(1 2) }
|
643
691
|
end
|
644
692
|
|
645
|
-
describe '
|
646
|
-
subject {
|
693
|
+
describe 'collections and objects' do
|
694
|
+
subject { described_class.new }
|
647
695
|
|
648
|
-
it '
|
649
|
-
expect(
|
650
|
-
expect(
|
696
|
+
it 'returns empty array when no members' do
|
697
|
+
expect(subject.collections).to eq []
|
698
|
+
expect(subject.objects).to eq []
|
651
699
|
end
|
652
700
|
|
653
|
-
it '
|
701
|
+
it 'collections should return empty array when only objects are aggregated' do
|
654
702
|
subject.members << object1
|
655
703
|
subject.members << object2
|
656
|
-
expect(
|
704
|
+
expect(subject.collections).to eq []
|
657
705
|
end
|
658
706
|
|
659
|
-
it '
|
707
|
+
it 'objects should return empty array when only collections are aggregated' do
|
660
708
|
subject.members << collection1
|
661
709
|
subject.members << collection2
|
662
|
-
expect(
|
710
|
+
expect(subject.objects).to eq []
|
663
711
|
end
|
664
712
|
|
665
713
|
context 'should only contain members of the correct type' do
|
666
|
-
it '
|
667
|
-
subject.
|
714
|
+
it 'returns only collections' do
|
715
|
+
subject.collections << collection1
|
668
716
|
subject.members << collection2
|
669
|
-
subject.
|
717
|
+
subject.objects << object1
|
670
718
|
subject.members << object2
|
671
|
-
expect(
|
672
|
-
expect(
|
673
|
-
expect(
|
719
|
+
expect(subject.collections).to eq [collection1, collection2]
|
720
|
+
expect(subject.objects).to eq [object1, object2]
|
721
|
+
expect(subject.members).to eq [collection1, collection2, object1, object2]
|
674
722
|
end
|
675
723
|
end
|
676
724
|
end
|
677
725
|
|
678
726
|
context 'when aggregated by other objects' do
|
679
|
-
|
680
727
|
before do
|
681
728
|
# Using before(:all) and instance variable because regular :let syntax had a significant impact on performance
|
682
729
|
# All of the tests in this context are describing idempotent behavior, so isolation between examples isn't necessary.
|
683
|
-
@collection1 =
|
684
|
-
@collection2 =
|
685
|
-
@collection =
|
686
|
-
@collection1.
|
687
|
-
@collection2.
|
688
|
-
allow(@collection).to receive(:id).and_return(
|
730
|
+
@collection1 = described_class.new
|
731
|
+
@collection2 = described_class.new
|
732
|
+
@collection = described_class.new
|
733
|
+
@collection1.collections << @collection
|
734
|
+
@collection2.collections << @collection
|
735
|
+
allow(@collection).to receive(:id).and_return('banana')
|
689
736
|
proxies = [
|
690
|
-
|
691
|
-
|
737
|
+
build_proxy(container: @collection1),
|
738
|
+
build_proxy(container: @collection2)
|
692
739
|
]
|
693
740
|
allow(ActiveFedora::Aggregation::Proxy).to receive(:where).with(proxyFor_ssim: @collection.id).and_return(proxies)
|
694
741
|
end
|
695
742
|
|
696
|
-
describe '
|
697
|
-
subject { @collection.
|
698
|
-
it
|
743
|
+
describe 'member_of' do
|
744
|
+
subject { @collection.member_of }
|
745
|
+
it 'finds all nodes that aggregate the object with hasMember' do
|
699
746
|
expect(subject).to include(@collection1, @collection2)
|
700
747
|
expect(subject.count).to eq 2
|
701
748
|
end
|
702
749
|
end
|
703
750
|
|
704
|
-
describe '
|
705
|
-
subject { @collection.
|
706
|
-
it
|
751
|
+
describe 'in_collections' do
|
752
|
+
subject { @collection.in_collections }
|
753
|
+
it 'finds collections that aggregate the object with hasMember' do
|
707
754
|
expect(subject).to include(@collection1, @collection2)
|
708
755
|
expect(subject.count).to eq 2
|
709
756
|
end
|
@@ -713,12 +760,12 @@ describe Hydra::PCDM::Collection do
|
|
713
760
|
end
|
714
761
|
end
|
715
762
|
|
716
|
-
describe
|
763
|
+
describe '.indexer' do
|
717
764
|
after do
|
718
765
|
Object.send(:remove_const, :Foo)
|
719
766
|
end
|
720
767
|
|
721
|
-
context
|
768
|
+
context 'without overriding' do
|
722
769
|
before do
|
723
770
|
class Foo < ActiveFedora::Base
|
724
771
|
include Hydra::PCDM::CollectionBehavior
|
@@ -729,7 +776,7 @@ describe Hydra::PCDM::Collection do
|
|
729
776
|
it { is_expected.to eq Hydra::PCDM::CollectionIndexer }
|
730
777
|
end
|
731
778
|
|
732
|
-
context
|
779
|
+
context 'when overridden with AS::Concern' do
|
733
780
|
before do
|
734
781
|
module IndexingStuff
|
735
782
|
extend ActiveSupport::Concern
|
@@ -753,4 +800,19 @@ describe Hydra::PCDM::Collection do
|
|
753
800
|
it { is_expected.to eq IndexingStuff::AltIndexer }
|
754
801
|
end
|
755
802
|
end
|
803
|
+
|
804
|
+
describe 'make sure deprecated methods still work' do
|
805
|
+
it 'deprecated methods should pass' do
|
806
|
+
expect(collection1.child_collections = [collection2]).to eq [collection2]
|
807
|
+
expect(collection1.child_collections << collection3).to eq [collection2, collection3]
|
808
|
+
expect(collection1.child_collections += [collection4]).to eq [collection2, collection3, collection4]
|
809
|
+
expect(collection1.child_objects = [object1]).to eq [object1]
|
810
|
+
expect(collection1.child_objects << object2).to eq [object1, object2]
|
811
|
+
expect(collection1.child_objects += [object3]).to eq [object1, object2, object3]
|
812
|
+
collection1.save # required until issue AF-Agg-75 is fixed
|
813
|
+
expect(collection2.parent_collections).to eq [collection1]
|
814
|
+
expect(collection2.parents).to eq [collection1]
|
815
|
+
expect(collection2.parent_collection_ids).to eq [collection1.id]
|
816
|
+
end
|
817
|
+
end
|
756
818
|
end
|