hydra-pcdm 0.1.0 → 0.2.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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +38 -0
  3. data/Gemfile +6 -3
  4. data/README.md +31 -38
  5. data/Rakefile +14 -4
  6. data/hydra-pcdm.gemspec +10 -10
  7. data/lib/hydra/pcdm.rb +13 -12
  8. data/lib/hydra/pcdm/collection_indexer.rb +2 -4
  9. data/lib/hydra/pcdm/deep_member_iterator.rb +1 -1
  10. data/lib/hydra/pcdm/models/collection.rb +0 -1
  11. data/lib/hydra/pcdm/models/concerns/collection_behavior.rb +18 -5
  12. data/lib/hydra/pcdm/models/concerns/object_behavior.rb +13 -17
  13. data/lib/hydra/pcdm/models/concerns/pcdm_behavior.rb +50 -9
  14. data/lib/hydra/pcdm/models/file.rb +7 -7
  15. data/lib/hydra/pcdm/models/object.rb +0 -1
  16. data/lib/hydra/pcdm/object_indexer.rb +1 -2
  17. data/lib/hydra/pcdm/services/file/add_type.rb +1 -3
  18. data/lib/hydra/pcdm/services/file/get_mime_type.rb +2 -4
  19. data/lib/hydra/pcdm/validators/ancestor_validator.rb +3 -11
  20. data/lib/hydra/pcdm/validators/pcdm_object_validator.rb +2 -2
  21. data/lib/hydra/pcdm/validators/pcdm_validator.rb +2 -2
  22. data/lib/hydra/pcdm/version.rb +1 -1
  23. data/lib/hydra/pcdm/vocab/pcdm_terms.rb +81 -80
  24. data/lib/hydra/pcdm/vocab/sweet_jpl_terms.rb +12 -0
  25. data/spec/hydra/pcdm/ancestor_checker_spec.rb +7 -7
  26. data/spec/hydra/pcdm/collection_indexer_spec.rb +12 -13
  27. data/spec/hydra/pcdm/deep_member_iterator_spec.rb +16 -16
  28. data/spec/hydra/pcdm/models/collection_spec.rb +375 -313
  29. data/spec/hydra/pcdm/models/file_spec.rb +38 -38
  30. data/spec/hydra/pcdm/models/object_spec.rb +270 -256
  31. data/spec/hydra/pcdm/object_indexer_spec.rb +4 -4
  32. data/spec/hydra/pcdm/services/file/get_mime_type_spec.rb +10 -12
  33. data/spec/hydra/pcdm_spec.rb +21 -26
  34. metadata +19 -5
  35. data/lib/hydra/pcdm/vocab/ebucore_terms.rb +0 -33
  36. 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 "#each" do
8
- context "with no members" do
9
- it "should return an empty array" do
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 "with a member" do
14
- let(:members) { [ instance_double(Hydra::PCDM::Object, members: []) ] }
15
- it "should return that member" do
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 "with deep members" do
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) { [ member_1, member_2] }
25
- it "should do a breadth first iteration of members" do
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 "with n levels deep" do
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) { [ member_1] }
34
- it "should traverse it" do
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 ".include?" do
40
- context "with n levels deep" do
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) { [ member_1] }
45
- it "should not go any deeper than necessary" do
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(:collection1) { Hydra::PCDM::Collection.new }
6
- let(:collection2) { Hydra::PCDM::Collection.new }
7
- let(:collection3) { Hydra::PCDM::Collection.new }
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
- describe "adding collections" do
13
- describe "with acceptable inputs" do
14
- subject { Hydra::PCDM::Collection.new }
15
- it 'should add collections, sub-collections, and repeating collections' do
16
- subject.child_collections << collection1 # first add
17
- subject.child_collections << collection2 # second add to same collection
18
- subject.child_collections << collection1 # repeat a collection
19
- collection1.child_collections << collection3 # add sub-collection
20
- expect( subject.child_collections ).to eq [collection1,collection2,collection1]
21
- expect( collection1.child_collections ).to eq [collection3]
22
- end
23
- it 'should add an object to collection with collections and objects' do
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( subject.members ).to eq [collection1,collection2,object1,object2,collection3]
30
- expect( subject.child_collections ).to eq [collection1,collection2,collection3]
31
- expect( subject.child_objects ).to eq [object1,object2]
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 'should accept implementing collection as a child' do
45
- subject.child_collections << kollection1
46
- expect( subject.child_collections ).to eq [kollection1]
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 'should accept implementing collection as a parent' do
50
- kollection1.child_collections << collection1
51
- expect( kollection1.child_collections ).to eq [collection1]
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 'should accept extending collection as a child' do
64
- subject.child_collections << cullection1
65
- expect( subject.child_collections ).to eq [cullection1]
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 'should accept extending collection as a parent' do
69
- cullection1.child_collections << collection1
70
- expect( cullection1.child_collections ).to eq [collection1]
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
- @non_PCDM_object = "I'm not a PCDM object"
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 'should NOT aggregate Hydra::PCDM::Objects in collections aggregation' do
89
- expect{ collection1.child_collections << @object101 }.to raise_error(error_type1,error_message1)
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 'should NOT aggregate Hydra::PCDM::Files in collections aggregation' do
93
- expect{ collection1.child_collections << @file101 }.to raise_error(error_type2,error_message2)
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 'should NOT aggregate non-PCDM objects in collections aggregation' do
97
- expect{ collection1.child_collections << @non_PCDM_object }.to raise_error(error_type2,error_message2)
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 'should NOT aggregate AF::Base objects in collections aggregation' do
101
- expect{ collection1.child_collections << @af_base_object }.to raise_error(error_type2,error_message2)
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 "adding collections that are ancestors" do
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 "when the source collection is the same" do
111
- it "raises an error" do
112
- expect{ subject.child_collections << subject }.to raise_error(error_type, error_message)
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.child_collections << collection1
128
+ subject.collections << collection1
118
129
  end
119
-
120
- it "raises and error" do
121
- expect{ collection1.child_collections << subject }.to raise_error(error_type, error_message)
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 "with more ancestors" do
134
+
135
+ context 'with more ancestors' do
125
136
  before do
126
- collection1.child_collections << collection2
137
+ collection1.collections << collection2
127
138
  end
128
-
129
- it "raises an error" do
130
- expect{ collection2.child_collections << subject }.to raise_error(error_type, error_message)
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 "with a more complicated example" do
143
+
144
+ context 'with a more complicated example' do
134
145
  before do
135
- collection2.child_collections << collection3
146
+ collection2.collections << collection3
136
147
  end
137
-
138
- it "raises errors" do
139
- expect{ collection3.child_collections << subject }.to raise_error(error_type, error_message)
140
- expect{ collection3.child_collections << collection1 }.to raise_error(error_type, error_message)
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 "removing collections" do
148
- subject { Hydra::PCDM::Collection.new }
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( subject.child_collections ).to eq [collection1]
164
+ expect(subject.collections).to eq [collection1]
155
165
  end
156
166
 
157
- it 'should remove collection while changes are in memory' do
158
- expect( subject.members.delete collection1 ).to eq [collection1]
159
- expect( subject.child_collections ).to eq []
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 'should remove collection only when objects and all changes are in memory' do
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( subject.members.delete collection1 ).to eq [collection1]
166
- expect( subject.child_collections ).to eq []
167
- expect( subject.child_objects ).to eq [object1,object2]
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( subject.child_collections ).to eq [collection1,collection2,collection3]
186
+ expect(subject.collections).to eq [collection1, collection2, collection3]
177
187
  end
178
188
 
179
- it 'should remove first collection when changes are in memory' do
180
- expect( subject.members.delete collection1 ).to eq [collection1]
181
- expect( subject.child_collections ).to eq [collection2,collection3]
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 'should remove last collection when changes are in memory' do
185
- expect( subject.members.delete collection3 ).to eq [collection3]
186
- expect( subject.child_collections ).to eq [collection1,collection2]
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 'should remove middle collection when changes are in memory' do
190
- expect( subject.members.delete collection2 ).to eq [collection2]
191
- expect( subject.child_collections ).to eq [collection1,collection3]
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 'should remove middle collection when changes are saved' do
195
- expect( subject.child_collections ).to eq [collection1,collection2,collection3]
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( subject.members.delete collection2 ).to eq [collection2]
198
- expect( subject.child_collections ).to eq [collection1,collection3]
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( subject.members.delete collection1 ).to eq []
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( subject.members.delete collection2 ).to eq []
219
+ expect(subject.members.delete collection2).to eq []
210
220
  end
211
221
 
212
- it 'should return empty array when changes are saved' do
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( subject.members.delete collection2 ).to eq []
226
+ expect(subject.members.delete collection2).to eq []
217
227
  end
218
228
  end
219
229
  end
220
230
 
221
- describe "adding objects" do
231
+ describe 'adding objects' do
222
232
  context 'with acceptable inputs' do
223
- it 'should add objects, sub-collections, and repeating collections' do
224
- subject.child_objects << object1 # first add
225
- subject.child_objects << object2 # second add to same collection
226
- subject.child_objects << object1 # repeat an object
227
- expect( subject.child_objects ).to eq [object1,object2,object1]
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 'should add an object to collection with collections and objects' do
232
- subject.child_objects << object1
233
- subject.child_collections << collection1
234
- subject.child_collections << collection2
235
- subject.child_objects << object2
236
- expect( subject.child_objects ).to eq [object1,object2]
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 'should accept implementing object as a child' do
250
- subject.child_objects << ahbject1
251
- expect( subject.child_objects ).to eq [ahbject1]
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 'should accept extending object as a child' do
265
- subject.child_objects << awbject1
266
- expect( subject.child_objects ).to eq [awbject1]
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
- @non_PCDM_object = "I'm not a PCDM object"
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 'should NOT aggregate Hydra::PCDM::Collection in objects aggregation' do
285
- expect{ collection1.child_objects << collection2 }.to raise_error(error_type1,error_message1)
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 'should NOT aggregate Hydra::PCDM::Files in objects aggregation' do
289
- expect{ collection1.child_objects << @file101 }.to raise_error(error_type2,error_message2)
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 'should NOT aggregate non-PCDM objects in objects aggregation' do
293
- expect{ collection1.child_objects << @non_PCDM_object }.to raise_error(error_type2,error_message2)
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 'should NOT aggregate AF::Base objects in objects aggregation' do
297
- expect{ collection1.child_objects << @af_base_object }.to raise_error(error_type2,error_message2)
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 "removing objects" do
312
+ describe 'removing objects' do
304
313
  context 'when it is the only object' do
305
314
  before do
306
- subject.child_objects << object1
307
- expect( subject.child_objects ).to eq [object1]
315
+ subject.objects << object1
316
+ expect(subject.objects).to eq [object1]
308
317
  end
309
318
 
310
- it 'should remove object while changes are in memory' do
311
- expect( subject.child_objects.delete object1 ).to eq [object1]
312
- expect( subject.child_objects ).to eq []
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 'should remove object only when collections and all changes are in memory' do
316
- subject.child_collections << collection1
317
- subject.child_collections << collection2
318
- expect( subject.child_objects.delete object1 ).to eq [object1]
319
- expect( subject.child_objects ).to eq []
320
- expect( subject.child_collections ).to eq [collection1,collection2]
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.child_objects << object1
329
- subject.child_objects << object2
330
- subject.child_objects << object3
331
- expect( subject.child_objects ).to eq [object1,object2,object3]
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 'should remove first object when changes are in memory' do
335
- expect( subject.child_objects.delete object1 ).to eq [object1]
336
- expect( subject.child_objects ).to eq [object2,object3]
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 'should remove middle object when changes are in memory' do
340
- expect( subject.child_objects.delete object2 ).to eq [object2]
341
- expect( subject.child_objects ).to eq [object1,object3]
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 'should remove last object when changes are in memory' do
345
- expect( subject.child_objects.delete object3 ).to eq [object3]
346
- expect( subject.child_objects ).to eq [object1,object2]
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 'should remove middle object when changes are saved' do
349
- expect( subject.child_objects.delete object2 ).to eq [object2]
350
- expect( subject.child_objects ).to eq [object1,object3]
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( subject.reload.child_objects ).to eq [object1,object3]
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.child_objects << object1
363
- subject.child_objects << object2
364
- subject.child_objects << object3
365
- subject.child_objects << object2
366
- subject.child_objects << object4
367
- subject.child_objects << object2
368
- subject.child_objects << object5
369
- expect( subject.child_objects ).to eq [object1,object2,object3,object2,object4,object2,object5]
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 'should remove first occurrence when changes in memory' do
375
- expect( subject.child_objects.delete object2 ).to eq [object2]
376
- expect( subject.child_objects ).to eq [object1,object3,object4,object5]
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 'should remove last occurrence when changes in memory' do
380
- skip( "pending resolution of AF-agg 46 and PCDM 102") do
381
- expect( subject.child_objects.delete object2, -1 ).to eq object2
382
- expect( subject.child_objects ).to eq [object1,object2,object3,object2,object4,object5]
383
- end
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 'should remove nth occurrence when changes in memory' do
387
- skip( "pending resolution of AF-agg 46 and PCDM 102") do
388
- expect( subject.child_objects.delete object2, 2 ).to eq object2
389
- expect( subject.child_objects ).to eq [object1,object2,object3,object4,object2,object5]
390
- end
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 'should remove nth occurrence when changes are saved' do
393
- skip( "pending resolution of AF-agg 46 and PCDM 102") do
394
- expect( subject.child_objects ).to eq [object1,object2,object3,object2,object4,object2,object5]
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( subject.reload.child_objects ).to eq [object1,object2,object3,object2,object4,object2,object5]
405
+ expect(subject.reload.objects).to eq [object1, object2, object3, object2, object4, object2, object5]
397
406
 
398
- expect( subject.child_objects.delete object2, 2 ).to eq object2
407
+ expect(subject.objects.delete object2, 2).to eq object2
399
408
  subject.save
400
- expect( subject.reload.child_objects ).to eq [object1,object2,object3,object4,object2,object5]
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( subject.child_objects.delete object1 ).to eq []
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.child_objects << object1
414
- subject.child_objects << object2
415
- expect( subject.child_objects.delete object3 ).to eq []
422
+ subject.objects << object1
423
+ subject.objects << object2
424
+ expect(subject.objects.delete object3).to eq []
416
425
  end
417
426
 
418
- it 'should return empty array when changes are saved' do
419
- subject.child_objects << object1
420
- subject.child_objects << object2
427
+ it 'returns empty array when changes are saved' do
428
+ subject.objects << object1
429
+ subject.objects << object2
421
430
  subject.save
422
- expect( subject.reload.child_objects.delete object3 ).to eq []
431
+ expect(subject.reload.objects.delete object3).to eq []
423
432
  end
424
433
  end
425
434
  end
426
435
 
427
- describe "add related objects" do
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( related_objects.include? object1 ).to be true
436
- expect( related_objects.include? object2 ).to be true
437
- expect( related_objects.size ).to eq 2
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 'should be empty when no related objects' do
441
- expect( collection1.related_objects ).to eq []
448
+ it 'is empty when no related objects' do
449
+ expect(collection1.related_objects).to eq []
442
450
  end
443
451
 
444
- it 'should not repeat objects in the related object set' do
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( related_objects.include? object1 ).to be true
451
- expect( related_objects.include? object2 ).to be true
452
- expect( related_objects.size ).to eq 2
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
- @non_PCDM_object = "I'm not a PCDM object"
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 'should NOT aggregate Hydra::PCDM::Collection in objects aggregation' do
465
- expect{ collection2.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch,/Hydra::PCDM::Collection:.* is not a PCDM object/)
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 'should NOT aggregate Hydra::PCDM::Files in objects aggregation' do
469
- expect{ collection2.related_objects << @file101 }.to raise_error(ActiveFedora::AssociationTypeMismatch,/ActiveFedora::Base\(#\d+\) expected, got Hydra::PCDM::File\(#\d+\)/)
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 'should NOT aggregate non-PCDM objects in objects aggregation' do
473
- expect{ collection2.related_objects << @non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch,/ActiveFedora::Base\(#\d+\) expected, got String\(#\d+\)/)
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 'should NOT aggregate AF::Base objects in objects aggregation' do
477
- expect{ collection2.related_objects << @af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch,/ActiveFedora::Base:.*> is not a PCDM object/)
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 'should NOT accept Hydra::PCDM::Files as parent object' do
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 'should NOT accept non-PCDM objects as parent object' do
487
- expect{ @non_PCDM_object.related_objects << object1 }.to raise_error(NoMethodError)
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 'should NOT accept AF::Base objects as parent object' do
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{ @non_PCDM_object.related_objects }.to raise_error(NoMethodError)
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 "remove related objects" do
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( subject.related_objects ).to eq [object1]
523
+ expect(subject.related_objects).to eq [object1]
516
524
  end
517
525
 
518
- it 'should remove related object while changes are in memory' do
519
- expect( subject.related_objects.delete object1 ).to eq [object1]
520
- expect( subject.related_objects ).to eq []
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 'should remove related object only when objects & collections and all changes are in memory' do
524
- subject.child_collections << collection1
525
- subject.child_collections << collection2
526
- subject.child_objects << object3
527
- subject.child_objects << object2
528
- expect( subject.related_objects.delete object1 ).to eq [object1]
529
- expect( subject.related_objects ).to eq []
530
- expect( subject.child_collections ).to eq [collection1,collection2]
531
- expect( subject.child_objects ).to eq [object3,object2]
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( subject.related_objects ).to eq [object1,object2,object3]
550
+ expect(subject.related_objects).to eq [object1, object2, object3]
543
551
  end
544
552
 
545
- it 'should remove first related object when changes are in memory' do
546
- expect( subject.related_objects.delete object1 ).to eq [object1]
547
- expect( subject.related_objects ).to eq [object2,object3]
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 'should remove last related object when changes are in memory' do
551
- expect( subject.related_objects.delete object3 ).to eq [object3]
552
- expect( subject.related_objects ).to eq [object1,object2]
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 'should remove middle related object when changes are in memory' do
556
- expect( subject.related_objects.delete object2 ).to eq [object2]
557
- expect( subject.related_objects ).to eq [object1,object3]
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 'should remove middle related object when changes are saved' do
561
- expect( subject.related_objects ).to eq [object1,object2,object3]
562
- expect( subject.related_objects.delete object2 ).to eq [object2]
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( subject.reload.related_objects ).to eq [object1,object3]
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 'should return empty array when 0 related objects and 0 collections and objects' do
572
- expect( subject.related_objects.delete object1 ).to eq []
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 'should return empty array when 0 related objects, but has collections and objects and changes in memory' do
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( subject.related_objects.delete object1 ).to eq []
588
+ expect(subject.related_objects.delete object1).to eq []
581
589
  end
582
590
 
583
- it 'should return empty array when other related objects and changes are in memory' do
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( subject.related_objects.delete object2 ).to eq []
594
+ expect(subject.related_objects.delete object2).to eq []
587
595
  end
588
596
 
589
- it 'should return empty array when changes are saved' do
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( subject.reload.related_objects.delete object2 ).to eq []
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
- @non_PCDM_object = "I'm not a PCDM object"
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 'should NOT accept Hydra::PCDM::Files as parent collection' do
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 'should NOT accept non-PCDM objects as parent collection' do
611
- expect{ @non_PCDM_object.related_objects.delete object1 }.to raise_error(NoMethodError)
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 'should NOT accept AF::Base objects as parent collection' do
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 '#child_collections=' do
621
- it 'should aggregate collections' do
622
- collection1.child_collections = [collection2, collection3]
623
- expect(collection1.child_collections).to eq [collection2, collection3]
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 '#child_objects=' do
628
- it 'should aggregate objects' do
629
- collection1.child_objects = [object1,object2]
630
- expect(collection1.child_objects).to eq [object1,object2]
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 "#child_collection_ids" do
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.child_collections = [child1, child2] }
686
+ before { object.collections = [child1, child2] }
639
687
 
640
- subject { object.child_collection_ids }
688
+ subject { object.collection_ids }
641
689
 
642
- it { is_expected.to eq ["1", "2"] }
690
+ it { is_expected.to eq %w(1 2) }
643
691
  end
644
692
 
645
- describe 'child_collections and child_objects' do
646
- subject { Hydra::PCDM::Collection.new }
693
+ describe 'collections and objects' do
694
+ subject { described_class.new }
647
695
 
648
- it 'should return empty array when no members' do
649
- expect( subject.child_collections ).to eq []
650
- expect( subject.child_objects ).to eq []
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 'child_collections should return empty array when only objects are aggregated' do
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( subject.child_collections ).to eq []
704
+ expect(subject.collections).to eq []
657
705
  end
658
706
 
659
- it 'child_objects should return empty array when only collections are aggregated' do
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( subject.child_objects ).to eq []
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 'should only return collections' do
667
- subject.child_collections << collection1
714
+ it 'returns only collections' do
715
+ subject.collections << collection1
668
716
  subject.members << collection2
669
- subject.child_objects << object1
717
+ subject.objects << object1
670
718
  subject.members << object2
671
- expect( subject.child_collections ).to eq [collection1,collection2]
672
- expect( subject.child_objects ).to eq [object1,object2]
673
- expect( subject.members ).to eq [collection1,collection2,object1,object2]
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 = Hydra::PCDM::Collection.new
684
- @collection2 = Hydra::PCDM::Collection.new
685
- @collection = Hydra::PCDM::Collection.new
686
- @collection1.child_collections << @collection
687
- @collection2.child_collections << @collection
688
- allow(@collection).to receive(:id).and_return("banana")
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
- build_proxy(container: @collection1),
691
- build_proxy(container: @collection2),
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 'parents' do
697
- subject { @collection.parents }
698
- it "finds all nodes that aggregate the object with hasMember" do
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 'parent_collections' do
705
- subject { @collection.parent_collections }
706
- it "finds collections that aggregate the object with hasMember" do
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 ".indexer" do
763
+ describe '.indexer' do
717
764
  after do
718
765
  Object.send(:remove_const, :Foo)
719
766
  end
720
767
 
721
- context "without overriding" do
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 "when overridden with AS::Concern" do
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