hydra-works 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +72 -0
  4. data/Gemfile +5 -4
  5. data/README.md +17 -11
  6. data/Rakefile +18 -8
  7. data/config/solrconfig.xml +223 -0
  8. data/hydra-works.gemspec +15 -15
  9. data/lib/hydra/works.rb +28 -17
  10. data/lib/hydra/works/errors/full_text_extraction_error.rb +5 -0
  11. data/lib/hydra/works/models/concerns/block_child_objects.rb +12 -6
  12. data/lib/hydra/works/models/concerns/collection_behavior.rb +44 -6
  13. data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +3 -3
  14. data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +2 -4
  15. data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +1 -3
  16. data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +4 -6
  17. data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +13 -14
  18. data/lib/hydra/works/models/concerns/generic_file_behavior.rb +13 -3
  19. data/lib/hydra/works/models/concerns/generic_work_behavior.rb +34 -9
  20. data/lib/hydra/works/models/generic_file.rb +0 -3
  21. data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +14 -16
  22. data/lib/hydra/works/services/generic_file/full_text_extraction_service.rb +57 -0
  23. data/lib/hydra/works/services/generic_file/generate_thumbnail.rb +13 -0
  24. data/lib/hydra/works/services/generic_file/persist_derivative.rb +3 -5
  25. data/lib/hydra/works/services/generic_file/{upload_file.rb → upload_file_to_generic_file.rb} +1 -3
  26. data/lib/hydra/works/version.rb +1 -1
  27. data/lib/hydra/works/vocab/works_terms.rb +9 -9
  28. data/lib/tasks/hydra-works_tasks.rake +80 -0
  29. data/lib/tasks/jetty.rake +15 -0
  30. data/spec/hydra/works/models/collection_spec.rb +258 -246
  31. data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +6 -8
  32. data/spec/hydra/works/models/concerns/generic_file/contained_files_spec.rb +40 -48
  33. data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +16 -18
  34. data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +11 -11
  35. data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +11 -8
  36. data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
  37. data/spec/hydra/works/models/generic_file_spec.rb +87 -85
  38. data/spec/hydra/works/models/generic_work_spec.rb +167 -169
  39. data/spec/hydra/works/services/full_text_extraction_service_spec.rb +89 -0
  40. data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +36 -38
  41. data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +10 -12
  42. data/spec/hydra/works/services/generic_file/upload_file_spec.rb +39 -42
  43. data/spec/hydra/works/services/persist_derivatives_spec.rb +2 -3
  44. data/spec/hydra/works_spec.rb +57 -61
  45. data/spec/spec_helper.rb +2 -4
  46. metadata +23 -15
  47. data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +0 -18
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Works::GenericWork do
4
-
5
4
  subject { Hydra::Works::GenericWork::Base.new }
6
5
 
7
6
  let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
@@ -16,30 +15,30 @@ describe Hydra::Works::GenericWork do
16
15
  let(:object1) { Hydra::PCDM::Object.new }
17
16
  let(:object2) { Hydra::PCDM::Object.new }
18
17
 
19
- let(:pcdm_file1) { Hydra::PCDM::File.new }
18
+ let(:pcdm_file1) { Hydra::PCDM::File.new }
20
19
 
21
- describe '#child_generic_works=' do
22
- it 'should aggregate generic_works' do
23
- generic_work1.child_generic_works = [generic_work2, generic_work3]
24
- expect(generic_work1.child_generic_works).to eq [generic_work2, generic_work3]
20
+ describe '#generic_works=' do
21
+ it 'aggregates generic_works' do
22
+ generic_work1.generic_works = [generic_work2, generic_work3]
23
+ expect(generic_work1.generic_works).to eq [generic_work2, generic_work3]
25
24
  end
26
25
  end
27
26
 
28
27
  describe '#generic_files=' do
29
- it 'should aggregate generic_files' do
28
+ it 'aggregates generic_files' do
30
29
  generic_work1.generic_files = [generic_file1, generic_file2]
31
30
  expect(generic_work1.generic_files).to eq [generic_file1, generic_file2]
32
31
  end
33
32
  end
34
33
 
35
34
  describe '#generic_file_ids' do
36
- it 'should list child generic_file ids' do
35
+ it 'lists generic_file ids' do
37
36
  generic_work1.generic_files = [generic_file1, generic_file2]
38
37
  expect(generic_work1.generic_file_ids).to eq [generic_file1.id, generic_file2.id]
39
38
  end
40
39
  end
41
40
 
42
- context "sub-class" do
41
+ context 'sub-class' do
43
42
  before do
44
43
  class TestWork < Hydra::Works::GenericWork::Base
45
44
  end
@@ -47,17 +46,11 @@ describe Hydra::Works::GenericWork do
47
46
 
48
47
  subject { TestWork.new(generic_files: [generic_file1]) }
49
48
 
50
- it "should have many generic files" do
49
+ it 'has many generic files' do
51
50
  expect(subject.generic_files).to eq [generic_file1]
52
51
  end
53
52
  end
54
53
 
55
- describe '#contains' do
56
- it 'should present as a missing method' do
57
- expect{ generic_work1.contains = [pcdm_file1] }.to raise_error(NoMethodError,"works can not directly contain files. You must add a GenericFile to the work's members and add files to that GenericFile.")
58
- end
59
- end
60
-
61
54
  describe 'Related objects' do
62
55
  let(:generic_work1) { Hydra::Works::GenericWork::Base.new }
63
56
  let(:object1) { Hydra::PCDM::Object.new }
@@ -71,20 +64,19 @@ describe Hydra::Works::GenericWork do
71
64
  end
72
65
  end
73
66
 
74
- describe '#child_generic_works' do
67
+ describe '#generic_works' do
75
68
  context 'with acceptable generic_works' do
76
-
77
69
  context 'with generic_files and generic_works' do
78
70
  before do
79
71
  subject.generic_files << generic_file1
80
72
  subject.generic_files << generic_file2
81
- subject.child_generic_works << generic_work1
82
- subject.child_generic_works << generic_work2
73
+ subject.generic_works << generic_work1
74
+ subject.generic_works << generic_work2
83
75
  end
84
76
 
85
- it 'should add generic_work to generic_work with generic_files and generic_works' do
86
- subject.child_generic_works << generic_work3
87
- expect(subject.child_generic_works).to eq [generic_work1,generic_work2,generic_work3]
77
+ it 'adds generic_work to generic_work with generic_files and generic_works' do
78
+ subject.generic_works << generic_work3
79
+ expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3]
88
80
  end
89
81
  end
90
82
 
@@ -97,9 +89,9 @@ describe Hydra::Works::GenericWork do
97
89
  after { Object.send(:remove_const, :DummyIncWork) }
98
90
  let(:iwork1) { DummyIncWork.new }
99
91
 
100
- it 'should accept implementing generic_work as a child' do
101
- subject.child_generic_works << iwork1
102
- expect(subject.child_generic_works).to eq [iwork1]
92
+ it 'accepts implementing generic_work as a child' do
93
+ subject.generic_works << iwork1
94
+ expect(subject.generic_works).to eq [iwork1]
103
95
  end
104
96
  end
105
97
 
@@ -111,9 +103,9 @@ describe Hydra::Works::GenericWork do
111
103
  after { Object.send(:remove_const, :DummyExtWork) }
112
104
  let(:ework1) { DummyExtWork.new }
113
105
 
114
- it 'should accept extending generic_work as a child' do
115
- subject.child_generic_works << ework1
116
- expect(subject.child_generic_works).to eq [ework1]
106
+ it 'accepts extending generic_work as a child' do
107
+ subject.generic_works << ework1
108
+ expect(subject.generic_works).to eq [ework1]
117
109
  end
118
110
  end
119
111
  end
@@ -127,116 +119,115 @@ describe Hydra::Works::GenericWork do
127
119
  @pcdm_collection101 = Hydra::PCDM::Collection.new
128
120
  @pcdm_object101 = Hydra::PCDM::Object.new
129
121
  @pcdm_file101 = Hydra::PCDM::File.new
130
- @non_PCDM_object = "I'm not a PCDM object"
122
+ @non_pcdm_object = "I'm not a PCDM object"
131
123
  @af_base_object = ActiveFedora::Base.new
132
124
  end
133
125
 
134
126
  context 'that are unacceptable child generic works' do
135
-
136
127
  let(:error_type1) { ArgumentError }
137
128
  let(:error_message1) { /Hydra::Works::(GenericFile::Base|Collection) with ID: was expected to works_generic_work\?, but it was false/ }
138
129
  let(:error_type2) { NoMethodError }
139
130
  let(:error_message2) { /undefined method `works_generic_work\?' for .*/ }
140
131
 
141
- it 'should NOT aggregate Hydra::Works::Collection in generic works aggregation' do
142
- expect{ subject.child_generic_works << @works_collection101 }.to raise_error(error_type1,error_message1)
132
+ it 'does not aggregate Hydra::Works::Collection in generic works aggregation' do
133
+ expect { subject.generic_works << @works_collection101 }.to raise_error(error_type1, error_message1)
143
134
  end
144
135
 
145
- it 'should NOT aggregate Hydra::Works::GenericFile in generic works aggregation' do
146
- expect{ subject.child_generic_works << @generic_file101 }.to raise_error(error_type1,error_message1)
136
+ it 'does not aggregate Hydra::Works::GenericFile in generic works aggregation' do
137
+ expect { subject.generic_works << @generic_file101 }.to raise_error(error_type1, error_message1)
147
138
  end
148
139
 
149
- it 'should NOT aggregate Hydra::PCDM::Collections in generic works aggregation' do
150
- expect{ subject.child_generic_works << @pcdm_collection101 }.to raise_error(error_type2,error_message2)
140
+ it 'does not aggregate Hydra::PCDM::Collections in generic works aggregation' do
141
+ expect { subject.generic_works << @pcdm_collection101 }.to raise_error(error_type2, error_message2)
151
142
  end
152
143
 
153
- it 'should NOT aggregate Hydra::PCDM::Objects in generic works aggregation' do
154
- expect{ subject.child_generic_works << @pcdm_object101 }.to raise_error(error_type2,error_message2)
144
+ it 'does not aggregate Hydra::PCDM::Objects in generic works aggregation' do
145
+ expect { subject.generic_works << @pcdm_object101 }.to raise_error(error_type2, error_message2)
155
146
  end
156
147
 
157
- it 'should NOT aggregate Hydra::PCDM::Files in generic works aggregation' do
158
- expect{ subject.child_generic_works << @pcdm_file101 }.to raise_error(error_type2,error_message2)
148
+ it 'does not aggregate Hydra::PCDM::Files in generic works aggregation' do
149
+ expect { subject.generic_works << @pcdm_file101 }.to raise_error(error_type2, error_message2)
159
150
  end
160
151
 
161
- it 'should NOT aggregate non-PCDM objects in generic works aggregation' do
162
- expect{ subject.child_generic_works << @non_PCDM_object }.to raise_error(error_type2,error_message2)
152
+ it 'does not aggregate non-PCDM objects in generic works aggregation' do
153
+ expect { subject.generic_works << @non_pcdm_object }.to raise_error(error_type2, error_message2)
163
154
  end
164
155
 
165
- it 'should NOT aggregate AF::Base objects in generic works aggregation' do
166
- expect{ subject.child_generic_works << @af_base_object }.to raise_error(error_type2,error_message2)
156
+ it 'does not aggregate AF::Base objects in generic works aggregation' do
157
+ expect { subject.generic_works << @af_base_object }.to raise_error(error_type2, error_message2)
167
158
  end
168
159
  end
169
160
  end
170
161
  end
171
162
 
172
163
  describe '#generic_files <<' do
173
- it 'should return empty array when only generic_files are aggregated' do
164
+ it 'returns empty array when only generic_files are aggregated' do
174
165
  subject.generic_files << generic_file1
175
166
  subject.generic_files << generic_file2
176
- expect(subject.child_generic_works).to eq []
167
+ expect(subject.generic_works).to eq []
177
168
  end
178
169
 
179
170
  context 'with generic_files and generic_works' do
180
171
  before do
181
172
  subject.generic_files << generic_file1
182
173
  subject.generic_files << generic_file2
183
- subject.child_generic_works << generic_work1
184
- subject.child_generic_works << generic_work2
174
+ subject.generic_works << generic_work1
175
+ subject.generic_works << generic_work2
185
176
  end
186
177
 
187
- it 'should only return generic_works' do
188
- expect(subject.child_generic_works).to eq [generic_work1,generic_work2]
178
+ it 'returns only generic_works' do
179
+ expect(subject.generic_works).to eq [generic_work1, generic_work2]
189
180
  end
190
- end
181
+ end
191
182
  end
192
183
 
193
- describe '#child_generic_works.delete' do
184
+ describe '#generic_works.delete' do
194
185
  context 'when multiple collections' do
195
186
  before do
196
- subject.child_generic_works << generic_work1
197
- subject.child_generic_works << generic_work2
187
+ subject.generic_works << generic_work1
188
+ subject.generic_works << generic_work2
198
189
  subject.generic_files << generic_file2
199
- subject.child_generic_works << generic_work3
200
- subject.child_generic_works << generic_work4
190
+ subject.generic_works << generic_work3
191
+ subject.generic_works << generic_work4
201
192
  subject.generic_files << generic_file1
202
- subject.child_generic_works << generic_work5
203
- expect(subject.child_generic_works).to eq [generic_work1,generic_work2,generic_work3,generic_work4,generic_work5]
193
+ subject.generic_works << generic_work5
194
+ expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3, generic_work4, generic_work5]
204
195
  end
205
196
 
206
- it 'should remove first collection' do
207
- expect(subject.child_generic_works.delete generic_work1).to eq [generic_work1]
208
- expect(subject.child_generic_works).to eq [generic_work2,generic_work3,generic_work4,generic_work5]
209
- expect(subject.generic_files).to eq [generic_file2,generic_file1]
197
+ it 'removes first collection' do
198
+ expect(subject.generic_works.delete generic_work1).to eq [generic_work1]
199
+ expect(subject.generic_works).to eq [generic_work2, generic_work3, generic_work4, generic_work5]
200
+ expect(subject.generic_files).to eq [generic_file2, generic_file1]
210
201
  end
211
202
 
212
- it 'should remove last collection' do
213
- expect(subject.child_generic_works.delete generic_work5).to eq [generic_work5]
214
- expect(subject.child_generic_works).to eq [generic_work1,generic_work2,generic_work3,generic_work4]
215
- expect(subject.generic_files).to eq [generic_file2,generic_file1]
203
+ it 'removes last collection' do
204
+ expect(subject.generic_works.delete generic_work5).to eq [generic_work5]
205
+ expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work3, generic_work4]
206
+ expect(subject.generic_files).to eq [generic_file2, generic_file1]
216
207
  end
217
208
 
218
- it 'should remove middle collection' do
219
- expect(subject.child_generic_works.delete generic_work3).to eq [generic_work3]
220
- expect(subject.child_generic_works).to eq [generic_work1,generic_work2,generic_work4,generic_work5]
221
- expect(subject.generic_files).to eq [generic_file2,generic_file1]
209
+ it 'removes middle collection' do
210
+ expect(subject.generic_works.delete generic_work3).to eq [generic_work3]
211
+ expect(subject.generic_works).to eq [generic_work1, generic_work2, generic_work4, generic_work5]
212
+ expect(subject.generic_files).to eq [generic_file2, generic_file1]
222
213
  end
223
214
  end
224
215
  end
225
216
 
226
- describe '#child_generic_works <<' do
217
+ describe '#generic_works <<' do
227
218
  context 'with acceptable generic_works' do
228
219
  context 'with generic_files and generic_works' do
229
220
  let(:generic_file3) { Hydra::Works::GenericFile::Base.new }
230
221
  before do
231
222
  subject.generic_files << generic_file1
232
223
  subject.generic_files << generic_file2
233
- subject.child_generic_works << generic_work1
234
- subject.child_generic_works << generic_work2
224
+ subject.generic_works << generic_work1
225
+ subject.generic_works << generic_work2
235
226
  end
236
227
 
237
- it 'should add generic_file to generic_work with generic_files and generic_works' do
228
+ it 'adds generic_file to generic_work with generic_files and generic_works' do
238
229
  subject.generic_files << generic_file3
239
- expect(subject.generic_files).to eq [generic_file1,generic_file2,generic_file3]
230
+ expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file3]
240
231
  end
241
232
  end
242
233
 
@@ -249,11 +240,10 @@ describe Hydra::Works::GenericWork do
249
240
  after { Object.send(:remove_const, :DummyIncFile) }
250
241
  let(:ifile1) { DummyIncFile.new }
251
242
 
252
- it 'should accept implementing generic_file as a child' do
243
+ it 'accepts implementing generic_file as a child' do
253
244
  subject.generic_files << ifile1
254
245
  expect(subject.generic_files).to eq [ifile1]
255
246
  end
256
-
257
247
  end
258
248
 
259
249
  describe 'aggregates generic_files that extend Hydra::Works::GenericFile::Base' do
@@ -264,7 +254,7 @@ describe Hydra::Works::GenericWork do
264
254
  after { Object.send(:remove_const, :DummyExtFile) }
265
255
  let(:efile1) { DummyExtFile.new }
266
256
 
267
- it 'should accept extending generic_file as a child' do
257
+ it 'accepts extending generic_file as a child' do
268
258
  subject.generic_files << efile1
269
259
  expect(subject.generic_files).to eq [efile1]
270
260
  end
@@ -281,54 +271,53 @@ describe Hydra::Works::GenericWork do
281
271
  @pcdm_collection101 = Hydra::PCDM::Collection.new
282
272
  @pcdm_object101 = Hydra::PCDM::Object.new
283
273
  @pcdm_file101 = Hydra::PCDM::File.new
284
- @non_PCDM_object = "I'm not a PCDM object"
274
+ @non_pcdm_object = "I'm not a PCDM object"
285
275
  @af_base_object = ActiveFedora::Base.new
286
276
  end
287
277
 
288
278
  context 'that are unacceptable child generic files' do
289
-
290
279
  let(:error_type1) { ArgumentError }
291
280
  let(:error_message1) { /Hydra::Works::(GenericWork::Base|Collection) with ID: was expected to works_generic_file\?, but it was false/ }
292
281
  let(:error_type2) { NoMethodError }
293
282
  let(:error_message2) { /undefined method `works_generic_file\?' for .*/ }
294
283
 
295
- it 'should NOT aggregate Hydra::Works::Collection in generic files aggregation' do
296
- expect{ subject.generic_files << @works_collection101 }.to raise_error(error_type1,error_message1)
284
+ it 'does not aggregate Hydra::Works::Collection in generic files aggregation' do
285
+ expect { subject.generic_files << @works_collection101 }.to raise_error(error_type1, error_message1)
297
286
  end
298
287
 
299
- it 'should NOT aggregate Hydra::Works::GenericWork in generic files aggregation' do
300
- expect{ subject.generic_files << @generic_work101 }.to raise_error(error_type1,error_message1)
288
+ it 'does not aggregate Hydra::Works::GenericWork in generic files aggregation' do
289
+ expect { subject.generic_files << @generic_work101 }.to raise_error(error_type1, error_message1)
301
290
  end
302
291
 
303
- it 'should NOT aggregate Hydra::PCDM::Collections in generic files aggregation' do
304
- expect{ subject.generic_files << @pcdm_collection101 }.to raise_error(error_type2,error_message2)
292
+ it 'does not aggregate Hydra::PCDM::Collections in generic files aggregation' do
293
+ expect { subject.generic_files << @pcdm_collection101 }.to raise_error(error_type2, error_message2)
305
294
  end
306
295
 
307
- it 'should NOT aggregate Hydra::PCDM::Objects in generic files aggregation' do
308
- expect{ subject.generic_files << @pcdm_object101 }.to raise_error(error_type2,error_message2)
296
+ it 'does not aggregate Hydra::PCDM::Objects in generic files aggregation' do
297
+ expect { subject.generic_files << @pcdm_object101 }.to raise_error(error_type2, error_message2)
309
298
  end
310
299
 
311
- it 'should NOT aggregate Hydra::PCDM::Files in generic files aggregation' do
312
- expect{ subject.generic_files << @pcdm_file101 }.to raise_error(error_type2,error_message2)
300
+ it 'does not aggregate Hydra::PCDM::Files in generic files aggregation' do
301
+ expect { subject.generic_files << @pcdm_file101 }.to raise_error(error_type2, error_message2)
313
302
  end
314
303
 
315
- it 'should NOT aggregate non-PCDM objects in generic files aggregation' do
316
- expect{ subject.generic_files << @non_PCDM_object }.to raise_error(error_type2,error_message2)
304
+ it 'does not aggregate non-PCDM objects in generic files aggregation' do
305
+ expect { subject.generic_files << @non_pcdm_object }.to raise_error(error_type2, error_message2)
317
306
  end
318
307
 
319
- it 'should NOT aggregate AF::Base objects in generic files aggregation' do
320
- expect{ subject.generic_files << @af_base_object }.to raise_error(error_type2,error_message2)
308
+ it 'does not aggregate AF::Base objects in generic files aggregation' do
309
+ expect { subject.generic_files << @af_base_object }.to raise_error(error_type2, error_message2)
321
310
  end
322
311
  end
323
312
  end
324
313
  end
325
314
 
326
- context "move generic file" do
327
- before do
315
+ context 'move generic file' do
316
+ before do
328
317
  subject.generic_files << generic_file1
329
318
  subject.generic_files << generic_file2
330
319
  end
331
- it "moves file from one work to another" do
320
+ it 'moves file from one work to another' do
332
321
  expect(subject.generic_files).to eq([generic_file1, generic_file2])
333
322
  expect(generic_work1.generic_files).to eq([])
334
323
  generic_work1.generic_files << subject.generic_files.delete(generic_file1)
@@ -338,9 +327,9 @@ describe Hydra::Works::GenericWork do
338
327
  end
339
328
 
340
329
  describe '#generic_files' do
341
- it 'should return empty array when only generic_works are aggregated' do
342
- subject.child_generic_works << generic_work1
343
- subject.child_generic_works << generic_work2
330
+ it 'returns empty array when only generic_works are aggregated' do
331
+ subject.generic_works << generic_work1
332
+ subject.generic_works << generic_work2
344
333
  expect(subject.generic_files).to eq []
345
334
  end
346
335
 
@@ -348,14 +337,14 @@ describe Hydra::Works::GenericWork do
348
337
  before do
349
338
  subject.generic_files << generic_file1
350
339
  subject.generic_files << generic_file2
351
- subject.child_generic_works << generic_work1
352
- subject.child_generic_works << generic_work2
340
+ subject.generic_works << generic_work1
341
+ subject.generic_works << generic_work2
353
342
  end
354
343
 
355
- it 'should only return generic_files' do
356
- expect(subject.generic_files).to eq [generic_file1,generic_file2]
344
+ it 'returns only generic_files' do
345
+ expect(subject.generic_files).to eq [generic_file1, generic_file2]
357
346
  end
358
- end
347
+ end
359
348
  end
360
349
 
361
350
  describe '#generic_files.delete' do
@@ -366,39 +355,37 @@ describe Hydra::Works::GenericWork do
366
355
  before do
367
356
  subject.generic_files << generic_file1
368
357
  subject.generic_files << generic_file2
369
- subject.child_generic_works << generic_work2
358
+ subject.generic_works << generic_work2
370
359
  subject.generic_files << generic_file3
371
360
  subject.generic_files << generic_file4
372
- subject.child_generic_works << generic_work1
361
+ subject.generic_works << generic_work1
373
362
  subject.generic_files << generic_file5
374
- expect(subject.generic_files).to eq [generic_file1,generic_file2,generic_file3,generic_file4,generic_file5]
363
+ expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file3, generic_file4, generic_file5]
375
364
  end
376
365
 
377
- it 'should remove first collection' do
366
+ it 'removes first collection' do
378
367
  expect(subject.generic_files.delete generic_file1).to eq [generic_file1]
379
- expect(subject.generic_files).to eq [generic_file2,generic_file3,generic_file4,generic_file5]
380
- expect(subject.child_generic_works).to eq [generic_work2,generic_work1]
368
+ expect(subject.generic_files).to eq [generic_file2, generic_file3, generic_file4, generic_file5]
369
+ expect(subject.generic_works).to eq [generic_work2, generic_work1]
381
370
  end
382
371
 
383
- it 'should remove last collection' do
372
+ it 'removes last collection' do
384
373
  expect(subject.generic_files.delete generic_file5).to eq [generic_file5]
385
- expect(subject.generic_files).to eq [generic_file1,generic_file2,generic_file3,generic_file4]
386
- expect(subject.child_generic_works).to eq [generic_work2,generic_work1]
374
+ expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file3, generic_file4]
375
+ expect(subject.generic_works).to eq [generic_work2, generic_work1]
387
376
  end
388
377
 
389
- it 'should remove middle collection' do
378
+ it 'removes middle collection' do
390
379
  expect(subject.generic_files.delete generic_file3).to eq [generic_file3]
391
- expect(subject.generic_files).to eq [generic_file1,generic_file2,generic_file4,generic_file5]
392
- expect(subject.child_generic_works).to eq [generic_work2,generic_work1]
380
+ expect(subject.generic_files).to eq [generic_file1, generic_file2, generic_file4, generic_file5]
381
+ expect(subject.generic_works).to eq [generic_work2, generic_work1]
393
382
  end
394
383
  end
395
384
  end
396
385
 
397
386
  describe '#related_objects' do
398
-
399
387
  context 'with acceptable related objects' do
400
-
401
- it 'should add various types of related objects to generic_work' do
388
+ it 'adds various types of related objects to generic_work' do
402
389
  subject.related_objects << generic_work1
403
390
  subject.related_objects << generic_file1
404
391
  subject.related_objects << object1
@@ -414,12 +401,12 @@ describe Hydra::Works::GenericWork do
414
401
  before do
415
402
  subject.generic_files << generic_file1
416
403
  subject.generic_files << generic_file2
417
- subject.child_generic_works << generic_work1
418
- subject.child_generic_works << generic_work2
404
+ subject.generic_works << generic_work1
405
+ subject.generic_works << generic_work2
419
406
  subject.related_objects << object1
420
407
  end
421
408
 
422
- it 'should add a related object to generic_work with generic_works and generic_files' do
409
+ it 'adds a related object to generic_work with generic_works and generic_files' do
423
410
  subject.related_objects << object2
424
411
  subject.save
425
412
  subject.reload
@@ -439,37 +426,37 @@ describe Hydra::Works::GenericWork do
439
426
 
440
427
  let(:error_message) { 'child_related_object must be a pcdm object' }
441
428
 
442
- it 'should NOT aggregate Hydra::Works::Collection in related objects aggregation' do
443
- expect{ subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
429
+ it 'does not aggregate Hydra::Works::Collection in related objects aggregation' do
430
+ expect { subject.related_objects << collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::Works::Collection:.*> is not a PCDM object./)
444
431
  end
445
432
 
446
- it 'should NOT aggregate Hydra::PCDM::Collections in related objects aggregation' do
447
- expect{ subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.*> is not a PCDM object./)
433
+ it 'does not aggregate Hydra::PCDM::Collections in related objects aggregation' do
434
+ expect { subject.related_objects << pcdm_collection1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /Hydra::PCDM::Collection:.*> is not a PCDM object./)
448
435
  end
449
436
 
450
- it 'should NOT aggregate Hydra::PCDM::Files in related objects aggregation' do
451
- expect{ subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
437
+ it 'does not aggregate Hydra::PCDM::Files in related objects aggregation' do
438
+ expect { subject.related_objects << pcdm_file1 }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got Hydra::PCDM::File.*/)
452
439
  end
453
440
 
454
- it 'should NOT aggregate non-PCDM objects in related objects aggregation' do
455
- expect{ subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
441
+ it 'does not aggregate non-PCDM objects in related objects aggregation' do
442
+ expect { subject.related_objects << non_PCDM_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base.* expected, got String.*/)
456
443
  end
457
444
 
458
- it 'should NOT aggregate AF::Base objects in related objects aggregation' do
459
- expect{ subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base:.*> is not a PCDM object./)
445
+ it 'does not aggregate AF::Base objects in related objects aggregation' do
446
+ expect { subject.related_objects << af_base_object }.to raise_error(ActiveFedora::AssociationTypeMismatch, /ActiveFedora::Base:.*> is not a PCDM object./)
460
447
  end
461
448
  end
462
449
 
463
450
  context 'with invalid bahaviors' do
464
- it 'should NOT allow related objects to repeat' do
451
+ it 'does not allow related objects to repeat' do
465
452
  skip 'skipping this test because issue pcdm#92 needs to be addressed' do
466
- subject.related_objects << object1
467
- subject.related_objects << object2
468
- subject.related_objects << object1
469
- expect(subject.related_objects.include? object1).to be true
470
- expect(subject.related_objects.include? object2).to be true
471
- expect(subject.related_objects.size).to eq 2
472
- end
453
+ subject.related_objects << object1
454
+ subject.related_objects << object2
455
+ subject.related_objects << object1
456
+ expect(subject.related_objects.include? object1).to be true
457
+ expect(subject.related_objects.include? object2).to be true
458
+ expect(subject.related_objects.size).to eq 2
459
+ end
473
460
  end
474
461
  end
475
462
  end
@@ -477,28 +464,28 @@ describe Hydra::Works::GenericWork do
477
464
  describe '#related_objects <<' do
478
465
  context 'with generic files and works' do
479
466
  before do
480
- subject.child_generic_works << generic_work1
481
- subject.child_generic_works << generic_work1
467
+ subject.generic_works << generic_work1
468
+ subject.generic_works << generic_work1
482
469
  subject.generic_files << generic_file1
483
470
  end
484
471
 
485
- it 'should return empty array when only generic files and generic works are aggregated' do
472
+ it 'returns empty array when only generic files and generic works are aggregated' do
486
473
  expect(subject.related_objects).to eq []
487
474
  end
488
475
 
489
- it 'should only return related objects' do
476
+ it 'returns only related objects' do
490
477
  subject.related_objects << object2
491
478
  expect(subject.related_objects).to eq [object2]
492
479
  end
493
480
 
494
- it 'should return related objects of various types' do
481
+ it 'returns related objects of various types' do
495
482
  subject.related_objects << generic_work2
496
483
  subject.related_objects << generic_file1
497
484
  subject.related_objects << object1
498
- expect(subject.related_objects).to eq [generic_work2,generic_file1,object1]
485
+ expect(subject.related_objects).to eq [generic_work2, generic_file1, object1]
499
486
  expect(subject.related_objects.size).to eq 3
500
487
  end
501
- end
488
+ end
502
489
  end
503
490
 
504
491
  describe '#related_objects.delete' do
@@ -511,56 +498,67 @@ describe Hydra::Works::GenericWork do
511
498
  before do
512
499
  subject.related_objects << related_object1
513
500
  subject.related_objects << related_work2
514
- subject.child_generic_works << generic_work2
501
+ subject.generic_works << generic_work2
515
502
  subject.generic_files << generic_file1
516
503
  subject.related_objects << related_file3
517
504
  subject.related_objects << related_object4
518
- subject.child_generic_works << generic_work1
505
+ subject.generic_works << generic_work1
519
506
  subject.related_objects << related_work5
520
- expect(subject.related_objects).to eq [related_object1,related_work2,related_file3,related_object4,related_work5]
507
+ expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4, related_work5]
521
508
  end
522
509
 
523
- it 'should remove first related object' do
510
+ it 'removes first related object' do
524
511
  expect(subject.related_objects.delete related_object1).to eq [related_object1]
525
- expect(subject.related_objects).to eq [related_work2,related_file3,related_object4,related_work5]
526
- expect(subject.child_generic_works).to eq [generic_work2,generic_work1]
512
+ expect(subject.related_objects).to eq [related_work2, related_file3, related_object4, related_work5]
513
+ expect(subject.generic_works).to eq [generic_work2, generic_work1]
527
514
  expect(subject.generic_files).to eq [generic_file1]
528
515
  end
529
516
 
530
- it 'should remove last related object' do
517
+ it 'removes last related object' do
531
518
  expect(subject.related_objects.delete related_work5).to eq [related_work5]
532
- expect(subject.related_objects).to eq [related_object1,related_work2,related_file3,related_object4]
533
- expect(subject.child_generic_works).to eq [generic_work2,generic_work1]
519
+ expect(subject.related_objects).to eq [related_object1, related_work2, related_file3, related_object4]
520
+ expect(subject.generic_works).to eq [generic_work2, generic_work1]
534
521
  expect(subject.generic_files).to eq [generic_file1]
535
522
  end
536
523
 
537
- it 'should remove middle related object' do
524
+ it 'removes middle related object' do
538
525
  expect(subject.related_objects.delete related_file3).to eq [related_file3]
539
- expect(subject.related_objects).to eq [related_object1,related_work2,related_object4,related_work5]
540
- expect(subject.child_generic_works).to eq [generic_work2,generic_work1]
526
+ expect(subject.related_objects).to eq [related_object1, related_work2, related_object4, related_work5]
527
+ expect(subject.generic_works).to eq [generic_work2, generic_work1]
541
528
  expect(subject.generic_files).to eq [generic_file1]
542
529
  end
543
530
  end
544
531
  end
545
532
 
546
- describe "should have parent work and collection accessors" do
533
+ describe 'should have parent work and collection accessors' do
547
534
  let(:collection1) { Hydra::Works::Collection.new }
548
535
  before do
549
- collection1.child_generic_works << generic_work2
550
- generic_work1.child_generic_works << generic_work2
536
+ collection1.generic_works << generic_work2
537
+ generic_work1.generic_works << generic_work2
551
538
  collection1.save
552
539
  generic_work1.save
553
540
  generic_work2.save
554
541
  end
555
542
 
556
- it 'should have parents' do
557
- expect(generic_work2.parents).to eq [collection1,generic_work1]
543
+ it 'has parents' do
544
+ expect(generic_work2.member_of).to eq [collection1, generic_work1]
558
545
  end
559
- it 'should have a parent collection' do
560
- expect(generic_work2.parent_collections).to eq [collection1]
546
+ it 'has a parent collection' do
547
+ expect(generic_work2.in_collections).to eq [collection1]
561
548
  end
562
- it 'should have a parent generic_work' do
549
+ it 'has a parent generic_work' do
550
+ expect(generic_work2.in_generic_works).to eq [generic_work1]
551
+ end
552
+ end
553
+
554
+ describe 'make sure deprecated methods still work' do
555
+ it 'deprecated methods should pass' do
556
+ expect(generic_work1.child_generic_works = [generic_work2]).to eq [generic_work2]
557
+ expect(generic_work1.child_generic_works << generic_work3).to eq [generic_work2, generic_work3]
558
+ expect(generic_work1.child_generic_works += [generic_work4]).to eq [generic_work2, generic_work3, generic_work4]
559
+ generic_work1.save # required until issue AF-Agg-75 is fixed
563
560
  expect(generic_work2.parent_generic_works).to eq [generic_work1]
561
+ expect(generic_work2.parents).to eq [generic_work1]
564
562
  end
565
563
  end
566
564
  end