active-fedora 2.3.4 → 2.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "2.3.4"
2
+ VERSION = "2.3.7"
3
3
  end
@@ -309,11 +309,11 @@ describe ActiveFedora::Base do
309
309
  @test_object5 = MockAFBaseRelationship.new
310
310
  @test_object5.new_object = true
311
311
  @test_object5.save
312
- #append to named relationship 'testing'
313
- @test_object2.add_named_relationship("testing",@test_object3)
314
- @test_object2.add_named_relationship("testing2",@test_object4)
315
- @test_object5.add_named_relationship("testing",@test_object2)
316
- @test_object5.add_named_relationship("testing2",@test_object3)
312
+ #append to relationship by 'testing'
313
+ @test_object2.add_relationship_by_name("testing",@test_object3)
314
+ @test_object2.add_relationship_by_name("testing2",@test_object4)
315
+ @test_object5.add_relationship_by_name("testing",@test_object2)
316
+ @test_object5.add_relationship_by_name("testing2",@test_object3)
317
317
  @test_object2.save
318
318
  @test_object5.save
319
319
  r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
@@ -322,43 +322,18 @@ describe ActiveFedora::Base do
322
322
  r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
323
323
  model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
324
324
  #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
325
- @test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
326
- "testing2"=>[r4.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
327
- :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
328
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
329
- @test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
330
- :inbound=>{"testing_inbound"=>[r2.object],
331
- "testing_inbound2"=>[r5.object],
332
- "testing_bidirectional_inbound"=>[],
333
- "testing_inbound3"=>[]}}
334
- @test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
335
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
336
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
337
- @test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
338
- "testing2"=>[r3.object],
339
- "testing_bidirectional_outbound"=>[],
340
- "testing3"=>[]},
341
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
342
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
325
+ @test_object2.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r5.object], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r4.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object], "testing_bidirectional_outbound"=>[]}}
326
+ @test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r2.object], "testing_inbound2"=>[r5.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
327
+ @test_object4.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
328
+ @test_object5.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object], "testing_bidirectional_outbound"=>[]}}
343
329
  @test_object2.delete
344
330
  #need to reload since removed from rels_ext in memory
345
331
  @test_object5 = MockAFBaseRelationship.load_instance(@test_object5.pid)
346
332
 
347
333
  #check any test_object2 inbound rels gone from source
348
- @test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
349
- :inbound=>{"testing_inbound"=>[],
350
- "testing_inbound2"=>[r5.object],
351
- "testing_bidirectional_inbound"=>[],
352
- "testing_inbound3"=>[]}}
353
- @test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
354
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
355
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
356
- @test_object5.named_relationships(false).should == {:self=>{"testing"=>[],
357
- "testing2"=>[r3.object],
358
- "testing_bidirectional_outbound"=>[],"testing3"=>[]},
359
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
360
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
361
-
334
+ @test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r5.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
335
+ @test_object4.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
336
+ @test_object5.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
362
337
  end
363
338
  end
364
339
 
@@ -481,7 +456,7 @@ describe ActiveFedora::Base do
481
456
  end
482
457
  end
483
458
 
484
- describe '#named_inbound_relationships' do
459
+ describe '#inbound_relationships_by_name' do
485
460
  it 'should return a hash of inbound relationship names to array of objects' do
486
461
  @test_object2 = MockAFBaseRelationship.new
487
462
  @test_object2.new_object = true
@@ -508,18 +483,18 @@ describe ActiveFedora::Base do
508
483
  r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
509
484
  model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
510
485
  #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
511
- @test_object2.named_inbound_relationships.should == {"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
512
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
513
- @test_object3.named_inbound_relationships.should == {"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object],
514
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
515
- @test_object4.named_inbound_relationships.should == {"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
516
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
517
- @test_object5.named_inbound_relationships.should == {"testing_inbound"=>[],"testing_inbound2"=>[],
518
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}
486
+ @test_object2.inbound_relationships_by_name.should == {"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
487
+ "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[], "parts_inbound" => []}
488
+ @test_object3.inbound_relationships_by_name.should == {"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object],
489
+ "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[], "parts_inbound" => []}
490
+ @test_object4.inbound_relationships_by_name.should == {"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
491
+ "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[], "parts_inbound" => []}
492
+ @test_object5.inbound_relationships_by_name.should == {"testing_inbound"=>[],"testing_inbound2"=>[],
493
+ "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[], "parts_inbound" => []}
519
494
  end
520
495
  end
521
496
 
522
- describe '#named_relationships' do
497
+ describe '#relationships_by_name' do
523
498
  it '' do
524
499
  @test_object2 = MockAFBaseRelationship.new
525
500
  @test_object2.new_object = true
@@ -546,37 +521,19 @@ describe ActiveFedora::Base do
546
521
  r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
547
522
  model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
548
523
  #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
549
- @test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
550
- "testing2"=>[r4.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
551
- :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
552
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
553
- @test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
554
- :inbound=>{"testing_inbound"=>[r2.object],
555
- "testing_inbound2"=>[r5.object],
556
- "testing_bidirectional_inbound"=>[],
557
- "testing_inbound3"=>[]}}
558
- @test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
559
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
560
- "testing_bidirectional_inbound"=>[], "testing_inbound3"=>[]}}
561
- @test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
562
- "testing2"=>[r3.object],
563
- "testing_bidirectional_outbound"=>[],
564
- "testing3"=>[]},
565
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
566
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
524
+ @test_object2.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r5.object], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r4.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object], "testing_bidirectional_outbound"=>[]}}
525
+ @test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r2.object], "testing_inbound2"=>[r5.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
526
+ @test_object4.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
527
+ @test_object5.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object], "testing_bidirectional_outbound"=>[]}}
567
528
  #all inbound should now be empty if no parameter supplied to relationships
568
- @test_object2.named_relationships.should == {:self=>{"testing"=>[r3.object],
569
- "testing2"=>[r4.object],
570
- "testing_bidirectional_outbound"=>[],
571
- "testing3"=>[]}}
572
- @test_object3.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]}}
573
- @test_object4.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]}}
574
- @test_object5.named_relationships.should == {:self=>{"testing"=>[r2.object],
575
- "testing2"=>[r3.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]}}
529
+ @test_object2.relationships_by_name.should == {:self=>{"testing2"=>[r4.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object], "testing_bidirectional_outbound"=>[]}}
530
+ @test_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
531
+ @test_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
532
+ @test_object5.relationships_by_name.should == {:self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object], "testing_bidirectional_outbound"=>[]}}
576
533
  end
577
534
  end
578
535
 
579
- describe '#add_named_relationship' do
536
+ describe '#add_relationship_by_name' do
580
537
  it 'should add a named relationship to an object' do
581
538
  @test_object2 = MockAFBaseRelationship.new
582
539
  @test_object2.new_object = true
@@ -591,10 +548,10 @@ describe ActiveFedora::Base do
591
548
  @test_object5.new_object = true
592
549
  @test_object5.save
593
550
  #append to named relationship 'testing'
594
- @test_object2.add_named_relationship("testing",@test_object3)
595
- @test_object2.add_named_relationship("testing2",@test_object4)
596
- @test_object5.add_named_relationship("testing",@test_object2)
597
- @test_object5.add_named_relationship("testing2",@test_object3)
551
+ @test_object2.add_relationship_by_name("testing",@test_object3)
552
+ @test_object2.add_relationship_by_name("testing2",@test_object4)
553
+ @test_object5.add_relationship_by_name("testing",@test_object2)
554
+ @test_object5.add_relationship_by_name("testing2",@test_object3)
598
555
  @test_object2.save
599
556
  @test_object5.save
600
557
  r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
@@ -603,24 +560,10 @@ describe ActiveFedora::Base do
603
560
  r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
604
561
  model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
605
562
  #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
606
- @test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
607
- "testing2"=>[r4.object],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
608
- :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
609
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
610
- @test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
611
- :inbound=>{"testing_inbound"=>[r2.object],
612
- "testing_inbound2"=>[r5.object],
613
- "testing_bidirectional_inbound"=>[],
614
- "testing_inbound3"=>[]}}
615
- @test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
616
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
617
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
618
- @test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
619
- "testing2"=>[r3.object],
620
- "testing_bidirectional_outbound"=>[],
621
- "testing3"=>[]},
622
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
623
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
563
+ @test_object2.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r5.object], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r4.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object], "testing_bidirectional_outbound"=>[]}}
564
+ @test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r2.object], "testing_inbound2"=>[r5.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
565
+ @test_object4.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
566
+ @test_object5.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object], "testing_bidirectional_outbound"=>[]}}
624
567
  end
625
568
  end
626
569
 
@@ -639,10 +582,10 @@ describe ActiveFedora::Base do
639
582
  @test_object5.new_object = true
640
583
  @test_object5.save
641
584
  #append to named relationship 'testing'
642
- @test_object2.add_named_relationship("testing",@test_object3)
643
- @test_object2.add_named_relationship("testing2",@test_object4)
644
- @test_object5.add_named_relationship("testing",@test_object2)
645
- @test_object5.add_named_relationship("testing2",@test_object3)
585
+ @test_object2.add_relationship_by_name("testing",@test_object3)
586
+ @test_object2.add_relationship_by_name("testing2",@test_object4)
587
+ @test_object5.add_relationship_by_name("testing",@test_object2)
588
+ @test_object5.add_relationship_by_name("testing2",@test_object3)
646
589
  @test_object2.save
647
590
  @test_object5.save
648
591
  r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
@@ -651,51 +594,26 @@ describe ActiveFedora::Base do
651
594
  r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
652
595
  model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
653
596
  #check inbound correct, testing goes to :has_part and testing2 goes to :has_member
654
- @test_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],
597
+ @test_object2.relationships_by_name(false).should == {:self=>{"testing"=>[r3.object],
655
598
  "testing2"=>[r4.object],
656
- "testing_bidirectional_outbound"=>[],"testing3"=>[]},
599
+ "testing_bidirectional_outbound"=>[],"testing3"=>[],
600
+ "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[r3.object]},
657
601
  :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
658
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
659
- @test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
660
- :inbound=>{"testing_inbound"=>[r2.object],
661
- "testing_inbound2"=>[r5.object],
662
- "testing_bidirectional_inbound"=>[],
663
- "testing_inbound3"=>[]}}
664
- @test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
665
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
666
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
667
- @test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
668
- "testing2"=>[r3.object],
669
- "testing_bidirectional_outbound"=>[],
670
- "testing3"=>[]},
671
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
672
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
673
- @test_object2.remove_named_relationship("testing",@test_object3)
602
+ "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[], "parts_inbound"=>[]}}
603
+ @test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r2.object], "testing_inbound2"=>[r5.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
604
+ @test_object4.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
605
+ @test_object5.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object], "testing_bidirectional_outbound"=>[]}}
606
+ @test_object2.remove_relationship_by_name("testing",@test_object3)
674
607
  @test_object2.save
675
608
  #check now removed for both outbound and inbound
676
- @test_object2.named_relationships(false).should == {:self=>{"testing"=>[],
677
- "testing2"=>[r4.object],
678
- "testing_bidirectional_outbound"=>[],
679
- "testing3"=>[]},
680
- :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],
681
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
682
- @test_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
683
- :inbound=>{"testing_inbound"=>[],
684
- "testing_inbound2"=>[r5.object],
685
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
686
- @test_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[],"testing_bidirectional_outbound"=>[],"testing3"=>[]},
687
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object],
688
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
689
- @test_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],
690
- "testing2"=>[r3.object],
691
- "testing_bidirectional_outbound"=>[],"testing3"=>[]},
692
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[],
693
- "testing_bidirectional_inbound"=>[],"testing_inbound3"=>[]}}
694
-
609
+ @test_object2.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[r5.object], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r4.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
610
+ @test_object3.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r5.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
611
+ @test_object4.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[], "testing_bidirectional_outbound"=>[]}}
612
+ @test_object5.relationships_by_name(false).should == {:inbound=>{"testing_inbound3"=>[], "testing_bidirectional_inbound"=>[], "parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "testing3"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object], "testing_bidirectional_outbound"=>[]}}
695
613
  end
696
614
  end
697
615
 
698
- describe '#named_relationship' do
616
+ describe '#find_relationship_by_name' do
699
617
  it 'should find relationships based on name passed in for inbound or outbound' do
700
618
  @test_object2 = MockAFBaseRelationship.new
701
619
  @test_object2.new_object = true
@@ -710,10 +628,10 @@ describe ActiveFedora::Base do
710
628
  @test_object5.new_object = true
711
629
  @test_object5.save
712
630
  #append to named relationship 'testing'
713
- @test_object2.add_named_relationship("testing",@test_object3)
714
- @test_object2.add_named_relationship("testing2",@test_object4)
715
- @test_object5.add_named_relationship("testing",@test_object2)
716
- @test_object5.add_named_relationship("testing2",@test_object3)
631
+ @test_object2.add_relationship_by_name("testing",@test_object3)
632
+ @test_object2.add_relationship_by_name("testing2",@test_object4)
633
+ @test_object5.add_relationship_by_name("testing",@test_object2)
634
+ @test_object5.add_relationship_by_name("testing2",@test_object3)
717
635
  @test_object2.save
718
636
  @test_object5.save
719
637
  r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
@@ -721,22 +639,22 @@ describe ActiveFedora::Base do
721
639
  r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object4)
722
640
  r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
723
641
  model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFBaseRelationship))
724
- @test_object2.named_relationship("testing").should == [r3.object]
725
- @test_object2.named_relationship("testing2").should == [r4.object]
726
- @test_object2.named_relationship("testing_inbound").should == [r5.object]
727
- @test_object2.named_relationship("testing_inbound2").should == []
728
- @test_object3.named_relationship("testing").should == []
729
- @test_object3.named_relationship("testing2").should == []
730
- @test_object3.named_relationship("testing_inbound").should == [r2.object]
731
- @test_object3.named_relationship("testing_inbound2").should == [r5.object]
732
- @test_object4.named_relationship("testing").should == []
733
- @test_object4.named_relationship("testing2").should == []
734
- @test_object4.named_relationship("testing_inbound").should == []
735
- @test_object4.named_relationship("testing_inbound2").should == [r2.object]
736
- @test_object5.named_relationship("testing").should == [r2.object]
737
- @test_object5.named_relationship("testing2").should == [r3.object]
738
- @test_object5.named_relationship("testing_inbound").should == []
739
- @test_object5.named_relationship("testing_inbound2").should == []
642
+ @test_object2.find_relationship_by_name("testing").should == [r3.object]
643
+ @test_object2.find_relationship_by_name("testing2").should == [r4.object]
644
+ @test_object2.find_relationship_by_name("testing_inbound").should == [r5.object]
645
+ @test_object2.find_relationship_by_name("testing_inbound2").should == []
646
+ @test_object3.find_relationship_by_name("testing").should == []
647
+ @test_object3.find_relationship_by_name("testing2").should == []
648
+ @test_object3.find_relationship_by_name("testing_inbound").should == [r2.object]
649
+ @test_object3.find_relationship_by_name("testing_inbound2").should == [r5.object]
650
+ @test_object4.find_relationship_by_name("testing").should == []
651
+ @test_object4.find_relationship_by_name("testing2").should == []
652
+ @test_object4.find_relationship_by_name("testing_inbound").should == []
653
+ @test_object4.find_relationship_by_name("testing_inbound2").should == [r2.object]
654
+ @test_object5.find_relationship_by_name("testing").should == [r2.object]
655
+ @test_object5.find_relationship_by_name("testing2").should == [r3.object]
656
+ @test_object5.find_relationship_by_name("testing_inbound").should == []
657
+ @test_object5.find_relationship_by_name("testing_inbound2").should == []
740
658
 
741
659
  end
742
660
  end
@@ -951,34 +869,33 @@ describe ActiveFedora::Base do
951
869
  :has_part=>[r3.object],
952
870
  :has_member=>[r4.object]},
953
871
  :inbound=>{:has_part=>[r5.object]}}
954
- test_from_solr_object2.named_relationships(false).should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object]},
955
- :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[]}}
872
+ test_from_solr_object2.relationships_by_name(false).should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object],
873
+ "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[r3.object]},
874
+ :inbound=>{"testing_inbound"=>[r5.object],"testing_inbound2"=>[],"parts_inbound"=>[]}}
956
875
  test_from_solr_object3.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
957
876
  :inbound=>{:has_part=>[r2.object],
958
877
  :has_member=>[r5.object]}}
959
- test_from_solr_object3.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[]},
960
- :inbound=>{"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object]}}
878
+ test_from_solr_object3.relationships_by_name(false).should == {:self=>{"testing"=>[],"testing2"=>[], "collection_members"=>[],"part_of"=>[],"parts_outbound"=>[]},
879
+ :inbound=>{"testing_inbound"=>[r2.object],"testing_inbound2"=>[r5.object], "parts_inbound"=>[]}}
961
880
  test_from_solr_object4.relationships(false).should == {:self=>{:has_model=>[model_rel.object]},
962
881
  :inbound=>{:has_member=>[r2.object]}}
963
- test_from_solr_object4.named_relationships(false).should == {:self=>{"testing"=>[],"testing2"=>[]},
964
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[r2.object]}}
882
+ test_from_solr_object4.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[r2.object]}, :self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
965
883
  test_from_solr_object5.relationships(false).should == {:self=>{:has_model=>[model_rel.object],
966
884
  :has_part=>[r2.object],
967
885
  :has_member=>[r3.object]},
968
886
  :inbound=>{}}
969
- test_from_solr_object5.named_relationships(false).should == {:self=>{"testing"=>[r2.object],"testing2"=>[r3.object]},
970
- :inbound=>{"testing_inbound"=>[],"testing_inbound2"=>[]}}
887
+ test_from_solr_object5.relationships_by_name(false).should == {:inbound=>{"parts_inbound"=>[], "testing_inbound"=>[], "testing_inbound2"=>[]}, :self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
971
888
  #all inbound should now be empty if no parameter supplied to relationships
972
889
  test_from_solr_object2.relationships.should == {:self=>{:has_part=>[r3.object],:has_member=>[r4.object],:has_model=>[model_rel.object]}}
973
- test_from_solr_object2.named_relationships.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object]}}
890
+ test_from_solr_object2.relationships_by_name.should == {:self=>{"testing2"=>[r4.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r3.object], "parts_outbound"=>[r3.object]}}
974
891
  test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
975
- test_from_solr_object3.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
892
+ test_from_solr_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
976
893
  test_from_solr_object4.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
977
- test_from_solr_object4.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
894
+ test_from_solr_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
978
895
  test_from_solr_object5.relationships.should == {:self=>{:has_model=>[model_rel.object],
979
896
  :has_part=>[r2.object],
980
897
  :has_member=>[r3.object]}}
981
- test_from_solr_object5.named_relationships.should == {:self=>{"testing"=>[r2.object],"testing2"=>[r3.object]}}
898
+ test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
982
899
  # need to check metadata
983
900
  test_from_solr_object2.fields[:language][:values].should == ["Italian"]
984
901
  test_from_solr_object2.fields[:creator][:values].should == ["Linguist, A."]
@@ -44,15 +44,15 @@ describe ActiveFedora::Datastream do
44
44
  it "should be able to update Blob Datastream content and save to Fedora" do
45
45
  dsid = "ds#{Time.now.to_i}"
46
46
  ds = ActiveFedora::Datastream.new(:dsID => dsid, :dsLabel => 'hello', :altIDs => '3333',
47
- :controlGroup => 'M', :blob => fixture('dino.jpg'))
48
- File.identical?(ds.blob, fixture('dino.jpg')).should be_true
47
+ :controlGroup => 'M', :blob => fixture('dino.jpg').read)
48
+ ds.blob.should == fixture('dino.jpg').read
49
49
  @test_object.add_datastream(ds).should be_true
50
50
  @test_object.save
51
51
  to = ActiveFedora::Base.load_instance(@test_object.pid)
52
52
  to.should_not be_nil
53
53
  to.datastreams[dsid].should_not be_nil
54
54
  # to.datastreams[dsid].control_group.should == "M"
55
- to.datastreams[dsid].content.length.should eql(fixture('dino.jpg').read.length)
55
+ to.datastreams[dsid].content.should == fixture('dino.jpg').read
56
56
 
57
57
  end
58
58
 
@@ -141,7 +141,7 @@ end
141
141
 
142
142
  it "should create/update image/file datastream" do
143
143
  ds = Fedora::Datastream.new(:pid => @test_object.pid, :dsID => 'DS1', :dsLabel => 'hello', :altIDs => '3333',
144
- :controlGroup => 'M', :blob => fixture('dino.jpg'))
144
+ :controlGroup => 'M', :blob => fixture('dino.jpg').read, :mimeType=>'image/jpeg')
145
145
 
146
146
  @fedora.save(ds).should be_true
147
147
 
@@ -139,15 +139,15 @@ describe ActiveFedora::RelsExtDatastream do
139
139
  test_from_solr_object5.rels_ext.from_solr(solr_doc)
140
140
 
141
141
  test_from_solr_object2.relationships.should == {:self=>{:has_part=>[r3.object],:has_member=>[r4.object],:has_model=>[model_rel.object]}}
142
- test_from_solr_object2.named_relationships.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object]}}
142
+ test_from_solr_object2.relationships_by_name.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[r3.object]}}
143
143
  test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
144
- test_from_solr_object3.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
144
+ test_from_solr_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
145
145
  test_from_solr_object4.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
146
- test_from_solr_object4.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
146
+ test_from_solr_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
147
147
  test_from_solr_object5.relationships.should == {:self=>{:has_model=>[model_rel.object],
148
148
  :has_part=>[r2.object],
149
149
  :has_member=>[r3.object]}}
150
- test_from_solr_object5.named_relationships.should == {:self=>{"testing"=>[r2.object],"testing2"=>[r3.object]}}
150
+ test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
151
151
  end
152
152
  end
153
153
  end
@@ -5,7 +5,7 @@ require 'active_fedora'
5
5
  describe ActiveFedora::SemanticNode do
6
6
 
7
7
  before(:all) do
8
- class SpecNode
8
+ class SpecNode
9
9
  include ActiveFedora::SemanticNode
10
10
  has_relationship "collection_members", :has_collection_member
11
11
  end
@@ -13,8 +13,17 @@ describe ActiveFedora::SemanticNode do
13
13
  class SNSpecModel < ActiveFedora::Base
14
14
  has_relationship("parts", :is_part_of, :inbound => true)
15
15
  has_relationship("containers", :is_member_of)
16
+ has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
16
17
  end
17
-
18
+ class SpecNodeSolrFilterQuery < ActiveFedora::Base
19
+ has_relationship("parts", :is_part_of, :inbound => true)
20
+ has_relationship("special_parts", :is_part_of, :inbound => true, :solr_fq=>"has_model_s:info\\:fedora/SpecialPart")
21
+ has_relationship("containers", :is_member_of)
22
+ has_relationship("special_containers", :is_member_of, :solr_fq=>"has_model_s:info\\:fedora/SpecialContainer")
23
+ has_bidirectional_relationship("bi_containers", :is_member_of, :has_member)
24
+ has_bidirectional_relationship("bi_special_containers", :is_member_of, :has_member, :solr_fq=>"has_model_s:info\\:fedora/SpecialContainer")
25
+ end
26
+
18
27
  @test_object = SNSpecModel.new
19
28
  @test_object.save
20
29
 
@@ -30,19 +39,101 @@ describe ActiveFedora::SemanticNode do
30
39
  @container1.save
31
40
  @container2 = ActiveFedora::Base.new()
32
41
  @container2.save
42
+ @container3 = ActiveFedora::Base.new()
43
+ @container3.save
44
+ @container4 = ActiveFedora::Base.new()
45
+ @container4.save
33
46
 
34
47
  @test_object.add_relationship(:is_member_of, @container1)
35
48
  @test_object.add_relationship(:is_member_of, @container2)
49
+ @test_object.add_relationship(:is_member_of, @container3)
36
50
  @test_object.save
51
+
52
+ @container4.add_relationship(:has_member,@test_object)
53
+ @container4.save
54
+
55
+ @special_container = ActiveFedora::Base.new()
56
+ @special_container.add_relationship(:has_model,"SpecialContainer")
57
+ @special_container.save
58
+
59
+ @special_container3 = ActiveFedora::Base.new()
60
+ @special_container3.add_relationship(:has_model,"SpecialContainer")
61
+ @special_container3.save
62
+
63
+ @special_container4 = ActiveFedora::Base.new()
64
+ @special_container4.add_relationship(:has_model,"SpecialContainer")
65
+ @special_container4.save
66
+
67
+ #even though adding container3 and 3 special containers, it should only include the special containers when returning via relationship name finder methods
68
+ #also should only return special part similarly
69
+ @test_object_query = SpecNodeSolrFilterQuery.new
70
+ @test_object_query.add_relationship(:is_member_of, @container3)
71
+ @test_object_query.add_relationship(:is_member_of, @special_container)
72
+ @test_object_query.add_relationship(:is_member_of, @special_container3)
73
+ @test_object_query.add_relationship(:is_member_of, @special_container4)
74
+ @test_object_query.save
75
+
76
+ @special_container2 = ActiveFedora::Base.new()
77
+ @special_container2.add_relationship(:has_model,"SpecialContainer")
78
+ @special_container2.add_relationship(:has_member,@test_object_query.pid)
79
+ @special_container2.save
80
+
81
+ @part3 = ActiveFedora::Base.new()
82
+ @part3.add_relationship(:is_part_of, @test_object_query)
83
+ @part3.save
84
+
85
+ @special_part = ActiveFedora::Base.new()
86
+ @special_part.add_relationship(:has_model,"SpecialPart")
87
+ @special_part.add_relationship(:is_part_of, @test_object_query)
88
+ @special_part.save
89
+
37
90
  end
38
91
 
39
92
  after(:all) do
93
+ begin
40
94
  @part1.delete
95
+ rescue
96
+ end
97
+ begin
41
98
  @part2.delete
99
+ rescue
100
+ end
101
+ begin
102
+ @part3.delete
103
+ rescue
104
+ end
105
+ begin
42
106
  @container1.delete
107
+ rescue
108
+ end
109
+ begin
43
110
  @container2.delete
111
+ rescue
112
+ end
113
+ begin
114
+ @container3.delete
115
+ rescue
116
+ end
117
+ begin
44
118
  @test_object.delete
45
-
119
+ rescue
120
+ end
121
+ begin
122
+ @test_object_query.delete
123
+ rescue
124
+ end
125
+ begin
126
+ @special_part.delete
127
+ rescue
128
+ end
129
+ begin
130
+ @special_container.delete
131
+ rescue
132
+ end
133
+ begin
134
+ @special_container2.delete
135
+ rescue
136
+ end
46
137
  Object.send(:remove_const, :SNSpecModel)
47
138
 
48
139
  end
@@ -62,6 +153,84 @@ describe ActiveFedora::SemanticNode do
62
153
  end
63
154
 
64
155
  describe "inbound relationship finders" do
156
+ describe "when inheriting from parents" do
157
+ before do
158
+ class Test2 < ActiveFedora::Base
159
+ # has_bidirectional_relationship "components", :has_component, :is_component_of
160
+ end
161
+ class Test3 < Test2
162
+ # has_bidirectional_relationship "components", :has_component, :is_component_of
163
+ has_relationship "testing", :has_member
164
+ end
165
+
166
+ class Test4 < Test3
167
+ has_relationship "testing_inbound", :is_member_of, :inbound=>true
168
+ end
169
+
170
+ class Test5 < Test4
171
+ has_relationship "testing_inbound", :is_part_of, :inbound=>true
172
+ end
173
+
174
+ @test_object2 = Test2.new
175
+ @test_object2.save
176
+ @part4 = ActiveFedora::Base.new()
177
+ end
178
+ it "should have relationships defined" do
179
+ # puts "Test2 relationships_desc:"
180
+ # puts Test2.relationships_desc.inspect
181
+ # puts "ActiveFedora::Base relationships_desc:"
182
+ # puts ActiveFedora::Base.relationships_desc.inspect
183
+ ActiveFedora::Base.relationships_desc.should have_key(:inbound)
184
+ Test2.relationships_desc.should have_key(:inbound)
185
+ ActiveFedora::Base.relationships_desc[:inbound].each_pair do |key, value|
186
+ Test2.relationships_desc[:inbound].should have_key(key)
187
+ Test2.relationships_desc[:inbound][key].should == value
188
+ Test2.inbound_relationship_query("foo:1",key.to_s).should_not be_empty
189
+ end
190
+ ActiveFedora::Base.relationships_desc[:self].each_pair do |key, value|
191
+ Test2.relationships_desc[:self].should have_key(key)
192
+ Test2.relationships_desc[:self][key].should == value
193
+ end
194
+ end
195
+
196
+ it "should have relationships defined from more than one ancestor class" do
197
+ Test4.relationships_desc[:self].should have_key("collection_members")
198
+ Test4.relationships_desc[:self].should have_key("testing")
199
+ Test4.relationships_desc[:inbound].should have_key("testing_inbound")
200
+ end
201
+
202
+ it "should override a parents relationship description if defined in the child" do
203
+ #check parent description
204
+ Test4.relationships_desc[:inbound]["testing_inbound"][:predicate].should == :is_member_of
205
+ #check child with overwritten relationship description has different predicate
206
+ Test5.relationships_desc[:inbound]["testing_inbound"][:predicate].should == :is_part_of
207
+ end
208
+
209
+ it "should not have relationships bleeding over from other sibling classes" do
210
+ SpecNodeSolrFilterQuery.relationships_desc[:inbound].should have_key("bi_special_containers_inbound")
211
+ ActiveFedora::Base.relationships_desc[:inbound].should_not have_key("bi_special_containers_inbound")
212
+ Test2.relationships_desc[:inbound].should_not have_key("bi_special_containers_inbound")
213
+ end
214
+ it "should return an empty set" do
215
+ @test_object2.parts.should == []
216
+ @test_object2.parts_outbound.should == []
217
+ end
218
+ it "should return stuff" do
219
+ @part4.add_relationship(:is_part_of, @test_object2)
220
+ @test_object2.add_relationship(:has_part, @test_object)
221
+ @part4.save
222
+ @test_object2.parts_inbound.map(&:pid).should == [@part4.pid]
223
+ @test_object2.parts_outbound.map(&:pid).should == [@test_object.pid]
224
+ @test_object2.parts.map(&:pid).should == [@part4.pid, @test_object.pid]
225
+ end
226
+ after do
227
+ @test_object2.delete
228
+ begin
229
+ @part4.delete
230
+ rescue
231
+ end
232
+ end
233
+ end
65
234
  it "should return an array of Base objects" do
66
235
  parts = @test_object.parts
67
236
  parts.each do |part|
@@ -70,12 +239,79 @@ describe ActiveFedora::SemanticNode do
70
239
  end
71
240
  it "_ids should return an array of pids" do
72
241
  ids = @test_object.parts_ids
73
- ids.each do |id|
74
- id.should satisfy {|id| id == @part1.pid || @part2.pid}
75
- end
242
+ ids.size.should == 2
243
+ ids.include?(@part1.pid).should == true
244
+ ids.include?(@part2.pid).should == true
245
+ end
246
+ it "should return an array of Base objects with some filtered out if using solr_fq" do
247
+ @test_object_query.special_parts_ids.should == [@special_part.pid]
248
+ end
249
+
250
+ it "should return an array of all Base objects with relationship if not using solr_fq" do
251
+ @test_object_query.parts_ids.size.should == 2
252
+ @test_object_query.parts_ids.include?(@special_part.pid).should == true
253
+ @test_object_query.parts_ids.include?(@part3.pid).should == true
254
+ end
255
+
256
+ it "should return a solr query for an inbound relationship" do
257
+ @test_object_query.special_parts_query.should == "#{@test_object_query.relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialPart"
76
258
  end
77
259
  end
78
-
260
+
261
+ describe "inbound relationship query" do
262
+ it "should return a properly formatted query for a relationship that has a solr filter query defined" do
263
+ SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"special_parts").should == "#{@test_object_query.relationship_predicates[:inbound]['special_parts']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialPart"
264
+ end
265
+
266
+ it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
267
+ SpecNodeSolrFilterQuery.inbound_relationship_query(@test_object_query.pid,"parts").should == "is_part_of_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')}"
268
+ end
269
+ end
270
+
271
+ describe "outbound relationship query" do
272
+ it "should return a properly formatted query for a relationship that has a solr filter query defined" do
273
+ expected_string = ""
274
+ @test_object_query.containers_ids.each_with_index do |id,index|
275
+ expected_string << " OR " if index > 0
276
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
277
+ end
278
+ SpecNodeSolrFilterQuery.outbound_relationship_query("special_containers",@test_object_query.containers_ids).should == expected_string
279
+ end
280
+
281
+ it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
282
+ expected_string = ""
283
+ @test_object_query.containers_ids.each_with_index do |id,index|
284
+ expected_string << " OR " if index > 0
285
+ expected_string << "id:" + id.gsub(/(:)/, '\\:')
286
+ end
287
+ SpecNodeSolrFilterQuery.outbound_relationship_query("containers",@test_object_query.containers_ids).should == expected_string
288
+ end
289
+ end
290
+
291
+ describe "bidirectional relationship query" do
292
+ it "should return a properly formatted query for a relationship that has a solr filter query defined" do
293
+ expected_string = ""
294
+ @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
295
+ expected_string << " OR " if index > 0
296
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
297
+ end
298
+ expected_string << " OR "
299
+ expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialContainer)"
300
+ SpecNodeSolrFilterQuery.bidirectional_relationship_query(@test_object_query.pid,"bi_special_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
301
+ end
302
+
303
+ it "should return a properly formatted query for a relationship that does not have a solr filter query defined" do
304
+ expected_string = ""
305
+ @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
306
+ expected_string << " OR " if index > 0
307
+ expected_string << "id:" + id.gsub(/(:)/, '\\:')
308
+ end
309
+ expected_string << " OR "
310
+ expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')})"
311
+ SpecNodeSolrFilterQuery.bidirectional_relationship_query(@test_object_query.pid,"bi_containers",@test_object_query.bi_containers_outbound_ids).should == expected_string
312
+ end
313
+ end
314
+
79
315
  describe "outbound relationship finders" do
80
316
  it "should return an array of Base objects" do
81
317
  containers = @test_object.containers
@@ -86,9 +322,132 @@ describe ActiveFedora::SemanticNode do
86
322
  end
87
323
  it "_ids should return an array of pids" do
88
324
  ids = @test_object.containers_ids
89
- ids.each do |id|
90
- id.should satisfy {|id| id == @container1.pid || @container2.pid}
91
- end
325
+ ids.size.should == 3
326
+ ids.include?(@container1.pid).should == true
327
+ ids.include?(@container2.pid).should == true
328
+ ids.include?(@container3.pid).should == true
329
+ ids.include?(@container4.pid).should == false
92
330
  end
331
+
332
+ it "should return an array of Base objects with some filtered out if using solr_fq" do
333
+ @test_object_query.special_containers_ids.size.should == 3
334
+ @test_object_query.special_containers_ids.include?(@container3.pid).should == false
335
+ @test_object_query.special_containers_ids.include?(@special_container.pid).should == true
336
+ @test_object_query.special_containers_ids.include?(@special_container3.pid).should == true
337
+ @test_object_query.special_containers_ids.include?(@special_container4.pid).should == true
338
+ end
339
+
340
+ it "should return an array of all Base objects with relationship if not using solr_fq" do
341
+ @test_object_query.containers_ids.size.should == 4
342
+ @test_object_query.containers_ids.include?(@special_container2.pid).should == false
343
+ @test_object_query.containers_ids.include?(@special_container.pid).should == true
344
+ @test_object_query.containers_ids.include?(@container3.pid).should == true
345
+ @test_object_query.containers_ids.include?(@special_container3.pid).should == true
346
+ @test_object_query.containers_ids.include?(@special_container4.pid).should == true
347
+ end
348
+
349
+ it "should return a solr query for an outbound relationship" do
350
+ end
351
+
352
+ it "should return an array of Base objects with some filtered out if using solr_fq" do
353
+ @test_object_query.special_containers_ids.size.should == 3
354
+ @test_object_query.special_containers_ids.include?(@container3.pid).should == false
355
+ @test_object_query.special_containers_ids.include?(@special_container.pid).should == true
356
+ @test_object_query.special_containers_ids.include?(@special_container3.pid).should == true
357
+ @test_object_query.special_containers_ids.include?(@special_container4.pid).should == true
358
+ end
359
+
360
+ it "should return an array of all Base objects with relationship if not using solr_fq" do
361
+ @test_object_query.containers_ids.size.should == 4
362
+ @test_object_query.containers_ids.include?(@special_container2.pid).should == false
363
+ @test_object_query.containers_ids.include?(@special_container.pid).should == true
364
+ @test_object_query.containers_ids.include?(@container3.pid).should == true
365
+ @test_object_query.containers_ids.include?(@special_container3.pid).should == true
366
+ @test_object_query.containers_ids.include?(@special_container4.pid).should == true
367
+ end
368
+
369
+ it "should return a solr query for an outbound relationship" do
370
+ expected_string = ""
371
+ @test_object_query.containers_ids.each_with_index do |id,index|
372
+ expected_string << " OR " if index > 0
373
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
374
+ end
375
+ @test_object_query.special_containers_query.should == expected_string
376
+ end
93
377
  end
378
+
379
+ describe "bidirectional relationship finders" do
380
+ it "should return an array of Base objects" do
381
+ containers = @test_object.bi_containers
382
+ containers.length.should > 0
383
+ containers.each do |container|
384
+ container.should be_kind_of(ActiveFedora::Base)
385
+ end
386
+ end
387
+ it "_ids should return an array of pids" do
388
+ ids = @test_object.bi_containers_ids
389
+ ids.size.should == 4
390
+ ids.include?(@container1.pid).should == true
391
+ ids.include?(@container2.pid).should == true
392
+ ids.include?(@container3.pid).should == true
393
+ ids.include?(@container4.pid).should == true
394
+ end
395
+
396
+ it "should return an array of Base objects with some filtered out if using solr_fq" do
397
+ ids = @test_object_query.bi_special_containers_ids
398
+ ids.size.should == 4
399
+ ids.include?(@container1.pid).should == false
400
+ ids.include?(@container2.pid).should == false
401
+ ids.include?(@container3.pid).should == false
402
+ ids.include?(@special_container.pid).should == true
403
+ ids.include?(@special_container2.pid).should == true
404
+ ids.include?(@special_container3.pid).should == true
405
+ ids.include?(@special_container4.pid).should == true
406
+ end
407
+
408
+ it "should return an array of all Base objects with relationship if not using solr_fq" do
409
+ ids = @test_object_query.bi_containers_ids
410
+ ids.size.should == 5
411
+ ids.include?(@container3.pid).should == true
412
+ ids.include?(@special_container.pid).should == true
413
+ ids.include?(@special_container2.pid).should == true
414
+ ids.include?(@special_container3.pid).should == true
415
+ ids.include?(@special_container4.pid).should == true
416
+ end
417
+
418
+ it "should return a solr query for a bidirectional relationship" do
419
+ expected_string = ""
420
+ @test_object_query.bi_containers_outbound_ids.each_with_index do |id,index|
421
+ expected_string << " OR " if index > 0
422
+ expected_string << "(id:" + id.gsub(/(:)/, '\\:') + " AND has_model_s:info\\:fedora/SpecialContainer)"
423
+ end
424
+ expected_string << " OR "
425
+ expected_string << "(#{@test_object_query.relationship_predicates[:inbound]['bi_special_containers_inbound']}_s:#{@test_object_query.internal_uri.gsub(/(:)/, '\\:')} AND has_model_s:info\\:fedora/SpecialContainer)"
426
+ @test_object_query.bi_special_containers_query.should == expected_string
427
+ end
428
+ end
429
+
430
+ #putting this test here instead of relationships_helper because testing that relationships_by_name hash gets refreshed if the relationships hash is changed
431
+ describe "relationships_by_name" do
432
+ class MockSemNamedRelationships
433
+ include ActiveFedora::SemanticNode
434
+ has_relationship "testing", :has_part
435
+ has_relationship "testing2", :has_member
436
+ has_relationship "testing_inbound", :has_part, :inbound=>true
437
+ end
438
+
439
+ it 'should automatically update the relationships_by_name if relationships has changed (no refresh of relationships_by_name hash unless relationships hash has changed' do
440
+ @test_object2 = MockSemNamedRelationships.new
441
+ r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockSemNamedRelationships)})
442
+ @test_object2.add_relationship(r)
443
+ #should return expected named relationships
444
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
445
+ r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object})
446
+ @test_object2.add_relationship(r3)
447
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[r3.object],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
448
+ r4 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>"3"})
449
+ @test_object2.add_relationship(r4)
450
+ @test_object2.relationships_by_name.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object]},:inbound=>{"testing_inbound"=>[]}}
451
+ end
452
+ end
94
453
  end