active-fedora 2.3.4 → 2.3.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/Gemfile.lock +5 -4
- data/History.txt +16 -0
- data/README.textile +1 -1
- data/active-fedora.gemspec +1 -1
- data/lib/active_fedora.rb +4 -4
- data/lib/active_fedora/relationships_helper.rb +889 -0
- data/lib/active_fedora/semantic_node.rb +53 -383
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_spec.rb +87 -170
- data/spec/integration/datastream_spec.rb +3 -3
- data/spec/integration/datastreams_crud_spec.rb +1 -1
- data/spec/integration/rels_ext_datastream_spec.rb +4 -4
- data/spec/integration/semantic_node_spec.rb +369 -10
- data/spec/unit/active_fedora_spec.rb +42 -19
- data/spec/unit/base_extra_spec.rb +1 -0
- data/spec/unit/base_spec.rb +16 -20
- data/spec/unit/relationships_helper_spec.rb +842 -0
- data/spec/unit/semantic_node_spec.rb +49 -323
- metadata +88 -85
@@ -138,10 +138,12 @@ describe ActiveFedora::SemanticNode do
|
|
138
138
|
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
139
139
|
local_node = SpecNode.new
|
140
140
|
local_node.should respond_to(:parts_ids)
|
141
|
+
local_node.should respond_to(:parts_query)
|
141
142
|
# local_node.should respond_to(:parts)
|
142
143
|
local_node.should_not respond_to(:containers)
|
143
144
|
SpecNode.has_relationship("containers", :is_member_of)
|
144
145
|
local_node.should respond_to(:containers_ids)
|
146
|
+
local_node.should respond_to(:containers_query)
|
145
147
|
end
|
146
148
|
|
147
149
|
it "should add a subject and predicate to the relationships array" do
|
@@ -187,6 +189,7 @@ describe ActiveFedora::SemanticNode do
|
|
187
189
|
end
|
188
190
|
|
189
191
|
#can only duplicate predicates if not both inbound or not both outbound
|
192
|
+
=begin
|
190
193
|
class MockHasRelationshipDuplicatePredicate < SpecNode2
|
191
194
|
has_relationship "testing", :has_member, :type=>SpecNode2
|
192
195
|
had_exception = false
|
@@ -197,7 +200,9 @@ describe ActiveFedora::SemanticNode do
|
|
197
200
|
end
|
198
201
|
raise "Did not raise exception if duplicate predicate used" unless had_exception
|
199
202
|
end
|
200
|
-
|
203
|
+
=end
|
204
|
+
|
205
|
+
=begin
|
201
206
|
#can only duplicate predicates if not both inbound or not both outbound
|
202
207
|
class MockHasRelationshipDuplicatePredicate2 < SpecNode2
|
203
208
|
has_relationship "testing", :has_member, :type=>SpecNode2, :inbound=>true
|
@@ -209,6 +214,7 @@ describe ActiveFedora::SemanticNode do
|
|
209
214
|
end
|
210
215
|
raise "Did not raise exception if duplicate predicate used" unless had_exception
|
211
216
|
end
|
217
|
+
=end
|
212
218
|
|
213
219
|
it 'should create relationship descriptions both inbound and outbound' do
|
214
220
|
@test_object2 = MockHasRelationship.new
|
@@ -224,7 +230,7 @@ describe ActiveFedora::SemanticNode do
|
|
224
230
|
@test_object2.should_not respond_to(:testing_inbound_append)
|
225
231
|
@test_object2.should_not respond_to(:testing_inbound_remove)
|
226
232
|
|
227
|
-
@test_object2.
|
233
|
+
@test_object2.relationships_desc.should ==
|
228
234
|
{:inbound=>{"testing_inbound"=>{:type=>SpecNode2,
|
229
235
|
:predicate=>:has_part,
|
230
236
|
:inbound=>true,
|
@@ -255,6 +261,7 @@ describe ActiveFedora::SemanticNode do
|
|
255
261
|
local_node.should respond_to(:containers_ids)
|
256
262
|
local_node.should respond_to(:containers)
|
257
263
|
local_node.should respond_to(:containers_from_solr)
|
264
|
+
local_node.should respond_to(:containers_query)
|
258
265
|
end
|
259
266
|
|
260
267
|
it "resulting finder should search against solr and use Model#load_instance to build an array of objects" do
|
@@ -265,7 +272,8 @@ describe ActiveFedora::SemanticNode do
|
|
265
272
|
mock_repo.expects(:find_model).with("_PID3_", "AudioRecord").returns("AR3")
|
266
273
|
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
267
274
|
local_node = SpecNode.new()
|
268
|
-
local_node.expects(:
|
275
|
+
local_node.expects(:pid).returns("test:sample_pid")
|
276
|
+
SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
|
269
277
|
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(solr_result)
|
270
278
|
Fedora::Repository.expects(:instance).returns(mock_repo).times(3)
|
271
279
|
Kernel.expects(:const_get).with("AudioRecord").returns("AudioRecord").times(3)
|
@@ -278,7 +286,8 @@ describe ActiveFedora::SemanticNode do
|
|
278
286
|
local_node = SpecNode.new
|
279
287
|
mock_repo = mock("repo")
|
280
288
|
mock_repo.expects(:find_model).never
|
281
|
-
local_node.expects(:
|
289
|
+
local_node.expects(:pid).returns("test:sample_pid")
|
290
|
+
SpecNode.expects(:relationships_desc).returns({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}}).at_least_once()
|
282
291
|
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid", :rows=>101).returns(solr_result)
|
283
292
|
local_node.constituents(:response_format => :solr, :rows=>101).should equal(solr_result)
|
284
293
|
end
|
@@ -287,7 +296,8 @@ describe ActiveFedora::SemanticNode do
|
|
287
296
|
it "resulting _ids finder should search against solr and return an array of fedora PIDs" do
|
288
297
|
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
289
298
|
local_node = SpecNode.new
|
290
|
-
local_node.expects(:
|
299
|
+
local_node.expects(:pid).returns("test:sample_pid")
|
300
|
+
SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
|
291
301
|
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(mock("solr result", :hits => [Hash["id"=>"pid1"], Hash["id"=>"pid2"]]))
|
292
302
|
local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
|
293
303
|
end
|
@@ -298,6 +308,13 @@ describe ActiveFedora::SemanticNode do
|
|
298
308
|
local_node.expects(:parts).with(:response_format => :id_array)
|
299
309
|
local_node.parts_ids
|
300
310
|
end
|
311
|
+
|
312
|
+
it "resulting _query finder should call relationship_query" do
|
313
|
+
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
314
|
+
local_node = SpecNode.new
|
315
|
+
local_node.expects(:relationship_query).with("parts")
|
316
|
+
local_node.parts_query
|
317
|
+
end
|
301
318
|
|
302
319
|
it "resulting finder should provide option of filtering results by :type"
|
303
320
|
end
|
@@ -318,6 +335,7 @@ describe ActiveFedora::SemanticNode do
|
|
318
335
|
local_node.should respond_to(:containers_ids)
|
319
336
|
local_node.should respond_to(:containers)
|
320
337
|
local_node.should respond_to(:containers_from_solr)
|
338
|
+
local_node.should respond_to(:containers_query)
|
321
339
|
end
|
322
340
|
|
323
341
|
describe " resulting finder" do
|
@@ -374,6 +392,13 @@ describe ActiveFedora::SemanticNode do
|
|
374
392
|
local_node.parts_ids
|
375
393
|
end
|
376
394
|
end
|
395
|
+
|
396
|
+
it "resulting _query finder should call relationship_query" do
|
397
|
+
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
398
|
+
local_node = SpecNode.new
|
399
|
+
local_node.expects(:relationship_query).with("containers")
|
400
|
+
local_node.containers_query
|
401
|
+
end
|
377
402
|
end
|
378
403
|
|
379
404
|
describe ".create_bidirectional_relationship_finder" do
|
@@ -399,10 +424,10 @@ describe ActiveFedora::SemanticNode do
|
|
399
424
|
end
|
400
425
|
it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
|
401
426
|
# get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
|
402
|
-
@local_node.expects(:
|
427
|
+
@local_node.expects(:outbound_relationships).returns({:has_part=>["mypid:1"]}).at_least_once()
|
403
428
|
id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
|
404
429
|
solr_result = mock("solr result")
|
405
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid
|
430
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("#{id_array_query} OR (is_part_of_s:info\\:fedora/test\\:sample_pid)", :rows=>25).returns(solr_result)
|
406
431
|
@local_node.all_parts(:response_format=>:solr)
|
407
432
|
end
|
408
433
|
|
@@ -416,6 +441,19 @@ describe ActiveFedora::SemanticNode do
|
|
416
441
|
@local_node.relationship_names.include?("all_parts_outbound").should == true
|
417
442
|
end
|
418
443
|
|
444
|
+
it "should register finder methods for the bidirectional relationship name" do
|
445
|
+
@local_node.should respond_to(:all_parts)
|
446
|
+
@local_node.should respond_to(:all_parts_ids)
|
447
|
+
@local_node.should respond_to(:all_parts_query)
|
448
|
+
@local_node.should respond_to(:all_parts_from_solr)
|
449
|
+
end
|
450
|
+
|
451
|
+
it "resulting _query finder should call relationship_query" do
|
452
|
+
SpecNode.create_bidirectional_relationship_finders("containers", :is_member_of, :has_member)
|
453
|
+
local_node = SpecNode.new
|
454
|
+
local_node.expects(:relationship_query).with("containers")
|
455
|
+
local_node.containers_query
|
456
|
+
end
|
419
457
|
end
|
420
458
|
|
421
459
|
describe "#has_bidirectional_relationship" do
|
@@ -424,7 +462,7 @@ describe ActiveFedora::SemanticNode do
|
|
424
462
|
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
425
463
|
end
|
426
464
|
|
427
|
-
it "should have
|
465
|
+
it "should have relationships_by_name and relationships hashes contain bidirectionally related objects" do
|
428
466
|
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
429
467
|
@local_node = SpecNode.new
|
430
468
|
@local_node.pid = "mypid1"
|
@@ -439,8 +477,8 @@ describe ActiveFedora::SemanticNode do
|
|
439
477
|
@local_node2.add_relationship(r3)
|
440
478
|
@local_node.relationships.should == {:self=>{:has_model=>[r.object],:has_part=>[r2.object]},:inbound=>{:is_part_of=>[]}}
|
441
479
|
@local_node2.relationships.should == {:self=>{:has_model=>[r.object],:has_part=>[r3.object]},:inbound=>{:is_part_of=>[]}}
|
442
|
-
@local_node.
|
443
|
-
@local_node2.
|
480
|
+
@local_node.relationships_by_name.should == {:self=>{"all_parts_outbound"=>[r2.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
481
|
+
@local_node2.relationships_by_name.should == {:self=>{"all_parts_outbound"=>[r3.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
444
482
|
end
|
445
483
|
end
|
446
484
|
|
@@ -597,82 +635,6 @@ describe ActiveFedora::SemanticNode do
|
|
597
635
|
|
598
636
|
end
|
599
637
|
end
|
600
|
-
|
601
|
-
it 'should provide #named_relationship_predicates' do
|
602
|
-
@test_object.should respond_to(:named_relationship_predicates)
|
603
|
-
end
|
604
|
-
|
605
|
-
describe '#named_relationship_predicates' do
|
606
|
-
class MockNamedRelationshipPredicates < SpecNode2
|
607
|
-
has_relationship "testing", :has_part, :type=>SpecNode2
|
608
|
-
has_relationship "testing2", :has_member, :type=>SpecNode2
|
609
|
-
has_relationship "testing_inbound", :has_part, :type=>SpecNode2, :inbound=>true
|
610
|
-
end
|
611
|
-
|
612
|
-
it 'should return a map of subject to relationship name to fedora ontology relationship predicate' do
|
613
|
-
@test_object2 = MockNamedRelationshipPredicates.new
|
614
|
-
@test_object2.pid = increment_pid
|
615
|
-
model_rel = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationshipPredicates)})
|
616
|
-
@test_object2.add_relationship(model_rel)
|
617
|
-
@test_object3 = SpecNode2.new
|
618
|
-
@test_object3.pid = increment_pid
|
619
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2)})
|
620
|
-
@test_object3.add_relationship(r)
|
621
|
-
@test_object4 = SpecNode2.new
|
622
|
-
@test_object4.pid = increment_pid
|
623
|
-
@test_object4.add_relationship(r)
|
624
|
-
@test_object.add_relationship(r)
|
625
|
-
#create relationships that mirror "testing"
|
626
|
-
r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object3})
|
627
|
-
r4 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object4})
|
628
|
-
@test_object2.add_relationship(r3)
|
629
|
-
@test_object2.add_relationship(r4)
|
630
|
-
#create relationship mirroring testing2
|
631
|
-
r5 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>@test_object})
|
632
|
-
@test_object2.add_relationship(r5)
|
633
|
-
@test_object2.named_relationship_predicates.should == {:self=>{"testing"=>:has_part,"testing2"=>:has_member},
|
634
|
-
:inbound=>{"testing_inbound"=>:has_part}}
|
635
|
-
|
636
|
-
end
|
637
|
-
end
|
638
|
-
|
639
|
-
it 'should provide #kind_of_model?' do
|
640
|
-
@test_object.should respond_to(:kind_of_model?)
|
641
|
-
end
|
642
|
-
|
643
|
-
describe '#kind_of_model?' do
|
644
|
-
it 'should check if current object is the kind of model class supplied' do
|
645
|
-
#has_model relationship does not get created until save called
|
646
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2)})
|
647
|
-
@test_object.add_relationship(r)
|
648
|
-
@test_object.kind_of_model?(SpecNode2).should == true
|
649
|
-
end
|
650
|
-
end
|
651
|
-
|
652
|
-
it 'should provide #assert_kind_of_model' do
|
653
|
-
@test_object.should respond_to(:assert_kind_of_model)
|
654
|
-
end
|
655
|
-
|
656
|
-
describe '#assert_kind_of_model' do
|
657
|
-
it 'should correctly assert if an object is the type of model supplied' do
|
658
|
-
@test_object3 = SpecNode2.new
|
659
|
-
@test_object3.pid = increment_pid
|
660
|
-
#has_model relationship does not get created until save called so need to add the has model rel here, is fine since not testing save
|
661
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2)})
|
662
|
-
@test_object.add_relationship(r)
|
663
|
-
@test_object3.assert_kind_of_model('object',@test_object,SpecNode2)
|
664
|
-
end
|
665
|
-
end
|
666
|
-
|
667
|
-
it 'should provide #class_from_name' do
|
668
|
-
@test_object.should respond_to(:class_from_name)
|
669
|
-
end
|
670
|
-
|
671
|
-
describe '#class_from_name' do
|
672
|
-
it 'should return a class constant for a string passed in' do
|
673
|
-
@test_object.class_from_name("SpecNode2").should == SpecNode2
|
674
|
-
end
|
675
|
-
end
|
676
638
|
|
677
639
|
it 'should provide #relationship_exists?' do
|
678
640
|
@test_object.should respond_to(:relationship_exists?)
|
@@ -689,54 +651,10 @@ describe ActiveFedora::SemanticNode do
|
|
689
651
|
end
|
690
652
|
end
|
691
653
|
|
692
|
-
it 'should provide #named_relationships' do
|
693
|
-
@test_object.should respond_to(:named_relationships)
|
694
|
-
end
|
695
|
-
|
696
|
-
describe '#named_relationships' do
|
697
|
-
|
698
|
-
class MockNamedRelationships3 < SpecNode2
|
699
|
-
has_relationship "testing", :has_part, :type=>SpecNode2
|
700
|
-
has_relationship "testing2", :has_member, :type=>SpecNode2
|
701
|
-
has_relationship "testing_inbound", :has_part, :type=>SpecNode2, :inbound=>true
|
702
|
-
end
|
703
|
-
|
704
|
-
it 'should return current named relationships' do
|
705
|
-
@test_object2 = MockNamedRelationships3.new
|
706
|
-
@test_object2.pid = increment_pid
|
707
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships3)})
|
708
|
-
@test_object2.add_relationship(r)
|
709
|
-
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2)})
|
710
|
-
@test_object.add_relationship(r2)
|
711
|
-
#should return expected named relationships
|
712
|
-
@test_object2.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
|
713
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object})
|
714
|
-
@test_object2.add_relationship(r)
|
715
|
-
@test_object2.named_relationships.should == {:self=>{"testing"=>[r.object],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
|
716
|
-
end
|
717
|
-
|
718
|
-
it 'should automatically update the named_relationships if relationships has changed (no refresh of named_relationships hash unless relationships hash has changed)' do
|
719
|
-
@test_object3 = MockNamedRelationships3.new
|
720
|
-
@test_object3.pid = increment_pid
|
721
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships3)})
|
722
|
-
@test_object3.add_relationship(r)
|
723
|
-
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2)})
|
724
|
-
@test_object.add_relationship(r2)
|
725
|
-
#should return expected named relationships
|
726
|
-
@test_object3.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
|
727
|
-
r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object})
|
728
|
-
@test_object3.add_relationship(r3)
|
729
|
-
@test_object3.named_relationships.should == {:self=>{"testing"=>[r3.object],"testing2"=>[]},:inbound=>{"testing_inbound"=>[]}}
|
730
|
-
r4 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>"3"})
|
731
|
-
@test_object3.add_relationship(r4)
|
732
|
-
@test_object3.named_relationships.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object]},:inbound=>{"testing_inbound"=>[]}}
|
733
|
-
end
|
734
|
-
end
|
735
|
-
|
736
654
|
it 'should provide #assert_kind_of' do
|
737
655
|
@test_object.should respond_to(:assert_kind_of)
|
738
656
|
end
|
739
|
-
|
657
|
+
|
740
658
|
describe '#assert_kind_of' do
|
741
659
|
it 'should raise an exception if object supplied is not the correct type' do
|
742
660
|
had_exception = false
|
@@ -750,196 +668,4 @@ describe ActiveFedora::SemanticNode do
|
|
750
668
|
@test_object.assert_kind_of 'SpecNode2', @test_object, SpecNode2
|
751
669
|
end
|
752
670
|
end
|
753
|
-
|
754
|
-
it 'should provide #relationship_names' do
|
755
|
-
@test_object.should respond_to(:relationship_names)
|
756
|
-
end
|
757
|
-
|
758
|
-
describe '#relationship_names' do
|
759
|
-
class MockRelationshipNames < SpecNode2
|
760
|
-
has_relationship "testing", :has_part, :type=>SpecNode2
|
761
|
-
has_relationship "testing2", :has_member, :type=>SpecNode2
|
762
|
-
has_relationship "testing_inbound", :has_part, :type=>SpecNode2, :inbound=>true
|
763
|
-
has_relationship "testing_inbound2", :has_member, :type=>SpecNode2, :inbound=>true
|
764
|
-
end
|
765
|
-
|
766
|
-
it 'should return an array of relationship names for this model' do
|
767
|
-
@test_object2 = MockRelationshipNames.new
|
768
|
-
@test_object2.pid = increment_pid
|
769
|
-
@test_object2.relationship_names.include?("testing").should == true
|
770
|
-
@test_object2.relationship_names.include?("testing2").should == true
|
771
|
-
@test_object2.relationship_names.include?("testing_inbound").should == true
|
772
|
-
@test_object2.relationship_names.include?("testing_inbound2").should == true
|
773
|
-
@test_object2.relationship_names.size.should == 4
|
774
|
-
end
|
775
|
-
end
|
776
|
-
|
777
|
-
it 'should provide #inbound_relationship_names' do
|
778
|
-
@test_object.should respond_to(:inbound_relationship_names)
|
779
|
-
end
|
780
|
-
|
781
|
-
describe '#inbound_relationship_names' do
|
782
|
-
it 'should return an array of inbound relationship names for this model' do
|
783
|
-
@test_object2 = MockRelationshipNames.new
|
784
|
-
@test_object2.pid = increment_pid
|
785
|
-
@test_object2.inbound_relationship_names.include?("testing_inbound").should == true
|
786
|
-
@test_object2.inbound_relationship_names.include?("testing_inbound2").should == true
|
787
|
-
@test_object2.inbound_relationship_names.size.should == 2
|
788
|
-
end
|
789
|
-
end
|
790
|
-
|
791
|
-
it 'should provide #outbound_relationship_names' do
|
792
|
-
@test_object.should respond_to(:outbound_relationship_names)
|
793
|
-
end
|
794
|
-
|
795
|
-
describe '#outbound_relationship_names' do
|
796
|
-
it 'should return an array of outbound relationship names for this model' do
|
797
|
-
@test_object2 = MockRelationshipNames.new
|
798
|
-
@test_object2.pid = increment_pid
|
799
|
-
@test_object2.outbound_relationship_names.include?("testing").should == true
|
800
|
-
@test_object2.outbound_relationship_names.include?("testing2").should == true
|
801
|
-
@test_object2.outbound_relationship_names.size.should == 2
|
802
|
-
end
|
803
|
-
end
|
804
|
-
|
805
|
-
it 'should provide #named_outbound_relationships' do
|
806
|
-
@test_object.should respond_to(:named_outbound_relationships)
|
807
|
-
end
|
808
|
-
|
809
|
-
describe '#named_outbound_relationships' do
|
810
|
-
it 'should return hash of outbound relationship names to arrays of object uri' do
|
811
|
-
@test_object2 = MockRelationshipNames.new
|
812
|
-
@test_object2.pid = increment_pid
|
813
|
-
@test_object2.named_outbound_relationships.should == {"testing"=>[],
|
814
|
-
"testing2"=>[]}
|
815
|
-
end
|
816
|
-
end
|
817
|
-
|
818
|
-
it 'should provide #named_inbound_relationships' do
|
819
|
-
#testing execution of this in integration since touches solr
|
820
|
-
@test_object.should respond_to(:named_inbound_relationships)
|
821
|
-
end
|
822
|
-
|
823
|
-
it 'should provide #named_relationship' do
|
824
|
-
@test_object.should respond_to(:named_relationship)
|
825
|
-
end
|
826
|
-
|
827
|
-
describe '#named_relationship' do
|
828
|
-
it 'should return an array of object uri for a given relationship name' do
|
829
|
-
@test_object2 = MockRelationshipNames.new
|
830
|
-
@test_object2.pid = increment_pid
|
831
|
-
r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_model, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockRelationshipNames))
|
832
|
-
@test_object2.add_relationship(r)
|
833
|
-
@test_object3 = SpecNode2.new
|
834
|
-
@test_object3.pid = increment_pid
|
835
|
-
r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_model, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2))
|
836
|
-
@test_object3.add_relationship(r2)
|
837
|
-
@test_object4 = SpecNode2.new
|
838
|
-
@test_object4.pid = increment_pid
|
839
|
-
@test_object4.add_relationship(r2)
|
840
|
-
@test_object.add_relationship(r2)
|
841
|
-
#add relationships that mirror 'testing' and 'testing2'
|
842
|
-
r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_part, :object=>@test_object3)
|
843
|
-
r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_member, :object=>@test_object4)
|
844
|
-
@test_object2.add_relationship(r3)
|
845
|
-
@test_object2.add_relationship(r4)
|
846
|
-
@test_object2.named_relationship("testing").should == [r3.object]
|
847
|
-
end
|
848
|
-
end
|
849
|
-
|
850
|
-
describe ActiveFedora::SemanticNode::ClassMethods do
|
851
|
-
|
852
|
-
after(:each) do
|
853
|
-
begin
|
854
|
-
@test_object2.delete
|
855
|
-
rescue
|
856
|
-
end
|
857
|
-
end
|
858
|
-
|
859
|
-
describe '#named_relationships_desc' do
|
860
|
-
it 'should initialize named_relationships_desc to a new hash containing self' do
|
861
|
-
@test_object2 = SpecNode2.new
|
862
|
-
@test_object2.pid = increment_pid
|
863
|
-
@test_object2.named_relationships_desc.should == {:self=>{}}
|
864
|
-
end
|
865
|
-
end
|
866
|
-
|
867
|
-
describe '#register_named_subject' do
|
868
|
-
|
869
|
-
class MockRegisterNamedSubject < SpecNode2
|
870
|
-
register_named_subject :test
|
871
|
-
end
|
872
|
-
|
873
|
-
it 'should add a new named subject to the named relationships only if it does not already exist' do
|
874
|
-
@test_object2 = MockRegisterNamedSubject.new
|
875
|
-
@test_object2.pid = increment_pid
|
876
|
-
@test_object2.named_relationships_desc.should == {:self=>{}, :test=>{}}
|
877
|
-
end
|
878
|
-
end
|
879
|
-
|
880
|
-
describe '#register_named_relationship' do
|
881
|
-
|
882
|
-
class MockRegisterNamedRelationship < SpecNode2
|
883
|
-
register_named_relationship :self, "testing", :is_part_of, :type=>SpecNode2
|
884
|
-
register_named_relationship :inbound, "testing2", :has_part, :type=>SpecNode2
|
885
|
-
end
|
886
|
-
|
887
|
-
it 'should add a new named subject to the named relationships only if it does not already exist' do
|
888
|
-
@test_object2 = MockRegisterNamedRelationship.new
|
889
|
-
@test_object2.pid = increment_pid
|
890
|
-
@test_object2.named_relationships_desc.should == {:inbound=>{"testing2"=>{:type=>SpecNode2, :predicate=>:has_part}}, :self=>{"testing"=>{:type=>SpecNode2, :predicate=>:is_part_of}}}
|
891
|
-
end
|
892
|
-
end
|
893
|
-
|
894
|
-
describe '#create_named_relationship_methods' do
|
895
|
-
class MockCreateNamedRelationshipMethods < SpecNode2
|
896
|
-
register_named_relationship :self, "testing", :is_part_of, :type=>SpecNode2
|
897
|
-
create_named_relationship_methods "testing"
|
898
|
-
end
|
899
|
-
|
900
|
-
it 'should create an append and remove method for each outbound relationship' do
|
901
|
-
@test_object2 = MockCreateNamedRelationshipMethods.new
|
902
|
-
@test_object2.pid = increment_pid
|
903
|
-
@test_object2.should respond_to(:testing_append)
|
904
|
-
@test_object2.should respond_to(:testing_remove)
|
905
|
-
#test execution in base_spec since method definitions include methods in ActiveFedora::Base
|
906
|
-
end
|
907
|
-
end
|
908
|
-
|
909
|
-
describe '#create_bidirectional_named_relationship_methods' do
|
910
|
-
class MockCreateNamedRelationshipMethods < SpecNode2
|
911
|
-
register_named_relationship :self, "testing_outbound", :is_part_of, :type=>SpecNode2
|
912
|
-
create_bidirectional_named_relationship_methods "testing", "testing_outbound"
|
913
|
-
end
|
914
|
-
|
915
|
-
it 'should create an append and remove method for each outbound relationship' do
|
916
|
-
@test_object2 = MockCreateNamedRelationshipMethods.new
|
917
|
-
@test_object2.pid = increment_pid
|
918
|
-
@test_object2.should respond_to(:testing_append)
|
919
|
-
@test_object2.should respond_to(:testing_remove)
|
920
|
-
#test execution in base_spec since method definitions include methods in ActiveFedora::Base
|
921
|
-
end
|
922
|
-
end
|
923
|
-
|
924
|
-
describe '#def named_predicate_exists_with_different_name?' do
|
925
|
-
|
926
|
-
it 'should return true if a predicate exists for same subject and different name but not different subject' do
|
927
|
-
class MockPredicateExists < SpecNode2
|
928
|
-
has_relationship "testing", :has_part, :type=>SpecNode2
|
929
|
-
has_relationship "testing2", :has_member, :type=>SpecNode2
|
930
|
-
has_relationship "testing_inbound", :is_part_of, :type=>SpecNode2, :inbound=>true
|
931
|
-
|
932
|
-
named_predicate_exists_with_different_name?(:self,"testing",:has_part).should == false
|
933
|
-
named_predicate_exists_with_different_name?(:self,"testing3",:has_part).should == true
|
934
|
-
named_predicate_exists_with_different_name?(:inbound,"testing",:has_part).should == false
|
935
|
-
named_predicate_exists_with_different_name?(:self,"testing2",:has_member).should == false
|
936
|
-
named_predicate_exists_with_different_name?(:self,"testing3",:has_member).should == true
|
937
|
-
named_predicate_exists_with_different_name?(:inbound,"testing2",:has_member).should == false
|
938
|
-
named_predicate_exists_with_different_name?(:self,"testing_inbound",:is_part_of).should == false
|
939
|
-
named_predicate_exists_with_different_name?(:inbound,"testing_inbound",:is_part_of).should == false
|
940
|
-
named_predicate_exists_with_different_name?(:inbound,"testing_inbound2",:is_part_of).should == true
|
941
|
-
end
|
942
|
-
end
|
943
|
-
end
|
944
|
-
end
|
945
671
|
end
|