active-fedora 1.2.6 → 1.2.7
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.
- data/VERSION +1 -1
- data/active-fedora.gemspec +5 -2
- data/lib/active_fedora/base.rb +19 -4
- data/lib/active_fedora/nokogiri_datastream.rb +228 -6
- data/lib/active_fedora/semantic_node.rb +23 -3
- data/lib/fedora/connection.rb +7 -4
- data/spec/fixtures/dino_jpg_no_file_ext +0 -0
- data/spec/fixtures/hydrangea_fixture_mods_article1.foxml.xml +58 -11
- data/spec/fixtures/mods_articles/hydrangea_article1.xml +24 -16
- data/spec/integration/base_spec.rb +145 -60
- data/spec/integration/nokogiri_datastream_spec.rb +60 -0
- data/spec/unit/base_named_datastream_spec.rb +3 -1
- data/spec/unit/nokogiri_datastream_spec.rb +110 -4
- data/spec/unit/semantic_node_spec.rb +45 -0
- metadata +7 -4
@@ -1,13 +1,13 @@
|
|
1
1
|
<mods version="3.0" xsi:schemaLocation="http://www.loc.gov/mods/v3
|
2
|
-
|
2
|
+
http://www.loc.gov/standards/mods/v3/mods-3-0.xsd" xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
3
3
|
|
4
4
|
<titleInfo>
|
5
5
|
<nonSort>THE</nonSort>
|
6
|
-
<title>ARTICLE TITLE
|
6
|
+
<title>ARTICLE TITLE</title>
|
7
7
|
<subTitle>SUBTITLE</subTitle>
|
8
8
|
</titleInfo>
|
9
|
-
<titleInfo
|
10
|
-
<title>
|
9
|
+
<titleInfo type="alternative">
|
10
|
+
<title>VARYING FORM OF TITLE</title>
|
11
11
|
</titleInfo>
|
12
12
|
|
13
13
|
<name type="personal">
|
@@ -17,23 +17,31 @@
|
|
17
17
|
<displayForm>NAME AS IT APPEARS</displayForm>
|
18
18
|
<affiliation>FACULTY, UNIVERSITY</affiliation>
|
19
19
|
<role>
|
20
|
-
<roleTerm authority="marcrelator" type="text">
|
21
|
-
</role>
|
22
|
-
<role>
|
23
|
-
<roleTerm type="text">submitter</roleTerm>
|
20
|
+
<roleTerm authority="marcrelator" type="text">Creator</roleTerm>
|
24
21
|
</role>
|
25
22
|
</name>
|
26
|
-
|
27
23
|
<name type="personal">
|
28
|
-
<namePart type="family">
|
29
|
-
<namePart type="given">
|
30
|
-
<
|
31
|
-
<affiliation>
|
32
|
-
<role>
|
33
|
-
<roleTerm authority="marcrelator" type="text">
|
24
|
+
<namePart type="family">Lacks</namePart>
|
25
|
+
<namePart type="given">Henrietta</namePart>
|
26
|
+
<displayForm>HeLa</displayForm>
|
27
|
+
<affiliation>Baltimore</affiliation>
|
28
|
+
<role>
|
29
|
+
<roleTerm authority="marcrelator" type="text">Contributor</roleTerm>
|
34
30
|
</role>
|
35
31
|
</name>
|
36
|
-
|
32
|
+
<name type="corporate">
|
33
|
+
<namePart>NSF</namePart>
|
34
|
+
<role>
|
35
|
+
<roleTerm authority="marcrelator" type="text">Funder</roleTerm>
|
36
|
+
</role>
|
37
|
+
</name>
|
38
|
+
<name type="conference">
|
39
|
+
<namePart>some conference</namePart>
|
40
|
+
<role>
|
41
|
+
<roleTerm authority="marcrelator" type="text">Host</roleTerm>
|
42
|
+
</role>
|
43
|
+
</name>
|
44
|
+
|
37
45
|
<typeOfResource>text</typeOfResource>
|
38
46
|
<genre authority="local">journal article</genre>
|
39
47
|
|
@@ -5,6 +5,10 @@ class MockAFBaseRelationship < ActiveFedora::Base
|
|
5
5
|
has_relationship "testing2", :has_member, :type=>MockAFBaseRelationship
|
6
6
|
has_relationship "testing_inbound", :has_part, :type=>MockAFBaseRelationship, :inbound=>true
|
7
7
|
has_relationship "testing_inbound2", :has_member, :type=>MockAFBaseRelationship, :inbound=>true
|
8
|
+
has_bidirectional_relationship "testing_bidirectional", :has_collection_member, :is_member_of_collection
|
9
|
+
#next 2 used to test objects on opposite end of bidirectional relationship
|
10
|
+
has_relationship "testing_inbound3", :has_collection_member, :inbound=>true
|
11
|
+
has_relationship "testing3", :is_member_of_collection
|
8
12
|
end
|
9
13
|
|
10
14
|
class MockAFBaseDatastream < ActiveFedora::Base
|
@@ -208,6 +212,33 @@ describe ActiveFedora::Base do
|
|
208
212
|
rexml.root.elements["rdf:Description/isMemberOf[@rdf:resource='info:fedora/demo:10']"].attributes["xmlns"].should == 'info:fedora/fedora-system:def/relations-external#'
|
209
213
|
end
|
210
214
|
end
|
215
|
+
|
216
|
+
describe '.add_file_datastream' do
|
217
|
+
|
218
|
+
it "should set the correct mimeType if :mime_type, :mimeType, or :content_type passed in and path does not contain correct extension" do
|
219
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino_jpg_no_file_ext" ))
|
220
|
+
@test_object.add_file_datastream(f)
|
221
|
+
@test_object.save
|
222
|
+
test_obj = ActiveFedora::Base.load_instance(@test_object.pid)
|
223
|
+
#check case where nothing passed in does not have correct mime type
|
224
|
+
test_obj.datastreams["DS1"].attributes["mimeType"].should == "application/octet-stream"
|
225
|
+
@test_object2 = ActiveFedora::Base.new
|
226
|
+
@test_object2.add_file_datastream(f,{:mimeType=>"image/jpeg"})
|
227
|
+
@test_object2.save
|
228
|
+
test_obj = ActiveFedora::Base.load_instance(@test_object2.pid)
|
229
|
+
test_obj.datastreams["DS1"].attributes["mimeType"].should == "image/jpeg"
|
230
|
+
@test_object3 = ActiveFedora::Base.new
|
231
|
+
@test_object3.add_file_datastream(f,{:mime_type=>"image/jpeg"})
|
232
|
+
@test_object3.save
|
233
|
+
test_obj = ActiveFedora::Base.load_instance(@test_object3.pid)
|
234
|
+
test_obj.datastreams["DS1"].attributes["mimeType"].should == "image/jpeg"
|
235
|
+
@test_object4 = ActiveFedora::Base.new
|
236
|
+
@test_object4.add_file_datastream(f,{:content_type=>"image/jpeg"})
|
237
|
+
@test_object4.save
|
238
|
+
test_obj = ActiveFedora::Base.load_instance(@test_object4.pid)
|
239
|
+
test_obj.datastreams["DS1"].attributes["mimeType"].should == "image/jpeg"
|
240
|
+
end
|
241
|
+
end
|
211
242
|
|
212
243
|
describe '.add_datastream' do
|
213
244
|
|
@@ -284,29 +315,41 @@ describe ActiveFedora::Base do
|
|
284
315
|
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
|
285
316
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
286
317
|
@test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
|
287
|
-
"testing2"=>[r4.object]},
|
288
|
-
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[]
|
289
|
-
|
318
|
+
"testing2"=>[r4.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
319
|
+
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
|
320
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
321
|
+
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
290
322
|
:inbound=>{"testing_inbound"=>[r2.object],
|
291
|
-
"testing_inbound2"=>[r5.object]
|
292
|
-
|
293
|
-
|
323
|
+
"testing_inbound2"=>[r5.object],
|
324
|
+
"testing_bidirectional_inbound"=>[],
|
325
|
+
"testing_inbound3"=>[]}}
|
326
|
+
@test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
327
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
|
328
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
294
329
|
@test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
|
295
|
-
"testing2"=>[r3.object]
|
296
|
-
|
330
|
+
"testing2"=>[r3.object],
|
331
|
+
"testing_bidirectional_outbound"=>[],
|
332
|
+
"testing3"=>[]},
|
333
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
334
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
297
335
|
@test_object2.delete
|
298
336
|
#need to reload since removed from rels_ext in memory
|
299
337
|
@test_object5 = MockAFBaseRelationship.load_instance(@test_object5.pid)
|
300
338
|
|
301
339
|
#check any test_object2 inbound rels gone from source
|
302
|
-
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[]},
|
340
|
+
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
303
341
|
:inbound=>{"testing_inbound"=>[],
|
304
|
-
"testing_inbound2"=>[r5.object]
|
305
|
-
|
306
|
-
|
342
|
+
"testing_inbound2"=>[r5.object],
|
343
|
+
"testing_bidirectional_inbound"=>[],
|
344
|
+
"testing_inbound3"=>[]}}
|
345
|
+
@test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
346
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
347
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
307
348
|
@test_object5.named_relationships(false).should == {:self=>{"testing"=>[],
|
308
|
-
"testing2"=>[r3.object]
|
309
|
-
|
349
|
+
"testing2"=>[r3.object],
|
350
|
+
"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
351
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
352
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
310
353
|
|
311
354
|
end
|
312
355
|
end
|
@@ -354,8 +397,10 @@ describe ActiveFedora::Base do
|
|
354
397
|
#append to named relationship 'testing'
|
355
398
|
@test_object2.testing_append(@test_object3)
|
356
399
|
@test_object2.testing2_append(@test_object4)
|
400
|
+
@test_object2.testing3_append(@test_object5)
|
357
401
|
@test_object5.testing_append(@test_object2)
|
358
402
|
@test_object5.testing2_append(@test_object3)
|
403
|
+
@test_object5.testing_bidirectional_append(@test_object4)
|
359
404
|
@test_object2.save
|
360
405
|
@test_object5.save
|
361
406
|
r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
|
@@ -366,26 +411,30 @@ describe ActiveFedora::Base do
|
|
366
411
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
367
412
|
@test_object2.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
|
368
413
|
:has_part=>[r3.object],
|
369
|
-
:has_member=>[r4.object]
|
414
|
+
:has_member=>[r4.object],
|
415
|
+
:is_member_of_collection=>[r5.object]},
|
370
416
|
:inbound=>{:has_part=>[r5.object]}}
|
371
417
|
@test_object3.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
|
372
418
|
:inbound=>{:has_part=>[r2.object],
|
373
419
|
:has_member=>[r5.object]}}
|
374
420
|
@test_object4.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
|
375
|
-
:inbound=>{:has_member=>[r2.object]}}
|
421
|
+
:inbound=>{:has_member=>[r2.object],:has_collection_member=>[r5.object]}}
|
376
422
|
@test_object5.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
|
377
423
|
:has_part=>[r2.object],
|
378
|
-
:has_member=>[r3.object]
|
379
|
-
|
424
|
+
:has_member=>[r3.object],
|
425
|
+
:has_collection_member=>[r4.object]},
|
426
|
+
:inbound=>{:is_member_of_collection=>[r2.object]}}
|
380
427
|
#all inbound should now be empty if no parameter supplied to relationships
|
381
428
|
@test_object2.relationships.should == {:self=>{:has_model=>[model_rel.object],
|
382
429
|
:has_part=>[r3.object],
|
383
|
-
:has_member=>[r4.object]
|
430
|
+
:has_member=>[r4.object],
|
431
|
+
:is_member_of_collection=>[r5.object]}}
|
384
432
|
@test_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
|
385
433
|
@test_object4.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
|
386
434
|
@test_object5.relationships.should == {:self=>{:has_model=>[model_rel.object],
|
387
435
|
:has_part=>[r2.object],
|
388
|
-
:has_member=>[r3.object]
|
436
|
+
:has_member=>[r3.object],
|
437
|
+
:has_collection_member=>[r4.object]}}
|
389
438
|
end
|
390
439
|
end
|
391
440
|
|
@@ -408,6 +457,7 @@ describe ActiveFedora::Base do
|
|
408
457
|
@test_object2.testing2_append(@test_object4)
|
409
458
|
@test_object5.testing_append(@test_object2)
|
410
459
|
@test_object5.testing2_append(@test_object3)
|
460
|
+
#@test_object5.testing_bidirectional_append(@test_object4)
|
411
461
|
@test_object2.save
|
412
462
|
@test_object5.save
|
413
463
|
r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
|
@@ -450,10 +500,14 @@ describe ActiveFedora::Base do
|
|
450
500
|
r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
|
451
501
|
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
|
452
502
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
453
|
-
@test_object2.named_inbound_relationships.should == {"testing_inbound"=>[r5.object],"testing_inbound2"=>[]
|
454
|
-
|
455
|
-
@
|
456
|
-
|
503
|
+
@test_object2.named_inbound_relationships.should == {"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
|
504
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
|
505
|
+
@test_object3.named_inbound_relationships.should == {"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object],
|
506
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
|
507
|
+
@test_object4.named_inbound_relationships.should == {"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
|
508
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
|
509
|
+
@test_object5.named_inbound_relationships.should == {"testing_inbound"=>[],"testing_inbound2"=>[],
|
510
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
|
457
511
|
end
|
458
512
|
end
|
459
513
|
|
@@ -485,23 +539,32 @@ describe ActiveFedora::Base do
|
|
485
539
|
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
|
486
540
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
487
541
|
@test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
|
488
|
-
"testing2"=>[r4.object]},
|
489
|
-
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[]
|
490
|
-
|
542
|
+
"testing2"=>[r4.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
543
|
+
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
|
544
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
545
|
+
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
491
546
|
:inbound=>{"testing_inbound"=>[r2.object],
|
492
|
-
"testing_inbound2"=>[r5.object]
|
493
|
-
|
494
|
-
|
547
|
+
"testing_inbound2"=>[r5.object],
|
548
|
+
"testing_bidirectional_inbound"=>[],
|
549
|
+
"testing_inbound3"=>[]}}
|
550
|
+
@test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
551
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
|
552
|
+
"testing_bidirectional_inbound"=>[], "testing_inbound3"=>[]}}
|
495
553
|
@test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
|
496
|
-
"testing2"=>[r3.object]
|
497
|
-
|
554
|
+
"testing2"=>[r3.object],
|
555
|
+
"testing_bidirectional_outbound"=>[],
|
556
|
+
"testing3"=>[]},
|
557
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
558
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
498
559
|
#all inbound should now be empty if no parameter supplied to relationships
|
499
560
|
@test_object2.named_relationships.should == {:self=>{"testing"=>[r3.object],
|
500
|
-
"testing2"=>[r4.object]
|
501
|
-
|
502
|
-
|
561
|
+
"testing2"=>[r4.object],
|
562
|
+
"testing_bidirectional_outbound"=>[],
|
563
|
+
"testing3"=>[]}}
|
564
|
+
@test_object3.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]}}
|
565
|
+
@test_object4.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]}}
|
503
566
|
@test_object5.named_relationships.should == {:self=>{"testing"=>[r2.object],
|
504
|
-
"testing2"=>[r3.object]}}
|
567
|
+
"testing2"=>[r3.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]}}
|
505
568
|
end
|
506
569
|
end
|
507
570
|
|
@@ -533,16 +596,23 @@ describe ActiveFedora::Base do
|
|
533
596
|
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
|
534
597
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
535
598
|
@test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
|
536
|
-
"testing2"=>[r4.object]},
|
537
|
-
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[]
|
538
|
-
|
599
|
+
"testing2"=>[r4.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
600
|
+
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
|
601
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
602
|
+
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
539
603
|
:inbound=>{"testing_inbound"=>[r2.object],
|
540
|
-
"testing_inbound2"=>[r5.object]
|
541
|
-
|
542
|
-
|
604
|
+
"testing_inbound2"=>[r5.object],
|
605
|
+
"testing_bidirectional_inbound"=>[],
|
606
|
+
"testing_inbound3"=>[]}}
|
607
|
+
@test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
608
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
|
609
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
543
610
|
@test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
|
544
|
-
"testing2"=>[r3.object]
|
545
|
-
|
611
|
+
"testing2"=>[r3.object],
|
612
|
+
"testing_bidirectional_outbound"=>[],
|
613
|
+
"testing3"=>[]},
|
614
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
615
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
546
616
|
end
|
547
617
|
end
|
548
618
|
|
@@ -574,30 +644,45 @@ describe ActiveFedora::Base do
|
|
574
644
|
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
|
575
645
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
576
646
|
@test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
|
577
|
-
"testing2"=>[r4.object]
|
578
|
-
|
579
|
-
|
647
|
+
"testing2"=>[r4.object],
|
648
|
+
"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
649
|
+
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
|
650
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
651
|
+
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
580
652
|
:inbound=>{"testing_inbound"=>[r2.object],
|
581
|
-
"testing_inbound2"=>[r5.object]
|
582
|
-
|
583
|
-
|
653
|
+
"testing_inbound2"=>[r5.object],
|
654
|
+
"testing_bidirectional_inbound"=>[],
|
655
|
+
"testing_inbound3"=>[]}}
|
656
|
+
@test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
657
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
|
658
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
584
659
|
@test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
|
585
|
-
"testing2"=>[r3.object]
|
586
|
-
|
660
|
+
"testing2"=>[r3.object],
|
661
|
+
"testing_bidirectional_outbound"=>[],
|
662
|
+
"testing3"=>[]},
|
663
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
664
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
587
665
|
@test_object2.remove_named_relationship("testing",@test_object3)
|
588
666
|
@test_object2.save
|
589
667
|
#check now removed for both outbound and inbound
|
590
668
|
@test_object2.named_relationships(false).should == {:self=>{"testing"=>[],
|
591
|
-
"testing2"=>[r4.object]
|
592
|
-
|
593
|
-
|
669
|
+
"testing2"=>[r4.object],
|
670
|
+
"testing_bidirectional_outbound"=>[],
|
671
|
+
"testing3"=>[]},
|
672
|
+
:inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
|
673
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
674
|
+
@test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
594
675
|
:inbound=>{"testing_inbound"=>[],
|
595
|
-
"testing_inbound2"=>[r5.object]
|
596
|
-
|
597
|
-
|
676
|
+
"testing_inbound2"=>[r5.object],
|
677
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
678
|
+
@test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
679
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
|
680
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
598
681
|
@test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
|
599
|
-
"testing2"=>[r3.object]
|
600
|
-
|
682
|
+
"testing2"=>[r3.object],
|
683
|
+
"testing_bidirectional_outbound"=>[],"testing3"=>[]},
|
684
|
+
:inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
|
685
|
+
"testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
|
601
686
|
|
602
687
|
end
|
603
688
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
|
+
require "hydra"
|
3
|
+
require "solrizer"
|
4
|
+
|
5
|
+
describe ActiveFedora::NokogiriDatastream do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
class HydrangeaArticle2 < ActiveFedora::Base
|
9
|
+
|
10
|
+
has_relationship "parts", :is_part_of, :inbound => true
|
11
|
+
|
12
|
+
# Uses the Hydra Rights Metadata Schema for tracking access permissions & copyright
|
13
|
+
# has_metadata :name => "rightsMetadata", :type => Hydra::RightsMetadata
|
14
|
+
|
15
|
+
# Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
|
16
|
+
has_metadata :name => "descMetadata", :type => Hydra::SampleModsDatastream
|
17
|
+
|
18
|
+
# A place to put extra metadata values
|
19
|
+
has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
|
20
|
+
m.field 'collection', :string
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@pid = "hydrangea:fixture_mods_article1"
|
25
|
+
@test_solr_object = HydrangeaArticle2.load_instance_from_solr(@pid)
|
26
|
+
@test_object = HydrangeaArticle2.load_instance(@pid)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.term_values' do
|
30
|
+
|
31
|
+
it "should return the same values whether getting from solr or Fedora" do
|
32
|
+
@test_solr_object.datastreams["descMetadata"].term_values(:name,:role,:text).should == ["Creator","Contributor","Funder","Host"]
|
33
|
+
@test_solr_object.datastreams["descMetadata"].term_values({:name=>0},:role,:text).should == ["Creator"]
|
34
|
+
@test_solr_object.datastreams["descMetadata"].term_values({:name=>1},:role,:text).should == ["Contributor"]
|
35
|
+
@test_solr_object.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text).should == ["Creator"]
|
36
|
+
@test_solr_object.datastreams["descMetadata"].term_values({:name=>1},{:role=>0},:text).should == ["Contributor"]
|
37
|
+
@test_solr_object.datastreams["descMetadata"].term_values({:name=>1},{:role=>1},:text).should == []
|
38
|
+
ar = @test_solr_object.datastreams["descMetadata"].term_values(:name,{:role=>0},:text)
|
39
|
+
ar.length.should == 4
|
40
|
+
ar.include?("Creator").should == true
|
41
|
+
ar.include?("Contributor").should == true
|
42
|
+
ar.include?("Funder").should == true
|
43
|
+
ar.include?("Host").should == true
|
44
|
+
|
45
|
+
@test_object.datastreams["descMetadata"].term_values(:name,:role,:text).should == ["Creator","Contributor","Funder","Host"]
|
46
|
+
@test_object.datastreams["descMetadata"].term_values({:name=>0},:role,:text).should == ["Creator"]
|
47
|
+
@test_object.datastreams["descMetadata"].term_values({:name=>1},:role,:text).should == ["Contributor"]
|
48
|
+
@test_object.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text).should == ["Creator"]
|
49
|
+
@test_object.datastreams["descMetadata"].term_values({:name=>1},{:role=>0},:text).should == ["Contributor"]
|
50
|
+
@test_object.datastreams["descMetadata"].term_values({:name=>1},{:role=>1},:text).should == []
|
51
|
+
ar = @test_object.datastreams["descMetadata"].term_values(:name,{:role=>0},:text)
|
52
|
+
ar.length.should == 4
|
53
|
+
ar.include?("Creator").should == true
|
54
|
+
ar.include?("Contributor").should == true
|
55
|
+
ar.include?("Funder").should == true
|
56
|
+
ar.include?("Host").should == true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -5,6 +5,8 @@ require "active_fedora"
|
|
5
5
|
|
6
6
|
describe ActiveFedora::Base do
|
7
7
|
|
8
|
+
@@last_pid = 0
|
9
|
+
|
8
10
|
def increment_pid
|
9
11
|
@@last_pid += 1
|
10
12
|
end
|
@@ -577,4 +579,4 @@ describe ActiveFedora::Base do
|
|
577
579
|
@test_object2.should respond_to(:external_ids)
|
578
580
|
end
|
579
581
|
end
|
580
|
-
end
|
582
|
+
end
|
@@ -10,7 +10,8 @@ describe ActiveFedora::NokogiriDatastream do
|
|
10
10
|
:empty_field => {:values => {}}
|
11
11
|
}
|
12
12
|
@sample_xml = XmlSimple.xml_in("<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>fake-date</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>")
|
13
|
-
|
13
|
+
|
14
|
+
@solr_doc = {"id"=>"hydrange_article1","name_role_roleTerm_t"=>["creator","submitter","teacher"],"name_0_role_t"=>"\r\ncreator\r\nsubmitter\r\n","name_1_role_t"=>"\r\n teacher \r\n","name_0_role_0_roleTerm_t"=>"creator","name_0_role_1_roleTerm_t"=>"submitter","name_1_role_0_roleTerm_t"=>["teacher"]}
|
14
15
|
end
|
15
16
|
|
16
17
|
before(:each) do
|
@@ -98,7 +99,7 @@ describe ActiveFedora::NokogiriDatastream do
|
|
98
99
|
end
|
99
100
|
|
100
101
|
it "should return the new index of any added values" do
|
101
|
-
@mods_ds.get_values([{:title_info=>0},:main_title]).should == ["ARTICLE TITLE
|
102
|
+
@mods_ds.get_values([{:title_info=>0},:main_title]).should == ["ARTICLE TITLE", "TITLE OF HOST JOURNAL"]
|
102
103
|
result = @mods_ds.update_indexed_attributes [{"title_info"=>"0"},"main_title"]=>{"-1"=>"mork"}
|
103
104
|
result.should == {"title_info_0_main_title"=>{"2"=>"mork"}}
|
104
105
|
end
|
@@ -157,7 +158,7 @@ describe ActiveFedora::NokogiriDatastream do
|
|
157
158
|
# end
|
158
159
|
|
159
160
|
it "should set @dirty to true" do
|
160
|
-
@mods_ds.get_values([{:title_info=>0},:main_title]).should == ["ARTICLE TITLE
|
161
|
+
@mods_ds.get_values([{:title_info=>0},:main_title]).should == ["ARTICLE TITLE", "TITLE OF HOST JOURNAL"]
|
161
162
|
@mods_ds.update_indexed_attributes [{"title_info"=>"0"},"main_title"]=>{"-1"=>"mork"}
|
162
163
|
@mods_ds.dirty?.should be_true
|
163
164
|
end
|
@@ -278,5 +279,110 @@ describe ActiveFedora::NokogiriDatastream do
|
|
278
279
|
@test_ds.set_blob_for_save
|
279
280
|
end
|
280
281
|
end
|
281
|
-
|
282
|
+
|
283
|
+
describe '.from_solr' do
|
284
|
+
it "should set the internal_solr_doc attribute to the solr document passed in" do
|
285
|
+
@test_ds.from_solr(@solr_doc)
|
286
|
+
@test_ds.internal_solr_doc.should == @solr_doc
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe '.get_values_from_solr' do
|
291
|
+
before(:each) do
|
292
|
+
@mods_ds = ActiveFedora::NokogiriDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should return empty array if internal_solr_doc not set" do
|
296
|
+
@mods_ds.get_values_from_solr(:name,:role,:roleTerm)
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should return correct values from solr_doc given different term pointers" do
|
300
|
+
mock_term = mock("OM::XML::Term")
|
301
|
+
mock_term.stubs(:data_type).returns(:text)
|
302
|
+
mock_terminology = mock("OM::XML::Terminology")
|
303
|
+
mock_terminology.stubs(:retrieve_term).returns(mock_term)
|
304
|
+
ActiveFedora::NokogiriDatastream.stubs(:terminology).returns(mock_terminology)
|
305
|
+
@mods_ds.from_solr(@solr_doc)
|
306
|
+
term_pointer = [:name,:role,:roleTerm]
|
307
|
+
@mods_ds.get_values_from_solr(:name,:role,:roleTerm).should == ["creator","submitter","teacher"]
|
308
|
+
ar = @mods_ds.get_values_from_solr({:name=>0},:role,:roleTerm)
|
309
|
+
ar.length.should == 2
|
310
|
+
ar.include?("creator").should == true
|
311
|
+
ar.include?("submitter").should == true
|
312
|
+
@mods_ds.get_values_from_solr({:name=>1},:role,:roleTerm).should == ["teacher"]
|
313
|
+
@mods_ds.get_values_from_solr({:name=>0},{:role=>0},:roleTerm).should == ["creator"]
|
314
|
+
@mods_ds.get_values_from_solr({:name=>0},{:role=>1},:roleTerm).should == ["submitter"]
|
315
|
+
@mods_ds.get_values_from_solr({:name=>0},{:role=>2},:roleTerm).should == []
|
316
|
+
@mods_ds.get_values_from_solr({:name=>1},{:role=>0},:roleTerm).should == ["teacher"]
|
317
|
+
@mods_ds.get_values_from_solr({:name=>1},{:role=>1},:roleTerm).should == []
|
318
|
+
ar = @mods_ds.get_values_from_solr(:name,{:role=>0},:roleTerm)
|
319
|
+
ar.length.should == 2
|
320
|
+
ar.include?("creator").should == true
|
321
|
+
ar.include?("teacher").should == true
|
322
|
+
@mods_ds.get_values_from_solr(:name,{:role=>1},:roleTerm).should == ["submitter"]
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe '.has_solr_name?' do
|
327
|
+
it "should return true if the given key exists in the solr document passed in" do
|
328
|
+
@test_ds.has_solr_name?("name_0_role_0_roleTerm_t",@solr_doc).should == true
|
329
|
+
@test_ds.has_solr_name?(:name_0_role_0_roleTerm_t,@solr_doc).should == true
|
330
|
+
@test_ds.has_solr_name?("name_1_role_1_roleTerm_t",@solr_doc).should == false
|
331
|
+
#if not doc passed in should be new empty solr doc and always return false
|
332
|
+
@test_ds.has_solr_name?("name_0_role_0_roleTerm_t").should == false
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
describe '.is_hierarchical_term_pointer?' do
|
337
|
+
it "should return true only if the pointer passed in is an array that contains a hash" do
|
338
|
+
@test_ds.is_hierarchical_term_pointer?(*[:image,{:tag1=>1},:tag2]).should == true
|
339
|
+
@test_ds.is_hierarchical_term_pointer?(*[:image,:tag1,{:tag2=>1}]).should == true
|
340
|
+
@test_ds.is_hierarchical_term_pointer?(*[:image,:tag1,:tag2]).should == false
|
341
|
+
@test_ds.is_hierarchical_term_pointer?(nil).should == false
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
describe '.update_values' do
|
346
|
+
before(:each) do
|
347
|
+
@mods_ds = ActiveFedora::NokogiriDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should throw an exception if we have initialized the internal_solr_doc." do
|
351
|
+
@mods_ds.from_solr(@solr_doc)
|
352
|
+
found_exception = false
|
353
|
+
begin
|
354
|
+
@mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
355
|
+
rescue
|
356
|
+
found_exception = true
|
357
|
+
end
|
358
|
+
found_exception.should == true
|
359
|
+
end
|
360
|
+
|
361
|
+
it "should update a value internally call OM::XML::TermValueOperators::update_values if internal_solr_doc is not set" do
|
362
|
+
@mods_ds.stubs(:om_update_values).once()
|
363
|
+
term_pointer = [:name,:role,:roleTerm]
|
364
|
+
@mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
describe '.term_values' do
|
369
|
+
|
370
|
+
before(:each) do
|
371
|
+
@mods_ds = ActiveFedora::NokogiriDatastream.new(:blob=>fixture(File.join("mods_articles","hydrangea_article1.xml")))
|
372
|
+
end
|
373
|
+
|
374
|
+
it "should call OM::XML::term_values if internal_solr_doc is not set and return values from xml" do
|
375
|
+
@mods_ds.stubs(:om_term_values).once()
|
376
|
+
term_pointer = [:name,:role,:roleTerm]
|
377
|
+
@mods_ds.term_values(*term_pointer)
|
378
|
+
end
|
379
|
+
|
380
|
+
# we will know this is working because solr_doc and xml are not synced so that wrong return mechanism can be detected
|
381
|
+
it "should call get_values_from_solr if internal_solr_doc is set" do
|
382
|
+
@mods_ds.from_solr(@solr_doc)
|
383
|
+
term_pointer = [:name,:role,:roleTerm]
|
384
|
+
@mods_ds.stubs(:get_values_from_solr).once()
|
385
|
+
@mods_ds.term_values(*term_pointer)
|
386
|
+
end
|
387
|
+
end
|
282
388
|
end
|