active-fedora 3.1.0.pre2 → 3.1.0.pre3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +9 -1
- data/active-fedora.gemspec +2 -0
- data/lib/active_fedora.rb +2 -3
- data/lib/active_fedora/base.rb +9 -29
- data/lib/active_fedora/content_model.rb +1 -1
- data/lib/active_fedora/relationships_helper.rb +23 -27
- data/lib/active_fedora/rels_ext_datastream.rb +48 -42
- data/lib/active_fedora/semantic_node.rb +109 -136
- data/lib/active_fedora/version.rb +1 -1
- data/lib/tasks/active_fedora_dev.rake +0 -12
- data/spec/integration/base_spec.rb +44 -40
- data/spec/integration/rels_ext_datastream_spec.rb +31 -10
- data/spec/integration/semantic_node_spec.rb +40 -31
- data/spec/spec_helper.rb +4 -2
- data/spec/unit/active_fedora_spec.rb +6 -13
- data/spec/unit/base_spec.rb +16 -19
- data/spec/unit/content_model_spec.rb +4 -4
- data/spec/unit/relationships_helper_spec.rb +31 -12
- data/spec/unit/rels_ext_datastream_spec.rb +55 -25
- data/spec/unit/semantic_node_spec.rb +52 -121
- metadata +48 -20
data/spec/unit/base_spec.rb
CHANGED
@@ -203,19 +203,16 @@ describe ActiveFedora::Base do
|
|
203
203
|
|
204
204
|
describe '#add_relationship' do
|
205
205
|
it 'should call #add_relationship on the rels_ext datastream' do
|
206
|
-
|
207
|
-
mock_rels_ext = mock("rels-ext", :add_relationship)
|
206
|
+
mock_rels_ext = mock("rels-ext")#, :add_relationship)
|
208
207
|
mock_rels_ext.expects(:dirty=).with(true)
|
209
208
|
@test_object.expects(:relationship_exists?).returns(false).once()
|
210
|
-
@test_object.expects(:rels_ext).returns(mock_rels_ext)
|
209
|
+
@test_object.expects(:rels_ext).returns(mock_rels_ext)
|
211
210
|
@test_object.add_relationship("predicate", "object")
|
212
211
|
end
|
213
212
|
|
214
213
|
it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
|
215
214
|
mock_ds = mock("Rels-Ext")
|
216
|
-
mock_ds.expects(:add_relationship).times(2)
|
217
215
|
mock_ds.expects(:dirty=).with(true).times(2)
|
218
|
-
@test_object.expects(:relationship_exists?).returns(false).times(2)
|
219
216
|
@test_object.datastreams["RELS-EXT"] = mock_ds
|
220
217
|
test_relationships = [ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:5"),
|
221
218
|
ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:10")]
|
@@ -229,15 +226,15 @@ describe ActiveFedora::Base do
|
|
229
226
|
@test_object3 = ActiveFedora::Base.new
|
230
227
|
@test_object.add_relationship(:has_part,@test_object3)
|
231
228
|
r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
|
232
|
-
@test_object.
|
229
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
|
233
230
|
#try adding again and make sure not there twice
|
234
231
|
@test_object.add_relationship(:has_part,@test_object3)
|
235
|
-
@test_object.
|
232
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
|
236
233
|
end
|
237
234
|
|
238
235
|
it 'should add literal relationships if requested' do
|
239
236
|
@test_object.add_relationship(:conforms_to,"AnInterface",true)
|
240
|
-
@test_object.
|
237
|
+
@test_object.ids_for_outbound(:conforms_to).should == ["AnInterface"]
|
241
238
|
end
|
242
239
|
end
|
243
240
|
|
@@ -253,16 +250,14 @@ describe ActiveFedora::Base do
|
|
253
250
|
@test_object4 = ActiveFedora::Base.new
|
254
251
|
@test_object.add_relationship(:has_part,@test_object3)
|
255
252
|
@test_object.add_relationship(:has_part,@test_object4)
|
256
|
-
r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
|
257
|
-
r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object4)
|
258
253
|
#check both are there
|
259
|
-
@test_object.
|
254
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid,@test_object4.pid]
|
260
255
|
@test_object.remove_relationship(:has_part,@test_object3)
|
261
256
|
#check only one item removed
|
262
|
-
@test_object.
|
257
|
+
@test_object.ids_for_outbound(:has_part).should == [@test_object4.pid]
|
263
258
|
@test_object.remove_relationship(:has_part,@test_object4)
|
264
259
|
#check last item removed and predicate removed since now emtpy
|
265
|
-
@test_object.relationships.should ==
|
260
|
+
@test_object.relationships.size.should == 0
|
266
261
|
end
|
267
262
|
end
|
268
263
|
|
@@ -271,9 +266,9 @@ describe ActiveFedora::Base do
|
|
271
266
|
end
|
272
267
|
|
273
268
|
describe '#relationships' do
|
274
|
-
it 'should
|
275
|
-
@test_object.
|
276
|
-
@test_object.relationships
|
269
|
+
it 'should return a graph' do
|
270
|
+
@test_object.relationships.kind_of?(RDF::Graph).should be_true
|
271
|
+
@test_object.relationships.size.should == 0
|
277
272
|
end
|
278
273
|
end
|
279
274
|
|
@@ -384,6 +379,7 @@ describe ActiveFedora::Base do
|
|
384
379
|
dirty_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
|
385
380
|
rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
386
381
|
rels_ds.expects(:new?).returns(false)
|
382
|
+
rels_ds.model = @test_object
|
387
383
|
mock2 = mock("ds2")
|
388
384
|
mock2.stubs(:changed? => false)
|
389
385
|
mock2.expects(:serialize!)
|
@@ -405,6 +401,7 @@ describe ActiveFedora::Base do
|
|
405
401
|
mock_rels_ext.stubs(:dsid=>"RELS-EXT", :relationships=>{}, :add_relationship=>nil, :dirty= => nil)
|
406
402
|
mock_rels_ext.expects( :changed?).returns(false).at_least_once
|
407
403
|
mock_rels_ext.expects(:serialize!)
|
404
|
+
mock_rels_ext.expects(:model=).with(@test_object)
|
408
405
|
ActiveFedora::RelsExtDatastream.expects(:new).returns(mock_rels_ext)
|
409
406
|
@test_object.stubs(:datastreams).returns({:ds1 => mock1, :ds2 => mock2})
|
410
407
|
@test_object.expects(:update_index).never
|
@@ -415,16 +412,16 @@ describe ActiveFedora::Base do
|
|
415
412
|
|
416
413
|
@test_object.save
|
417
414
|
end
|
418
|
-
it "should update solr index if
|
415
|
+
it "should update solr index if relationships have changed" do
|
419
416
|
@mock_repo = mock('repository')
|
420
417
|
@mock_repo.expects(:ingest).with(:pid => @test_object.pid)
|
421
418
|
@test_object.inner_object.expects(:repository).returns(@mock_repo).at_least_once
|
422
419
|
@test_object.inner_object.expects(:new?).returns(true).twice
|
423
420
|
|
424
421
|
rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
425
|
-
rels_ext.
|
422
|
+
rels_ext.model = @test_object
|
426
423
|
rels_ext.expects(:new?).returns(true)
|
427
|
-
|
424
|
+
rels_ext.expects(:save).returns(true)
|
428
425
|
rels_ext.expects(:serialize!)
|
429
426
|
clean_ds = mock("ds2")
|
430
427
|
clean_ds.stubs(:dirty? => false, :changed? => false, :new? => false)
|
@@ -55,16 +55,16 @@ describe ActiveFedora::ContentModel do
|
|
55
55
|
|
56
56
|
describe "#pid_from_ruby_class" do
|
57
57
|
it "should construct pids" do
|
58
|
-
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "afmodel:ActiveFedora_ContentModel"
|
59
|
-
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class, :namespace => "foo", :pid_suffix => "BarBar").should == "foo:ActiveFedora_ContentModelBarBar"
|
58
|
+
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "info:fedora/afmodel:ActiveFedora_ContentModel"
|
59
|
+
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class, :namespace => "foo", :pid_suffix => "BarBar").should == "info:fedora/foo:ActiveFedora_ContentModelBarBar"
|
60
60
|
end
|
61
61
|
it "should construct pids with the namespace declared in the model" do
|
62
62
|
ActiveFedora::ContentModel.stubs(:pid_namespace).returns("test-cModel")
|
63
|
-
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "test-cModel:ActiveFedora_ContentModel"
|
63
|
+
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == "info:fedora/test-cModel:ActiveFedora_ContentModel"
|
64
64
|
end
|
65
65
|
it "should construct pids with the suffix declared in the model" do
|
66
66
|
ActiveFedora::ContentModel.stubs(:pid_suffix).returns("-TEST-SUFFIX")
|
67
|
-
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == 'afmodel:ActiveFedora_ContentModel-TEST-SUFFIX'
|
67
|
+
ActiveFedora::ContentModel.pid_from_ruby_class(@test_cmodel.class).should == 'info:fedora/afmodel:ActiveFedora_ContentModel-TEST-SUFFIX'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -6,6 +6,7 @@ require 'xmlsimple'
|
|
6
6
|
@@last_pid = 0
|
7
7
|
|
8
8
|
class SpecNamedNode
|
9
|
+
include ActiveFedora::SemanticNode
|
9
10
|
include ActiveFedora::RelationshipsHelper
|
10
11
|
|
11
12
|
attr_accessor :pid
|
@@ -51,7 +52,10 @@ describe ActiveFedora::RelationshipsHelper do
|
|
51
52
|
it 'should check if current object is the kind of model class supplied' do
|
52
53
|
#has_model relationship does not get created until save called
|
53
54
|
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNamedNode)})
|
54
|
-
|
55
|
+
graph = RDF::Graph.new
|
56
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
57
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new(r.object))
|
58
|
+
@test_object.expects(:relationships).returns(graph).at_least_once
|
55
59
|
@test_object.conforms_to?(SpecNamedNode).should == true
|
56
60
|
end
|
57
61
|
end
|
@@ -66,7 +70,10 @@ describe ActiveFedora::RelationshipsHelper do
|
|
66
70
|
@test_object3.pid = increment_pid
|
67
71
|
#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
|
68
72
|
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNamedNode)})
|
69
|
-
|
73
|
+
graph = RDF::Graph.new
|
74
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
75
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new(r.object))
|
76
|
+
@test_object.expects(:relationships).returns(graph).at_least_once
|
70
77
|
@test_object3.assert_conforms_to('object',@test_object,SpecNamedNode)
|
71
78
|
end
|
72
79
|
end
|
@@ -101,12 +108,19 @@ describe ActiveFedora::RelationshipsHelper do
|
|
101
108
|
@test_object3 = MockNamedRelationships3.new
|
102
109
|
@test_object3.pid = increment_pid
|
103
110
|
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockNamedRelationships3)})
|
104
|
-
|
111
|
+
graph = RDF::Graph.new
|
112
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
113
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new(r.object))
|
114
|
+
@test_object2.expects(:relationships).returns(graph).at_least_once
|
105
115
|
#should return expected named relationships
|
106
|
-
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[]}
|
116
|
+
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[]}}
|
107
117
|
r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@test_object})
|
108
|
-
|
109
|
-
|
118
|
+
graph = RDF::Graph.new
|
119
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
120
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new(r.object))
|
121
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_part), RDF::URI.new(r3.object))
|
122
|
+
@test_object3.expects(:relationships).returns(graph).at_least_once
|
123
|
+
@test_object3.relationships_by_name.should == {:self=>{"testing"=>[r3.object],"testing2"=>[]}}
|
110
124
|
end
|
111
125
|
end
|
112
126
|
|
@@ -171,7 +185,9 @@ describe ActiveFedora::RelationshipsHelper do
|
|
171
185
|
it 'should return hash of outbound relationship names to arrays of object uri' do
|
172
186
|
@test_object2 = MockRelationshipNames.new
|
173
187
|
@test_object2.pid = increment_pid
|
174
|
-
|
188
|
+
graph = RDF::Graph.new
|
189
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
190
|
+
@test_object2.expects(:relationships).returns(graph).at_least_once
|
175
191
|
@test_object2.outbound_relationships_by_name.should == {"testing"=>[],
|
176
192
|
"testing2"=>[]}
|
177
193
|
end
|
@@ -198,7 +214,12 @@ describe ActiveFedora::RelationshipsHelper do
|
|
198
214
|
#add relationships that mirror 'testing' and 'testing2'
|
199
215
|
r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_part, :object=>@test_object3)
|
200
216
|
r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:has_member, :object=>@test_object4)
|
201
|
-
|
217
|
+
graph = RDF::Graph.new
|
218
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
219
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new(r.object))
|
220
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_member), RDF::URI.new(r4.object))
|
221
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_part), RDF::URI.new(r3.object))
|
222
|
+
@test_object2.expects(:relationships).returns(graph).at_least_once
|
202
223
|
@test_object2.find_relationship_by_name("testing").should == [r3.object]
|
203
224
|
end
|
204
225
|
end
|
@@ -221,18 +242,16 @@ describe ActiveFedora::RelationshipsHelper do
|
|
221
242
|
end
|
222
243
|
|
223
244
|
it "should call bidirectional_relationship_query if a bidirectional relationship" do
|
224
|
-
rels_ids = ["info:fedora/changeme:1","info:fedora/changeme:2","info:fedora/changeme:3","info:fedora/changeme:4"]
|
225
|
-
@mockrelsquery.expects(:outbound_relationships).returns({:has_part=>rels_ids}).at_least_once
|
226
245
|
ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
|
246
|
+
@mockrelsquery.expects(:ids_for_outbound).with(:has_part).returns(ids).at_least_once
|
227
247
|
@mockrelsquery.expects(:pid).returns("changeme:5")
|
228
248
|
MockNamedRelationshipQuery.expects(:bidirectional_relationship_query).with("changeme:5","testing_bi_query",ids)
|
229
249
|
@mockrelsquery.relationship_query("testing_bi_query")
|
230
250
|
end
|
231
251
|
|
232
252
|
it "should call outbound_relationship_query if an outbound relationship" do
|
233
|
-
rels_ids = ["info:fedora/changeme:1","info:fedora/changeme:2","info:fedora/changeme:3","info:fedora/changeme:4"]
|
234
|
-
@mockrelsquery.expects(:outbound_relationships).returns({:is_part_of=>rels_ids}).at_least_once
|
235
253
|
ids = ["changeme:1","changeme:2","changeme:3","changeme:4"]
|
254
|
+
@mockrelsquery.expects(:ids_for_outbound).with(:is_part_of).returns(ids).at_least_once
|
236
255
|
MockNamedRelationshipQuery.expects(:outbound_relationship_query).with("testing_outbound_no_solr_fq",ids)
|
237
256
|
@mockrelsquery.relationship_query("testing_outbound_no_solr_fq")
|
238
257
|
end
|
@@ -1,18 +1,11 @@
|
|
1
1
|
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
2
|
|
3
|
-
require '
|
4
|
-
require "rexml/document"
|
5
|
-
require "nokogiri"
|
6
|
-
require 'ftools'
|
3
|
+
require 'equivalent-xml'
|
7
4
|
|
8
5
|
describe ActiveFedora::RelsExtDatastream do
|
9
6
|
|
10
7
|
before(:all) do
|
11
8
|
@pid = "test:sample_pid"
|
12
|
-
@test_relationship1 = ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "demo:10")
|
13
|
-
@test_relationship2 = ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_part_of, :object => "demo:11")
|
14
|
-
@test_relationship3 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => :has_part, :object => "demo:12")
|
15
|
-
@test_relationship4 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => :conforms_to, :object => "AnInterface", :is_literal=>true)
|
16
9
|
|
17
10
|
@sample_xml = Nokogiri::XML::Document.parse(@sample_xml_string)
|
18
11
|
end
|
@@ -33,36 +26,65 @@ describe ActiveFedora::RelsExtDatastream do
|
|
33
26
|
describe '#serialize!' do
|
34
27
|
|
35
28
|
it "should generate new rdf/xml as the datastream content if the object has been changed" do
|
36
|
-
|
29
|
+
graph = RDF::Graph.new
|
30
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
31
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('demo:10'))
|
32
|
+
|
33
|
+
@test_ds.expects(:model).returns(stub("model", :outbound_relationships=>graph, :relationships=>graph, :relationships_are_dirty =>true, :relationships_are_dirty= => true)).times(3)
|
37
34
|
@test_ds.serialize!
|
38
|
-
@test_ds.content
|
35
|
+
EquivalentXml.equivalent?(@test_ds.content, "<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n <rdf:Description rdf:about='info:fedora/test:sample_pid'>\n <isMemberOf rdf:resource='demo:10' xmlns='info:fedora/fedora-system:def/relations-external#'/></rdf:Description>\n </rdf:RDF>").should be_true
|
39
36
|
end
|
40
37
|
|
41
38
|
end
|
39
|
+
|
40
|
+
describe '#to_rels_ext' do
|
41
|
+
|
42
|
+
before(:all) do
|
43
|
+
@sample_rels_ext_xml = <<-EOS
|
44
|
+
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
|
45
|
+
<rdf:Description rdf:about='info:fedora/test:sample_pid'>
|
46
|
+
<isMemberOf rdf:resource='info:fedora/demo:10' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
47
|
+
<isPartOf rdf:resource='info:fedora/demo:11' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
48
|
+
<hasPart rdf:resource='info:fedora/demo:12' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
49
|
+
<hasModel rdf:resource='info:fedora/afmodel:OtherModel' xmlns='info:fedora/fedora-system:def/model#'/>
|
50
|
+
<hasModel rdf:resource='info:fedora/afmodel:SampleModel' xmlns='info:fedora/fedora-system:def/model#'/>
|
51
|
+
</rdf:Description>
|
52
|
+
</rdf:RDF>
|
53
|
+
EOS
|
54
|
+
@pid = "test:sample_pid"
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should serialize the relationships array to Fedora RELS-EXT rdf/xml' do
|
58
|
+
graph = RDF::Graph.new
|
59
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
60
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
61
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
62
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
63
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new("info:fedora/afmodel:OtherModel"))
|
64
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_model), RDF::URI.new("info:fedora/afmodel:SampleModel"))
|
65
|
+
|
66
|
+
@test_ds.expects(:model).returns(stub("model", :relationships=>graph, :relationships_are_dirty= => true))
|
67
|
+
EquivalentXml.equivalent?(@test_ds.to_rels_ext(), @sample_rels_ext_xml).should be_true
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
42
71
|
|
43
72
|
describe "#from_xml" do
|
44
73
|
before(:all) do
|
45
74
|
@test_obj = ActiveFedora::Base.new
|
46
|
-
@test_obj.add_relationship(:is_member_of, "demo:10")
|
47
|
-
@test_obj.add_relationship(:is_part_of, "demo:11")
|
75
|
+
@test_obj.add_relationship(:is_member_of, "info:fedora/demo:10")
|
76
|
+
@test_obj.add_relationship(:is_part_of, "info:fedora/demo:11")
|
48
77
|
@test_obj.add_relationship(:conforms_to, "AnInterface", true)
|
49
78
|
@test_obj.save
|
50
79
|
end
|
51
80
|
after(:all) do
|
52
81
|
@test_obj.delete
|
53
82
|
end
|
54
|
-
it "should load RELS-EXT relationships into relationships hash" do
|
55
|
-
@test_obj.relationships.should == {:self=>{:is_member_of=>["info:fedora/demo:10"], :is_part_of=>["info:fedora/demo:11"], :has_model=>["info:fedora/afmodel:ActiveFedora_Base"], :conforms_to=>["AnInterface"]}}
|
56
|
-
new_ds = ActiveFedora::RelsExtDatastream.new(nil, nil)
|
57
|
-
new_ds.relationships.should == {:self=>{}}
|
58
|
-
ActiveFedora::RelsExtDatastream.from_xml(@test_obj.rels_ext.content,new_ds)
|
59
|
-
new_ds.relationships.should == @test_obj.relationships
|
60
|
-
end
|
61
83
|
it "should handle un-mapped predicates gracefully" do
|
62
|
-
@test_obj.relationships.should == {:self=>{:is_member_of=>["info:fedora/demo:10"], :is_part_of=>["info:fedora/demo:11"], :has_model=>["info:fedora/afmodel:ActiveFedora_Base"], :conforms_to=>["AnInterface"]}}
|
63
84
|
@test_obj.add_relationship("foo", "foo:bar")
|
64
85
|
@test_obj.save
|
65
|
-
@test_obj.relationships.should ==
|
86
|
+
@test_obj.relationships.size.should == 5
|
87
|
+
@test_obj.ids_for_outbound("foo").should == ["foo:bar"]
|
66
88
|
end
|
67
89
|
it "should handle un-mapped literals" do
|
68
90
|
pending
|
@@ -93,15 +115,23 @@ describe ActiveFedora::RelsExtDatastream do
|
|
93
115
|
describe ".to_solr" do
|
94
116
|
|
95
117
|
it "should provide .to_solr and return a SolrDocument" do
|
118
|
+
graph = RDF::Graph.new
|
119
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
120
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('demo:10'))
|
96
121
|
@test_ds.should respond_to(:to_solr)
|
122
|
+
@test_ds.expects(:model).returns(stub("model", :relationships=>graph, :relationships_are_dirty= => true))
|
97
123
|
@test_ds.to_solr.should be_kind_of(Hash)
|
98
124
|
end
|
99
125
|
|
100
126
|
it "should serialize the relationships into a Hash" do
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
127
|
+
graph = RDF::Graph.new
|
128
|
+
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
129
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
130
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
131
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
132
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Base.new.find_graph_predicate(:conforms_to), "AnInterface")
|
133
|
+
|
134
|
+
@test_ds.expects(:model).returns(stub("model", :relationships=>graph, :relationships_are_dirty= => true))
|
105
135
|
solr_doc = @test_ds.to_solr
|
106
136
|
solr_doc["is_member_of_s"].should == ["info:fedora/demo:10"]
|
107
137
|
solr_doc["is_part_of_s"].should == ["info:fedora/demo:11"]
|
@@ -156,13 +156,13 @@ describe ActiveFedora::SemanticNode do
|
|
156
156
|
it "should add a subject and predicate to the relationships array" do
|
157
157
|
SpecNode.has_relationship("parents", :is_part_of)
|
158
158
|
SpecNode.relationships.should have_key(:self)
|
159
|
-
|
159
|
+
SpecNode.relationships[:self].should have_key(:is_part_of)
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should use :inbound as the subject if :inbound => true" do
|
163
163
|
SpecNode.has_relationship("parents", :is_part_of, :inbound => true)
|
164
164
|
SpecNode.relationships.should have_key(:inbound)
|
165
|
-
|
165
|
+
SpecNode.relationships[:inbound].should have_key(:is_part_of)
|
166
166
|
end
|
167
167
|
|
168
168
|
it 'should create inbound relationship finders' do
|
@@ -181,8 +181,12 @@ describe ActiveFedora::SemanticNode do
|
|
181
181
|
local_node = SpecNode.new
|
182
182
|
local_node.internal_uri = "info:fedora/#{@pid}"
|
183
183
|
|
184
|
-
local_node.add_relationship(ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/container:A") )
|
185
|
-
local_node.add_relationship(ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/container:B") )
|
184
|
+
# local_node.add_relationship(ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/container:A") )
|
185
|
+
# local_node.add_relationship(ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/container:B") )
|
186
|
+
local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true)).twice
|
187
|
+
local_node.add_relationship(:is_member_of, "info:fedora/container:A")
|
188
|
+
local_node.add_relationship(:is_member_of, "info:fedora/container:B")
|
189
|
+
|
186
190
|
containers_result = local_node.containers_ids
|
187
191
|
containers_result.should be_instance_of(Array)
|
188
192
|
containers_result.should include("container:A")
|
@@ -227,8 +231,8 @@ describe ActiveFedora::SemanticNode do
|
|
227
231
|
@test_object2 = MockHasRelationship.new
|
228
232
|
@test_object2.pid = increment_pid
|
229
233
|
@test_object2.stubs(:testing_inbound).returns({})
|
230
|
-
|
231
|
-
@test_object2.add_relationship(
|
234
|
+
@test_object2.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
|
235
|
+
@test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2))
|
232
236
|
@test_object2.should respond_to(:testing_append)
|
233
237
|
@test_object2.should respond_to(:testing_remove)
|
234
238
|
@test_object2.should respond_to(:testing2_append)
|
@@ -343,7 +347,7 @@ describe ActiveFedora::SemanticNode do
|
|
343
347
|
it "should read from relationships array and use Repository.find_model to build an array of objects" do
|
344
348
|
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
345
349
|
local_node = SpecNode.new
|
346
|
-
local_node.expects(:
|
350
|
+
local_node.expects(:ids_for_outbound).with(:is_member_of).returns(["my:_PID1_", "my:_PID2_", "my:_PID3_"])
|
347
351
|
mock_repo = mock("repo")
|
348
352
|
solr_result = mock("solr result", :is_a? => true)
|
349
353
|
solr_result.expects(:hits).returns(
|
@@ -369,14 +373,15 @@ describe ActiveFedora::SemanticNode do
|
|
369
373
|
it "(:response_format => :id_array) should read from relationships array" do
|
370
374
|
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
371
375
|
local_node = SpecNode.new
|
372
|
-
local_node.expects(:
|
376
|
+
local_node.expects(:ids_for_outbound).with(:is_member_of).returns([])
|
373
377
|
local_node.containers_ids
|
374
378
|
end
|
375
379
|
|
376
380
|
it "(:response_format => :id_array) should return an array of fedora PIDs" do
|
377
381
|
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
378
382
|
local_node = SpecNode.new
|
379
|
-
local_node.
|
383
|
+
local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
|
384
|
+
local_node.add_relationship(@test_relationship1.predicate, @test_relationship1.object)
|
380
385
|
result = local_node.containers_ids
|
381
386
|
result.should be_instance_of(Array)
|
382
387
|
result.should include("demo:10")
|
@@ -433,8 +438,8 @@ describe ActiveFedora::SemanticNode do
|
|
433
438
|
end
|
434
439
|
|
435
440
|
it "should register both inbound and outbound predicate components" do
|
436
|
-
@local_node.relationships[:inbound].has_key?(:is_part_of).should == true
|
437
|
-
@local_node.relationships[:self].has_key?(:has_part).should == true
|
441
|
+
@local_node.class.relationships[:inbound].has_key?(:is_part_of).should == true
|
442
|
+
@local_node.class.relationships[:self].has_key?(:has_part).should == true
|
438
443
|
end
|
439
444
|
|
440
445
|
it "should register relationship names for inbound, outbound" do
|
@@ -470,35 +475,38 @@ describe ActiveFedora::SemanticNode do
|
|
470
475
|
@local_node2 = SpecNode.new
|
471
476
|
@local_node2.pid = "mypid2"
|
472
477
|
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode)})
|
473
|
-
@local_node.
|
474
|
-
@
|
478
|
+
@local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true)).twice
|
479
|
+
@local_node.add_relationship(r.predicate, r.object)
|
480
|
+
@local_node2.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true)).twice
|
481
|
+
@local_node2.add_relationship(r.predicate, r.object)
|
475
482
|
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@local_node2})
|
476
|
-
@local_node.add_relationship(r2)
|
483
|
+
@local_node.add_relationship(r2.predicate, r2.object)
|
477
484
|
r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@local_node})
|
478
|
-
@local_node2.add_relationship(r3)
|
479
|
-
@local_node.
|
480
|
-
@
|
481
|
-
@
|
482
|
-
@local_node2.
|
485
|
+
@local_node2.add_relationship(r3.predicate, r3.object)
|
486
|
+
@local_node.ids_for_outbound(:has_part).should == [@local_node2.pid]
|
487
|
+
@local_node.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
488
|
+
@local_node2.ids_for_outbound(:has_part).should == [@local_node.pid]
|
489
|
+
@local_node2.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
490
|
+
@local_node.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[r2.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
491
|
+
@local_node2.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[r3.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
483
492
|
end
|
484
493
|
end
|
485
494
|
|
486
495
|
describe ".add_relationship" do
|
487
496
|
it "should add relationship to the relationships hash" do
|
488
|
-
@node.
|
489
|
-
@node.
|
490
|
-
@node.
|
491
|
-
@node.relationships[@test_relationship.subject][@test_relationship.predicate].should include(@test_relationship.object)
|
497
|
+
@node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
|
498
|
+
@node.add_relationship(@test_relationship.predicate, @test_relationship.object)
|
499
|
+
@node.ids_for_outbound("isMemberOf").should == ['demo:9']
|
492
500
|
end
|
493
501
|
|
494
502
|
it "adding relationship to an instance should not affect class-level relationships hash" do
|
495
503
|
local_test_node1 = SpecNode.new
|
496
504
|
local_test_node2 = SpecNode.new
|
497
|
-
local_test_node1.
|
498
|
-
|
505
|
+
local_test_node1.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
|
506
|
+
local_test_node1.add_relationship(@test_relationship1.predicate, @test_relationship1.object)
|
499
507
|
|
500
|
-
local_test_node1.
|
501
|
-
local_test_node2.
|
508
|
+
local_test_node1.ids_for_outbound(:is_member_of).should == ["demo:10"]
|
509
|
+
local_test_node2.ids_for_outbound(:is_member_of).should == []
|
502
510
|
end
|
503
511
|
|
504
512
|
end
|
@@ -518,12 +526,10 @@ describe ActiveFedora::SemanticNode do
|
|
518
526
|
|
519
527
|
describe '.register_triple' do
|
520
528
|
it 'should add triples to the relationships hash' do
|
521
|
-
@node.register_triple(
|
522
|
-
@node.register_triple(
|
523
|
-
@node.
|
524
|
-
@node.
|
525
|
-
@node.relationships[:self][:is_part_of].should include("info:fedora/demo:10")
|
526
|
-
@node.relationships[:self][:is_member_of].should include("info:fedora/demo:11")
|
529
|
+
@node.register_triple(@node.internal_uri, :is_part_of, "info:fedora/demo:10")
|
530
|
+
@node.register_triple(@node.internal_uri, :is_member_of, "info:fedora/demo:11")
|
531
|
+
@node.ids_for_outbound(:is_part_of).should == ['demo:10']
|
532
|
+
@node.ids_for_outbound(:is_member_of).should == ['demo:11']
|
527
533
|
end
|
528
534
|
|
529
535
|
it "should not be a class level method"
|
@@ -541,121 +547,46 @@ describe ActiveFedora::SemanticNode do
|
|
541
547
|
lambda { SpecNode.predicate_lookup(:has_foo) }.should raise_error ActiveFedora::UnregisteredPredicateError
|
542
548
|
end
|
543
549
|
|
544
|
-
it 'should provide #relationships_to_rels_ext' do
|
545
|
-
SpecNode.should respond_to(:relationships_to_rels_ext)
|
546
|
-
@node.should respond_to(:to_rels_ext)
|
547
|
-
end
|
548
|
-
|
549
|
-
describe '#relationships_to_rels_ext' do
|
550
|
-
|
551
|
-
before(:all) do
|
552
|
-
@sample_rels_ext_xml = <<-EOS
|
553
|
-
<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
|
554
|
-
<rdf:Description rdf:about='info:fedora/test:sample_pid'>
|
555
|
-
<isMemberOf rdf:resource='info:fedora/demo:10' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
556
|
-
<isPartOf rdf:resource='info:fedora/demo:11' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
557
|
-
<hasPart rdf:resource='info:fedora/demo:12' xmlns='info:fedora/fedora-system:def/relations-external#'/>
|
558
|
-
<hasModel rdf:resource='info:fedora/afmodel:OtherModel' xmlns='info:fedora/fedora-system:def/model#'/>
|
559
|
-
<hasModel rdf:resource='info:fedora/afmodel:SampleModel' xmlns='info:fedora/fedora-system:def/model#'/>
|
560
|
-
</rdf:Description>
|
561
|
-
</rdf:RDF>
|
562
|
-
EOS
|
563
|
-
end
|
564
|
-
|
565
|
-
it 'should serialize the relationships array to Fedora RELS-EXT rdf/xml' do
|
566
|
-
@node.add_relationship(@test_relationship1)
|
567
|
-
@node.add_relationship(@test_relationship2)
|
568
|
-
@node.add_relationship(@test_relationship3)
|
569
|
-
@node.add_relationship(@test_cmodel_relationship1)
|
570
|
-
@node.add_relationship(@test_cmodel_relationship2)
|
571
|
-
@node.internal_uri = @uri
|
572
|
-
# returned_xml = XmlSimple.xml_in(@node.to_rels_ext(@pid))
|
573
|
-
# returned_xml.should == XmlSimple.xml_in(@sample_rels_ext_xml)
|
574
|
-
EquivalentXml.equivalent?(@node.to_rels_ext(@pid), @sample_rels_ext_xml).should be_true
|
575
|
-
end
|
576
|
-
|
577
|
-
it "should treat :self and self.pid as equivalent subjects"
|
578
|
-
end
|
579
|
-
|
580
|
-
it 'should provide #relationships_to_rdf_xml'
|
581
|
-
|
582
|
-
describe '#relationships_to_rdf_xml' do
|
583
|
-
it 'should serialize the relationships array to rdf/xml'
|
584
|
-
end
|
585
550
|
|
586
551
|
it "should provide .outbound_relationships" do
|
587
552
|
@node.should respond_to(:outbound_relationships)
|
588
553
|
end
|
589
554
|
|
590
555
|
|
591
|
-
it 'should provide #unregister_triple' do
|
592
|
-
@test_object.should respond_to(:unregister_triple)
|
593
|
-
end
|
594
|
-
|
595
|
-
describe '#unregister_triple' do
|
596
|
-
it 'should remove a triple from the relationships hash' do
|
597
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/3"})
|
598
|
-
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/4"})
|
599
|
-
@test_object.add_relationship(r)
|
600
|
-
@test_object.add_relationship(r2)
|
601
|
-
#check both are there
|
602
|
-
@test_object.relationships.should == {:self=>{:has_part=>[r.object,r2.object]}}
|
603
|
-
@test_object.unregister_triple(r.subject,r.predicate,r.object)
|
604
|
-
#check returns false if relationship does not exist and does nothing
|
605
|
-
@test_object.unregister_triple(:self,:has_member,r2.object).should == false
|
606
|
-
#check only one item removed
|
607
|
-
@test_object.relationships.should == {:self=>{:has_part=>[r2.object]}}
|
608
|
-
@test_object.unregister_triple(r2.subject,r2.predicate,r2.object)
|
609
|
-
#check last item removed and predicate removed since now emtpy
|
610
|
-
@test_object.relationships.should == {:self=>{}}
|
611
|
-
|
612
|
-
end
|
613
|
-
end
|
614
|
-
|
615
|
-
it 'should provide #remove_relationship' do
|
616
|
-
@test_object.should respond_to(:remove_relationship)
|
617
|
-
end
|
618
|
-
|
619
556
|
describe '#remove_relationship' do
|
620
557
|
it 'should remove a relationship from the relationships hash' do
|
621
558
|
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/3"})
|
622
559
|
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/4"})
|
623
|
-
@test_object.
|
624
|
-
@test_object.add_relationship(
|
560
|
+
@test_object.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true)).times(5)
|
561
|
+
@test_object.add_relationship(r.predicate, r.object)
|
562
|
+
@test_object.add_relationship(r2.predicate, r2.object)
|
625
563
|
#check both are there
|
626
|
-
@test_object.
|
627
|
-
@test_object.remove_relationship(r)
|
564
|
+
@test_object.ids_for_outbound(:has_part).should include "3", "4"
|
565
|
+
@test_object.remove_relationship(r.predicate, r.object)
|
628
566
|
#check returns false if relationship does not exist and does nothing with different predicate
|
629
567
|
rBad = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>"info:fedora/4"})
|
630
|
-
@test_object.remove_relationship(rBad
|
568
|
+
@test_object.remove_relationship(rBad.predicate, rBad.object)
|
631
569
|
#check only one item removed
|
632
|
-
@test_object.
|
633
|
-
@test_object.remove_relationship(r2)
|
570
|
+
@test_object.ids_for_outbound(:has_part).should == ['4']
|
571
|
+
@test_object.remove_relationship(r2.predicate, r2.object)
|
634
572
|
#check last item removed and predicate removed since now emtpy
|
635
|
-
@test_object.
|
573
|
+
@test_object.ids_for_outbound(:has_part).should == []
|
636
574
|
|
637
575
|
end
|
638
576
|
end
|
639
577
|
|
640
|
-
it 'should provide #relationship_exists?' do
|
641
|
-
@test_object.should respond_to(:relationship_exists?)
|
642
|
-
end
|
643
|
-
|
644
578
|
describe '#relationship_exists?' do
|
645
579
|
it 'should return true if a relationship does exist' do
|
646
580
|
@test_object3 = SpecNode2.new
|
647
581
|
@test_object3.pid = increment_pid
|
648
582
|
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>@test_object3})
|
649
|
-
@test_object.relationship_exists?(
|
650
|
-
@test_object.
|
651
|
-
@test_object.
|
583
|
+
@test_object.relationship_exists?(@test_object.internal_uri,r.predicate,r.object).should == false
|
584
|
+
@test_object.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
|
585
|
+
@test_object.add_relationship(r.predicate, r.object)
|
586
|
+
@test_object.relationship_exists?(@test_object.internal_uri,r.predicate,r.object).should == true
|
652
587
|
end
|
653
588
|
end
|
654
589
|
|
655
|
-
it 'should provide #assert_kind_of' do
|
656
|
-
@test_object.should respond_to(:assert_kind_of)
|
657
|
-
end
|
658
|
-
|
659
590
|
describe '#assert_kind_of' do
|
660
591
|
it 'should raise an exception if object supplied is not the correct type' do
|
661
592
|
had_exception = false
|