hydra-pcdm 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e913d0d541120cd90ba7b1248d649d9db8d4ece
4
- data.tar.gz: 836913f3d1251a91dd6cc4bbbb491c3a1b2bfc77
3
+ metadata.gz: c0be7a3fa222eb99a0aac81f40a4946f03231891
4
+ data.tar.gz: c13f936e7d5b45e39e80108e91c7dc1a96f37336
5
5
  SHA512:
6
- metadata.gz: 5333b3cf2d17c4bf64597234759316bb3ef8a7af807bf1e1adf4a1312f22746d9d92deab8b55b6b6150f5247ff154ced8cdf702c707ff03dc2c2d3b2eb4d207f
7
- data.tar.gz: 4d01b55002fd90b154e577dc9340732fe7e7796ba154a80536fbc91a04e6d487a102fe25f75472fd3a7196aca57e1787d2fba099d48a94802880f3b31a84a2f3
6
+ metadata.gz: 91fa47b049b2886f33a8ff57e33c002926ebecc21d2209d6d50691b4ff8d4bc6c35be05f2a83e7ab64d87c43998b71c216687bf2db6f4d26ba990dcfb8dffc83
7
+ data.tar.gz: 1a15fc8ebba626fa74a78931d88f4dab56ee2e0880293c587a4b19406859961d672bca76cd1b47f4da9c731f55159f52b6bf39b6d06e31f08430ff91ede3ea2d
@@ -64,12 +64,8 @@ module Hydra::PCDM
64
64
  # file_of_type(::RDF::URI("http://pcdm.org/ExtractedText"))
65
65
  def file_of_type(uri)
66
66
  matching_files = filter_files_by_type(uri)
67
- if matching_files.empty?
68
- file = files.build
69
- Hydra::PCDM::AddTypeToFile.call(file, uri)
70
- else
71
- return matching_files.first
72
- end
67
+ return matching_files.first unless matching_files.empty?
68
+ Hydra::PCDM::AddTypeToFile.call(files.build, uri)
73
69
  end
74
70
  end
75
71
  end
@@ -24,6 +24,7 @@ module Hydra::PCDM
24
24
  end
25
25
 
26
26
  def member_of
27
+ return [] if id.nil?
27
28
  ActiveFedora::Base.where(member_ids_ssim: id)
28
29
  end
29
30
 
@@ -1,5 +1,5 @@
1
1
  module Hydra
2
2
  module PCDM
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'.freeze
4
4
  end
5
5
  end
@@ -238,20 +238,20 @@ describe Hydra::PCDM::Collection do
238
238
  end
239
239
  context 'when collection is missing' do
240
240
  it 'and 0 sub-collections should return empty array' do
241
- expect(subject.members.delete collection1).to eq []
241
+ expect(subject.members.delete(collection1)).to eq []
242
242
  end
243
243
 
244
244
  it 'and multiple sub-collections should return empty array when changes are in memory' do
245
245
  subject.ordered_members << collection1
246
246
  subject.ordered_members << collection3
247
- expect(subject.members.delete collection2).to eq []
247
+ expect(subject.members.delete(collection2)).to eq []
248
248
  end
249
249
 
250
250
  it 'returns empty array when changes are saved' do
251
251
  subject.ordered_members << collection1
252
252
  subject.ordered_members << collection3
253
253
  subject.save
254
- expect(subject.members.delete collection2).to eq []
254
+ expect(subject.members.delete(collection2)).to eq []
255
255
  end
256
256
  end
257
257
  end
@@ -313,9 +313,7 @@ describe Hydra::PCDM::Collection do
313
313
  collection1.related_objects << object2 # second add to same collection
314
314
  collection1.save
315
315
  related_objects = collection1.reload.related_objects
316
- expect(related_objects.include? object1).to be true
317
- expect(related_objects.include? object2).to be true
318
- expect(related_objects.size).to eq 2
316
+ expect(related_objects).to match_array [object1, object2]
319
317
  end
320
318
 
321
319
  it 'is empty when no related objects' do
@@ -328,9 +326,7 @@ describe Hydra::PCDM::Collection do
328
326
  collection1.related_objects << object2 # second add to same collection
329
327
  collection1.related_objects << object1 # repeat an object replaces the object
330
328
  related_objects = collection1.related_objects
331
- expect(related_objects.include? object1).to be true
332
- expect(related_objects.include? object2).to be true
333
- expect(related_objects.size).to eq 2
329
+ expect(related_objects).to match_array [object1, object2]
334
330
  end
335
331
  end
336
332
  end
@@ -397,7 +393,7 @@ describe Hydra::PCDM::Collection do
397
393
  end
398
394
 
399
395
  it 'removes related object while changes are in memory' do
400
- expect(subject.related_objects.delete object1).to eq [object1]
396
+ expect(subject.related_objects.delete(object1)).to eq [object1]
401
397
  expect(subject.related_objects).to eq []
402
398
  end
403
399
 
@@ -406,7 +402,7 @@ describe Hydra::PCDM::Collection do
406
402
  subject.ordered_members << collection2
407
403
  subject.ordered_members << object3
408
404
  subject.ordered_members << object2
409
- expect(subject.related_objects.delete object1).to eq [object1]
405
+ expect(subject.related_objects.delete(object1)).to eq [object1]
410
406
  expect(subject.related_objects).to eq []
411
407
  expect(subject.ordered_collections).to eq [collection1, collection2]
412
408
  expect(subject.ordered_objects).to eq [object3, object2]
@@ -424,23 +420,23 @@ describe Hydra::PCDM::Collection do
424
420
  end
425
421
 
426
422
  it 'removes first related object when changes are in memory' do
427
- expect(subject.related_objects.delete object1).to eq [object1]
423
+ expect(subject.related_objects.delete(object1)).to eq [object1]
428
424
  expect(subject.related_objects).to eq [object2, object3]
429
425
  end
430
426
 
431
427
  it 'removes last related object when changes are in memory' do
432
- expect(subject.related_objects.delete object3).to eq [object3]
428
+ expect(subject.related_objects.delete(object3)).to eq [object3]
433
429
  expect(subject.related_objects).to eq [object1, object2]
434
430
  end
435
431
 
436
432
  it 'removes middle related object when changes are in memory' do
437
- expect(subject.related_objects.delete object2).to eq [object2]
433
+ expect(subject.related_objects.delete(object2)).to eq [object2]
438
434
  expect(subject.related_objects).to eq [object1, object3]
439
435
  end
440
436
 
441
437
  it 'removes middle related object when changes are saved' do
442
438
  expect(subject.related_objects).to eq [object1, object2, object3]
443
- expect(subject.related_objects.delete object2).to eq [object2]
439
+ expect(subject.related_objects.delete(object2)).to eq [object2]
444
440
  subject.save
445
441
  expect(subject.reload.related_objects).to eq [object1, object3]
446
442
  end
@@ -450,7 +446,7 @@ describe Hydra::PCDM::Collection do
450
446
  let(:object3) { Hydra::PCDM::Object.new }
451
447
 
452
448
  it 'returns empty array when 0 related objects and 0 collections and objects' do
453
- expect(subject.related_objects.delete object1).to eq []
449
+ expect(subject.related_objects.delete(object1)).to eq []
454
450
  end
455
451
 
456
452
  it 'returns empty array when 0 related objects, but has collections and objects and changes in memory' do
@@ -458,20 +454,20 @@ describe Hydra::PCDM::Collection do
458
454
  subject.ordered_members << collection2
459
455
  subject.ordered_members << object1
460
456
  subject.ordered_members << object2
461
- expect(subject.related_objects.delete object1).to eq []
457
+ expect(subject.related_objects.delete(object1)).to eq []
462
458
  end
463
459
 
464
460
  it 'returns empty array when other related objects and changes are in memory' do
465
461
  subject.related_objects << object1
466
462
  subject.related_objects << object3
467
- expect(subject.related_objects.delete object2).to eq []
463
+ expect(subject.related_objects.delete(object2)).to eq []
468
464
  end
469
465
 
470
466
  it 'returns empty array when changes are saved' do
471
467
  subject.related_objects << object1
472
468
  subject.related_objects << object3
473
469
  subject.save
474
- expect(subject.reload.related_objects.delete object2).to eq []
470
+ expect(subject.reload.related_objects.delete(object2)).to eq []
475
471
  end
476
472
  end
477
473
  end
@@ -616,7 +612,7 @@ describe Hydra::PCDM::Collection do
616
612
 
617
613
  describe 'make sure deprecated methods still work' do
618
614
  it 'deprecated methods should pass' do
619
- expect(collection1.ordered_members = [collection2]).to eq [collection2]
615
+ collection1.ordered_members = [collection2]
620
616
  expect(collection1.ordered_members << collection3).to eq [collection2, collection3]
621
617
  expect(collection1.ordered_members += [collection4]).to eq [collection2, collection3, collection4]
622
618
  expect(collection1.ordered_members << object1).to eq [collection2, collection3, collection4, object1]
@@ -146,44 +146,73 @@ describe Hydra::PCDM::Object do
146
146
  end
147
147
  end
148
148
 
149
- context 'when aggregated by other objects' do
149
+ describe 'in_objects' do
150
+ let(:object) { described_class.create }
151
+ subject { object.in_objects }
152
+ let(:collection) { Hydra::PCDM::Collection.new }
153
+ let(:parent_object) { described_class.new }
150
154
  before do
151
- # Using before(:all) and instance variable because regular :let syntax had a significant impact on performance
152
- # All of the tests in this context are describing idempotent behavior, so isolation between examples isn't necessary.
153
- @collection1 = Hydra::PCDM::Collection.new
154
- @collection2 = Hydra::PCDM::Collection.new
155
- @parent_object = described_class.new
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
155
+ collection.ordered_members = [object]
156
+ parent_object.ordered_members = [object]
157
+ parent_object.save
158
+ collection.save
163
159
  end
164
160
 
165
- describe 'member_of' do
166
- subject { @object.member_of }
167
- it 'finds all nodes that aggregate the object with hasMember' do
168
- expect(subject).to include(@collection1, @collection2, @parent_object)
169
- end
161
+ it 'finds objects that aggregate the object' do
162
+ expect(subject).to eq [parent_object]
170
163
  end
164
+ end
171
165
 
172
- describe 'in_objects' do
173
- subject { @object.in_objects }
174
- it 'finds objects that aggregate the object with hasMember' do
175
- expect(subject).to eq [@parent_object]
176
- end
166
+ describe 'in_collections' do
167
+ let(:object) { described_class.create }
168
+ subject { object.in_collections }
169
+ let(:object) { described_class.create }
170
+ let(:collection1) { Hydra::PCDM::Collection.new }
171
+ let(:collection2) { Hydra::PCDM::Collection.new }
172
+ let(:parent_object) { described_class.new }
173
+ before do
174
+ collection1.ordered_members = [object]
175
+ collection2.ordered_members = [object]
176
+ parent_object.ordered_members = [object]
177
+ parent_object.save
178
+ collection1.save
179
+ collection2.save
177
180
  end
178
- describe 'in_collections' do
179
- subject { @object.in_collections }
180
- it 'finds collections that aggregate the object with hasMember' do
181
- expect(subject).to include(@collection1, @collection2)
182
- expect(subject.count).to eq 2
181
+
182
+ it 'finds collections that aggregate the object' do
183
+ expect(subject).to match_array [collection1, collection2]
184
+ expect(subject.count).to eq 2
185
+ end
186
+ end
187
+
188
+ describe 'member_of' do
189
+ subject { object.member_of }
190
+
191
+ context 'when it is aggregated by other objects' do
192
+ let(:object) { described_class.create }
193
+ let(:collection) { Hydra::PCDM::Collection.new }
194
+ let(:parent_object) { described_class.new }
195
+ before do
196
+ collection.ordered_members = [object]
197
+ parent_object.ordered_members = [object]
198
+ parent_object.save
199
+ collection.save
200
+ end
201
+
202
+ it 'finds all nodes that aggregate the object' do
203
+ expect(subject).to include(collection, parent_object)
183
204
  end
184
205
  end
185
- def build_proxy(container:)
186
- instance_double(ActiveFedora::Aggregation::Proxy, container: container)
206
+
207
+ context 'when the object is not saved' do
208
+ let(:object) { described_class.new }
209
+
210
+ context 'and other objects exist in the repo' do
211
+ before { Hydra::PCDM::Collection.create }
212
+ it 'is empty' do
213
+ expect(subject).to be_empty
214
+ end
215
+ end
187
216
  end
188
217
  end
189
218
 
@@ -203,9 +232,7 @@ describe Hydra::PCDM::Object do
203
232
  subject.related_objects << object2 # second add to same object
204
233
  subject.save
205
234
  related_objects = subject.reload.related_objects
206
- expect(related_objects.include? object1).to be true
207
- expect(related_objects.include? object2).to be true
208
- expect(related_objects.size).to eq 2
235
+ expect(related_objects).to match_array [object1, object2]
209
236
  end
210
237
 
211
238
  it 'not repeat objects in the related object set' do
@@ -214,15 +241,13 @@ describe Hydra::PCDM::Object do
214
241
  subject.related_objects << object2 # second add to same object
215
242
  subject.related_objects << object1 # repeat an object replaces the object
216
243
  related_objects = subject.related_objects
217
- expect(related_objects.include? object1).to be true
218
- expect(related_objects.include? object2).to be true
219
- expect(related_objects.size).to eq 2
244
+ expect(related_objects).to match_array [object1, object2]
220
245
  end
221
246
  end
222
247
  end
223
248
 
224
249
  context 'with unacceptable inputs' do
225
- before(:all) do
250
+ before do
226
251
  @collection101 = Hydra::PCDM::Collection.new
227
252
  @object101 = described_class.new
228
253
  @file101 = Hydra::PCDM::File.new
@@ -296,7 +321,7 @@ describe Hydra::PCDM::Object do
296
321
  end
297
322
 
298
323
  it 'remove related object while changes are in memory' do
299
- expect(subject.related_objects.delete object1).to eq [object1]
324
+ expect(subject.related_objects.delete(object1)).to eq [object1]
300
325
  expect(subject.related_objects).to eq []
301
326
  end
302
327
  end
@@ -312,23 +337,23 @@ describe Hydra::PCDM::Object do
312
337
  end
313
338
 
314
339
  it 'remove first related object when changes are in memory' do
315
- expect(subject.related_objects.delete object1).to eq [object1]
340
+ expect(subject.related_objects.delete(object1)).to eq [object1]
316
341
  expect(subject.related_objects).to eq [object2, object3, object4, object5]
317
342
  end
318
343
 
319
344
  it 'remove last related object when changes are in memory' do
320
- expect(subject.related_objects.delete object5).to eq [object5]
345
+ expect(subject.related_objects.delete(object5)).to eq [object5]
321
346
  expect(subject.related_objects).to eq [object1, object2, object3, object4]
322
347
  end
323
348
 
324
349
  it 'remove middle related object when changes are in memory' do
325
- expect(subject.related_objects.delete object3).to eq [object3]
350
+ expect(subject.related_objects.delete(object3)).to eq [object3]
326
351
  expect(subject.related_objects).to eq [object1, object2, object4, object5]
327
352
  end
328
353
 
329
354
  it 'remove middle related object when changes are saved' do
330
355
  expect(subject.related_objects).to eq [object1, object2, object3, object4, object5]
331
- expect(subject.related_objects.delete object3).to eq [object3]
356
+ expect(subject.related_objects.delete(object3)).to eq [object3]
332
357
  subject.save
333
358
  expect(subject.reload.related_objects).to eq [object1, object2, object4, object5]
334
359
  end
@@ -336,15 +361,7 @@ describe Hydra::PCDM::Object do
336
361
 
337
362
  context 'when related object is missing' do
338
363
  it 'return empty array when 0 related objects and 0 objects' do
339
- expect(subject.related_objects.delete object1).to eq []
340
- end
341
-
342
- it 'return empty array when other related objects and changes in memory' do
343
- subject.related_objects << object1
344
- subject.related_objects << object2
345
- subject.related_objects << object4
346
- subject.related_objects << object5
347
- expect(subject.related_objects.delete object3).to eq []
364
+ expect(subject.related_objects.delete(object1)).to eq []
348
365
  end
349
366
 
350
367
  it 'return empty array when other related objects and changes are in memory' do
@@ -352,7 +369,7 @@ describe Hydra::PCDM::Object do
352
369
  subject.related_objects << object2
353
370
  subject.related_objects << object4
354
371
  subject.related_objects << object5
355
- expect(subject.related_objects.delete object3).to eq []
372
+ expect(subject.related_objects.delete(object3)).to eq []
356
373
  end
357
374
 
358
375
  it 'return empty array when changes are saved' do
@@ -361,7 +378,7 @@ describe Hydra::PCDM::Object do
361
378
  subject.related_objects << object4
362
379
  subject.related_objects << object5
363
380
  subject.save
364
- expect(subject.reload.related_objects.delete object3).to eq []
381
+ expect(subject.reload.related_objects.delete(object3)).to eq []
365
382
  end
366
383
  end
367
384
  end
@@ -477,7 +494,7 @@ describe Hydra::PCDM::Object do
477
494
  let(:object4) { described_class.new }
478
495
 
479
496
  it 'deprecated methods should pass' do
480
- expect(object1.ordered_members = [object2]).to eq [object2]
497
+ object1.ordered_members = [object2]
481
498
  expect(object1.ordered_members << object3).to eq [object2, object3]
482
499
  expect(object1.ordered_members += [object4]).to eq [object2, object3, object4]
483
500
  object1.save # required until issue AF-Agg-75 is fixed
@@ -8,43 +8,43 @@ describe Hydra::PCDM do
8
8
  describe 'Validations' do
9
9
  describe '#collection?' do
10
10
  it 'return true for a pcdm collection' do
11
- expect(described_class.collection? coll1).to be true
11
+ expect(described_class).to be_collection coll1
12
12
  end
13
13
 
14
14
  it 'return false for a pcdm object' do
15
- expect(described_class.collection? obj1).to be false
15
+ expect(described_class).not_to be_collection obj1
16
16
  end
17
17
 
18
18
  it 'return false for a pcdm file' do
19
- expect(described_class.collection? file1).to be false
19
+ expect(described_class).not_to be_collection file1
20
20
  end
21
21
  end
22
22
 
23
23
  describe '#object?' do
24
24
  it 'return false for a pcdm collection' do
25
- expect(described_class.object? coll1).to be false
25
+ expect(described_class).not_to be_object coll1
26
26
  end
27
27
 
28
28
  it 'return true for a pcdm object' do
29
- expect(described_class.object? obj1).to be true
29
+ expect(described_class).to be_object obj1
30
30
  end
31
31
 
32
32
  it 'return false for a pcdm file' do
33
- expect(described_class.object? file1).to be false
33
+ expect(described_class).not_to be_object file1
34
34
  end
35
35
  end
36
36
 
37
37
  describe '#file?' do
38
38
  it 'return false for a pcdm collection' do
39
- expect(described_class.file? coll1).to be false
39
+ expect(described_class).not_to be_file coll1
40
40
  end
41
41
 
42
42
  it 'return false for a pcdm object' do
43
- expect(described_class.file? obj1).to be false
43
+ expect(described_class).not_to be_file obj1
44
44
  end
45
45
 
46
46
  it 'return true for a pcdm file' do
47
- expect(described_class.file? file1).to be true
47
+ expect(described_class).to be_file file1
48
48
  end
49
49
  end
50
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-pcdm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - E. Lynette Rayle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-03 00:00:00.000000000 Z
11
+ date: 2016-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active-fedora