hydra-pcdm 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/hydra-pcdm.gemspec +1 -2
- data/lib/hydra/pcdm/collection_indexer.rb +4 -2
- data/lib/hydra/pcdm/models/concerns/collection_behavior.rb +18 -9
- data/lib/hydra/pcdm/models/concerns/object_behavior.rb +1 -1
- data/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb +34 -14
- data/lib/hydra/pcdm/object_indexer.rb +4 -1
- data/lib/hydra/pcdm/version.rb +1 -1
- data/spec/hydra/pcdm/collection_indexer_spec.rb +2 -2
- data/spec/hydra/pcdm/models/collection_spec.rb +159 -342
- data/spec/hydra/pcdm/models/object_spec.rb +60 -276
- data/spec/hydra/pcdm/object_indexer_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -6
- metadata +6 -19
@@ -5,134 +5,22 @@ describe Hydra::PCDM::Object do
|
|
5
5
|
let(:child1) { described_class.new(id: '1') }
|
6
6
|
let(:child2) { described_class.new(id: '2') }
|
7
7
|
let(:object) { described_class.new }
|
8
|
-
before
|
8
|
+
before do
|
9
|
+
object.ordered_members << child1
|
10
|
+
object.ordered_members << child2
|
11
|
+
end
|
9
12
|
|
10
|
-
subject { object.
|
13
|
+
subject { object.ordered_object_ids }
|
11
14
|
|
12
15
|
it { is_expected.to eq %w(1 2) }
|
13
16
|
end
|
14
17
|
|
15
|
-
describe '#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
let(:object3) { described_class.new }
|
20
|
-
let(:object4) { described_class.new }
|
21
|
-
let(:object5) { described_class.new }
|
22
|
-
|
23
|
-
it 'empty when no objects have been added' do
|
24
|
-
expect(subject.objects).to eq []
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'add objects' do
|
28
|
-
subject.objects = [object1, object2]
|
29
|
-
subject.objects << object3
|
30
|
-
subject.objects += [object4, object5]
|
31
|
-
expect(subject.objects).to eq [object1, object2, object3, object4, object5]
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'allow sub-objects' do
|
35
|
-
subject.objects = [object1, object2]
|
36
|
-
object1.objects = [object3]
|
37
|
-
expect(subject.objects).to eq [object1, object2]
|
38
|
-
expect(object1.objects).to eq [object3]
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'allow repeating objects' do
|
42
|
-
subject.objects = [object1, object2]
|
43
|
-
subject.objects << object1
|
44
|
-
expect(subject.objects).to eq [object1, object2, object1]
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'adding objects that are ancestors' do
|
48
|
-
let(:error_type) { ArgumentError }
|
49
|
-
let(:error_message) { 'Hydra::PCDM::Object with ID: failed to pass AncestorChecker validation' }
|
50
|
-
|
51
|
-
context 'when the source object is the same' do
|
52
|
-
it 'raises an error' do
|
53
|
-
expect { object1.objects = [object1] }.to raise_error(error_type, error_message)
|
54
|
-
expect { object1.objects += [object1] }.to raise_error(error_type, error_message)
|
55
|
-
expect { object1.objects << [object1] }.to raise_error(error_type, error_message)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
before do
|
60
|
-
object1.objects = [object2]
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'raises an error' do
|
64
|
-
expect { object2.objects += [object1] }.to raise_error(error_type, error_message)
|
65
|
-
expect { object2.objects << [object1] }.to raise_error(error_type, error_message)
|
66
|
-
expect { object2.objects = [object1] }.to raise_error(error_type, error_message)
|
67
|
-
end
|
68
|
-
|
69
|
-
context 'with more ancestors' do
|
70
|
-
before do
|
71
|
-
object2.objects = [object3]
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'raises an error' do
|
75
|
-
expect { object3.objects << [object1] }.to raise_error(error_type, error_message)
|
76
|
-
expect { object3.objects = [object1] }.to raise_error(error_type, error_message)
|
77
|
-
expect { object3.objects += [object1] }.to raise_error(error_type, error_message)
|
78
|
-
end
|
79
|
-
|
80
|
-
context 'with a more complicated example' do
|
81
|
-
before do
|
82
|
-
object3.objects = [object4, object5]
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'raises errors' do
|
86
|
-
expect { object4.objects = [object1] }.to raise_error(error_type, error_message)
|
87
|
-
expect { object4.objects += [object1] }.to raise_error(error_type, error_message)
|
88
|
-
expect { object4.objects << [object1] }.to raise_error(error_type, error_message)
|
89
|
-
|
90
|
-
expect { object4.objects = [object2] }.to raise_error(error_type, error_message)
|
91
|
-
expect { object4.objects += [object2] }.to raise_error(error_type, error_message)
|
92
|
-
expect { object4.objects << [object2] }.to raise_error(error_type, error_message)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'with unacceptable child objects' do
|
100
|
-
before(:all) do
|
101
|
-
@collection101 = Hydra::PCDM::Collection.new
|
102
|
-
@object101 = described_class.new
|
103
|
-
@file101 = Hydra::PCDM::File.new
|
104
|
-
@non_pcdm_object = "I'm not a PCDM object"
|
105
|
-
@af_base_object = ActiveFedora::Base.new
|
106
|
-
end
|
107
|
-
|
108
|
-
let(:error_type1) { ArgumentError }
|
109
|
-
let(:error_message1) { 'Hydra::PCDM::Collection with ID: was expected to pcdm_object?, but it was false' }
|
110
|
-
let(:error_type2) { NoMethodError }
|
111
|
-
let(:error_message2) { /undefined method `pcdm_object\?' for .*/ }
|
112
|
-
|
113
|
-
it 'NOT aggregate Hydra::PCDM::Collection in objects aggregation' do
|
114
|
-
expect { @object101.objects = [@collection101] }.to raise_error(error_type1, error_message1)
|
115
|
-
expect { @object101.objects += [@collection101] }.to raise_error(error_type1, error_message1)
|
116
|
-
expect { @object101.objects << @collection101 }.to raise_error(error_type1, error_message1)
|
117
|
-
end
|
118
|
-
|
119
|
-
it 'NOT aggregate Hydra::PCDM::Files in objects aggregation' do
|
120
|
-
expect { @object101.objects += [@file1] }.to raise_error(error_type2, error_message2)
|
121
|
-
expect { @object101.objects << @file1 }.to raise_error(error_type2, error_message2)
|
122
|
-
expect { @object101.objects = [@file1] }.to raise_error(error_type2, error_message2)
|
123
|
-
end
|
18
|
+
describe '#ordered_member_ids' do
|
19
|
+
it 'returns IDs of all ordered members' do
|
20
|
+
o = described_class.new
|
21
|
+
subject.ordered_members << o
|
124
22
|
|
125
|
-
|
126
|
-
expect { @object101.objects << @non_pcdm_object }.to raise_error(error_type2, error_message2)
|
127
|
-
expect { @object101.objects = [@non_pcdm_object] }.to raise_error(error_type2, error_message2)
|
128
|
-
expect { @object101.objects += [@non_pcdm_object] }.to raise_error(error_type2, error_message2)
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'NOT aggregate AF::Base objects in objects aggregation' do
|
132
|
-
expect { @object101.objects = [@af_base_object] }.to raise_error(error_type2, error_message2)
|
133
|
-
expect { @object101.objects += [@af_base_object] }.to raise_error(error_type2, error_message2)
|
134
|
-
expect { @object101.objects << @af_base_object }.to raise_error(error_type2, error_message2)
|
135
|
-
end
|
23
|
+
expect(subject.ordered_member_ids).to eq [o.id]
|
136
24
|
end
|
137
25
|
end
|
138
26
|
|
@@ -145,22 +33,22 @@ describe Hydra::PCDM::Object do
|
|
145
33
|
let(:object5) { described_class.new }
|
146
34
|
|
147
35
|
it 'add objects' do
|
148
|
-
subject.
|
149
|
-
subject.
|
150
|
-
subject.
|
151
|
-
expect(subject.
|
36
|
+
subject.ordered_members = [object1, object2]
|
37
|
+
subject.ordered_members << object3
|
38
|
+
subject.ordered_members += [object4, object5]
|
39
|
+
expect(subject.ordered_members).to eq [object1, object2, object3, object4, object5]
|
152
40
|
end
|
153
41
|
|
154
42
|
it 'allow sub-objects' do
|
155
|
-
subject.
|
156
|
-
object1.
|
157
|
-
expect(subject.
|
158
|
-
expect(object1.
|
43
|
+
subject.ordered_members = [object1, object2]
|
44
|
+
object1.ordered_members = [object3]
|
45
|
+
expect(subject.ordered_members).to eq [object1, object2]
|
46
|
+
expect(object1.ordered_members).to eq [object3]
|
159
47
|
end
|
160
48
|
|
161
49
|
it 'allow repeating objects' do
|
162
|
-
subject.
|
163
|
-
expect(subject.
|
50
|
+
subject.ordered_members = [object1, object2, object1]
|
51
|
+
expect(subject.ordered_members).to eq [object1, object2, object1]
|
164
52
|
end
|
165
53
|
|
166
54
|
describe 'adding objects that are ancestors' do
|
@@ -169,46 +57,46 @@ describe Hydra::PCDM::Object do
|
|
169
57
|
|
170
58
|
context 'when the source object is the same' do
|
171
59
|
it 'raises an error' do
|
172
|
-
expect { object1.
|
173
|
-
expect { object1.
|
174
|
-
expect { object1.
|
60
|
+
expect { object1.ordered_members = [object1] }.to raise_error(error_type, error_message)
|
61
|
+
expect { object1.ordered_members += [object1] }.to raise_error(error_type, error_message)
|
62
|
+
expect { object1.ordered_members << [object1] }.to raise_error(error_type, error_message)
|
175
63
|
end
|
176
64
|
end
|
177
65
|
|
178
66
|
before do
|
179
|
-
object1.
|
67
|
+
object1.ordered_members = [object2]
|
180
68
|
end
|
181
69
|
|
182
70
|
it 'raises an error' do
|
183
|
-
expect { object2.
|
184
|
-
expect { object2.
|
185
|
-
expect { object2.
|
71
|
+
expect { object2.ordered_members += [object1] }.to raise_error(error_type, error_message)
|
72
|
+
expect { object2.ordered_members << [object1] }.to raise_error(error_type, error_message)
|
73
|
+
expect { object2.ordered_members = [object1] }.to raise_error(error_type, error_message)
|
186
74
|
end
|
187
75
|
|
188
76
|
context 'with more ancestors' do
|
189
77
|
before do
|
190
|
-
object2.
|
78
|
+
object2.ordered_members = [object3]
|
191
79
|
end
|
192
80
|
|
193
81
|
it 'raises an error' do
|
194
|
-
expect { object3.
|
195
|
-
expect { object3.
|
196
|
-
expect { object3.
|
82
|
+
expect { object3.ordered_members << [object1] }.to raise_error(error_type, error_message)
|
83
|
+
expect { object3.ordered_members = [object1] }.to raise_error(error_type, error_message)
|
84
|
+
expect { object3.ordered_members += [object1] }.to raise_error(error_type, error_message)
|
197
85
|
end
|
198
86
|
|
199
87
|
context 'with a more complicated example' do
|
200
88
|
before do
|
201
|
-
object3.
|
89
|
+
object3.ordered_members = [object4, object5]
|
202
90
|
end
|
203
91
|
|
204
92
|
it 'raises errors' do
|
205
|
-
expect { object4.
|
206
|
-
expect { object4.
|
207
|
-
expect { object4.
|
93
|
+
expect { object4.ordered_members = [object1] }.to raise_error(error_type, error_message)
|
94
|
+
expect { object4.ordered_members += [object1] }.to raise_error(error_type, error_message)
|
95
|
+
expect { object4.ordered_members << [object1] }.to raise_error(error_type, error_message)
|
208
96
|
|
209
|
-
expect { object4.
|
210
|
-
expect { object4.
|
211
|
-
expect { object4.
|
97
|
+
expect { object4.ordered_members = [object2] }.to raise_error(error_type, error_message)
|
98
|
+
expect { object4.ordered_members += [object2] }.to raise_error(error_type, error_message)
|
99
|
+
expect { object4.ordered_members << [object2] }.to raise_error(error_type, error_message)
|
212
100
|
end
|
213
101
|
end
|
214
102
|
end
|
@@ -234,26 +122,26 @@ describe Hydra::PCDM::Object do
|
|
234
122
|
let(:error_message3) { /ActiveFedora::Base\(#\d+\) expected, got String\(#[\d]+\)/ }
|
235
123
|
|
236
124
|
it 'NOT aggregate Hydra::PCDM::Collection in members aggregation' do
|
237
|
-
expect { @object101.
|
238
|
-
expect { @object101.
|
239
|
-
expect { @object101.
|
125
|
+
expect { @object101.ordered_members = [@collection101] }.to raise_error(error_type1, error_message1)
|
126
|
+
expect { @object101.ordered_members += [@collection101] }.to raise_error(error_type1, error_message1)
|
127
|
+
expect { @object101.ordered_members << @collection101 }.to raise_error(error_type1, error_message1)
|
240
128
|
end
|
241
129
|
it 'NOT aggregate Hydra::PCDM::Files in members aggregation' do
|
242
|
-
expect { @object101.
|
243
|
-
expect { @object101.
|
244
|
-
expect { @object101.
|
130
|
+
expect { @object101.ordered_members += [@file1] }.to raise_error(error_type2, error_message2)
|
131
|
+
expect { @object101.ordered_members << @file1 }.to raise_error(error_type2, error_message2)
|
132
|
+
expect { @object101.ordered_members = [@file1] }.to raise_error(error_type2, error_message2)
|
245
133
|
end
|
246
134
|
|
247
135
|
it 'NOT aggregate non-PCDM objects in members aggregation' do
|
248
|
-
expect { @object101.
|
249
|
-
expect { @object101.
|
250
|
-
expect { @object101.
|
136
|
+
expect { @object101.ordered_members << @non_pcdm_object }.to raise_error(error_type3, error_message3)
|
137
|
+
expect { @object101.ordered_members = [@non_pcdm_object] }.to raise_error(error_type3, error_message3)
|
138
|
+
expect { @object101.ordered_members += [@non_pcdm_object] }.to raise_error(error_type3, error_message3)
|
251
139
|
end
|
252
140
|
|
253
141
|
it 'NOT aggregate non-PCDM AF::Base objects in members aggregation' do
|
254
|
-
expect { @object101.
|
255
|
-
expect { @object101.
|
256
|
-
expect { @object101.
|
142
|
+
expect { @object101.ordered_members = [@af_base_object] }.to raise_error(error_type1, error_message1)
|
143
|
+
expect { @object101.ordered_members += [@af_base_object] }.to raise_error(error_type1, error_message1)
|
144
|
+
expect { @object101.ordered_members << @af_base_object }.to raise_error(error_type1, error_message1)
|
257
145
|
end
|
258
146
|
end
|
259
147
|
end
|
@@ -265,17 +153,13 @@ describe Hydra::PCDM::Object do
|
|
265
153
|
@collection1 = Hydra::PCDM::Collection.new
|
266
154
|
@collection2 = Hydra::PCDM::Collection.new
|
267
155
|
@parent_object = described_class.new
|
268
|
-
@object = described_class.
|
269
|
-
@collection1.
|
270
|
-
@collection2.
|
271
|
-
@parent_object.
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
build_proxy(container: @collection2),
|
276
|
-
build_proxy(container: @parent_object)
|
277
|
-
]
|
278
|
-
allow(ActiveFedora::Aggregation::Proxy).to receive(:where).with(proxyFor_ssim: @object.id).and_return(proxies)
|
156
|
+
@object = described_class.create
|
157
|
+
@collection1.ordered_members = [@object]
|
158
|
+
@collection2.ordered_members = [@object]
|
159
|
+
@parent_object.ordered_members = [@object]
|
160
|
+
@parent_object.save
|
161
|
+
@collection1.save
|
162
|
+
@collection2.save
|
279
163
|
end
|
280
164
|
|
281
165
|
describe 'member_of' do
|
@@ -482,106 +366,6 @@ describe Hydra::PCDM::Object do
|
|
482
366
|
end
|
483
367
|
end
|
484
368
|
|
485
|
-
describe 'removing child objects' do
|
486
|
-
subject { described_class.new }
|
487
|
-
let(:object1) { described_class.new }
|
488
|
-
let(:object2) { described_class.new }
|
489
|
-
let(:object3) { described_class.new }
|
490
|
-
|
491
|
-
context 'when it is the only object' do
|
492
|
-
before do
|
493
|
-
subject.objects += [object1]
|
494
|
-
expect(subject.objects).to eq [object1]
|
495
|
-
end
|
496
|
-
|
497
|
-
it 'remove object while changes are in memory' do
|
498
|
-
expect(subject.objects.delete object1).to eq [object1]
|
499
|
-
expect(subject.objects).to eq []
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
context 'when multiple objects' do
|
504
|
-
before do
|
505
|
-
subject.objects += [object1, object2, object3]
|
506
|
-
expect(subject.objects).to eq [object1, object2, object3]
|
507
|
-
end
|
508
|
-
|
509
|
-
it 'remove first object when changes are in memory' do
|
510
|
-
expect(subject.objects.delete object1).to eq [object1]
|
511
|
-
expect(subject.objects).to eq [object2, object3]
|
512
|
-
end
|
513
|
-
|
514
|
-
it 'remove last object when changes are in memory' do
|
515
|
-
expect(subject.objects.delete object3).to eq [object3]
|
516
|
-
expect(subject.objects).to eq [object1, object2]
|
517
|
-
end
|
518
|
-
|
519
|
-
it 'remove middle object when changes are in memory' do
|
520
|
-
expect(subject.objects.delete object2).to eq [object2]
|
521
|
-
expect(subject.objects).to eq [object1, object3]
|
522
|
-
end
|
523
|
-
|
524
|
-
it 'remove middle object when changes are saved' do
|
525
|
-
subject.save
|
526
|
-
expect(subject.objects).to eq [object1, object2, object3]
|
527
|
-
expect(subject.objects.delete object2).to eq [object2]
|
528
|
-
expect(subject.objects).to eq [object1, object3]
|
529
|
-
end
|
530
|
-
end
|
531
|
-
context 'when object repeats' do
|
532
|
-
before do
|
533
|
-
subject.objects += [object1, object2, object3, object2, object3]
|
534
|
-
expect(subject.objects).to eq [object1, object2, object3, object2, object3]
|
535
|
-
end
|
536
|
-
|
537
|
-
it 'remove first occurrence when changes in memory' do
|
538
|
-
expect(subject.objects.delete object2).to eq [object2]
|
539
|
-
expect(subject.objects).to eq [object1, object3, object3]
|
540
|
-
end
|
541
|
-
|
542
|
-
it 'remove last occurrence when changes in memory' do
|
543
|
-
skip('pending resolution of AF-agg 46 and PCDM 102') do
|
544
|
-
expect(subject.objects.delete object2, -1).to eq object2
|
545
|
-
expect(subject.objects).to eq [object1, object2, object3, object3]
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
it 'remove nth occurrence when changes in memory' do
|
550
|
-
skip('pending resolution of AF-agg 46 and PCDM 102') do
|
551
|
-
expect(subject.objects.delete object2, 2).to eq object2
|
552
|
-
expect(subject.objects).to eq [object1, object2, object3, object3]
|
553
|
-
end
|
554
|
-
end
|
555
|
-
|
556
|
-
it 'remove nth occurrence when changes are saved' do
|
557
|
-
skip('pending resolution of AF-agg 46 and PCDM 102') do
|
558
|
-
expect(subject.objects).to eq [object1, object2, object3, object2, object3]
|
559
|
-
expect(subject.objects).to eq [object1, object2, object3, object2, object3]
|
560
|
-
|
561
|
-
expect(subject.objects.delete object2, 2).to eq object2
|
562
|
-
subject.save
|
563
|
-
expect(subject.objects).to eq [object1, object2, object3, object2, object3]
|
564
|
-
end
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
context 'when object is missing' do
|
569
|
-
it 'and 0 objects in object return empty array' do
|
570
|
-
expect(subject.objects.delete object1).to eq []
|
571
|
-
end
|
572
|
-
|
573
|
-
it 'and multiple objects in object return empty array when changes are in memory' do
|
574
|
-
subject.objects += [object1, object2]
|
575
|
-
expect(subject.objects.delete object3).to eq []
|
576
|
-
end
|
577
|
-
|
578
|
-
it 'return empty array when changes are saved' do
|
579
|
-
subject.objects += [object1, object2]
|
580
|
-
expect(subject.objects.delete object3).to eq []
|
581
|
-
end
|
582
|
-
end
|
583
|
-
end
|
584
|
-
|
585
369
|
describe '#files' do
|
586
370
|
subject { described_class.new }
|
587
371
|
it 'have a files relation' do
|
@@ -693,9 +477,9 @@ describe Hydra::PCDM::Object do
|
|
693
477
|
let(:object4) { described_class.new }
|
694
478
|
|
695
479
|
it 'deprecated methods should pass' do
|
696
|
-
expect(object1.
|
697
|
-
expect(object1.
|
698
|
-
expect(object1.
|
480
|
+
expect(object1.ordered_members = [object2]).to eq [object2]
|
481
|
+
expect(object1.ordered_members << object3).to eq [object2, object3]
|
482
|
+
expect(object1.ordered_members += [object4]).to eq [object2, object3, object4]
|
699
483
|
object1.save # required until issue AF-Agg-75 is fixed
|
700
484
|
expect(object2.parent_objects).to eq [object1]
|
701
485
|
expect(object2.parents).to eq [object1]
|
@@ -7,7 +7,7 @@ describe Hydra::PCDM::ObjectIndexer do
|
|
7
7
|
let(:indexer) { described_class.new(object) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
allow(object).to receive(:
|
10
|
+
allow(object).to receive(:ordered_object_ids).and_return([child_object1.id, child_object2.id])
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '#generate_solr_document' do
|
data/spec/spec_helper.rb
CHANGED
@@ -2,12 +2,11 @@ ENV['environment'] ||= 'test'
|
|
2
2
|
require 'simplecov'
|
3
3
|
require 'coveralls'
|
4
4
|
|
5
|
-
SimpleCov.formatter =
|
6
|
-
SimpleCov
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
Coveralls.wear!
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
SimpleCov.start 'rails'
|
11
10
|
|
12
11
|
require 'bundler/setup'
|
13
12
|
Bundler.setup
|