active-fedora 3.1.0.pre13 → 3.1.0.pre14
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/lib/active_fedora/semantic_node.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_file_management_spec.rb +2 -2
- data/spec/integration/rels_ext_datastream_spec.rb +1 -1
- data/spec/unit/base_spec.rb +1 -1
- data/spec/unit/rels_ext_datastream_spec.rb +1 -1
- data/spec/unit/semantic_node_spec.rb +508 -522
- metadata +3 -3
@@ -47,7 +47,6 @@ module ActiveFedora
|
|
47
47
|
# @param target an object to store
|
48
48
|
def build_statement(uri, predicate, target)
|
49
49
|
raise "Not allowed anymore" if uri == :self
|
50
|
-
raise "Doesn't seem to be a URI(#{uri})" unless /^info/.match(uri)
|
51
50
|
target = target.internal_uri if target.respond_to? :internal_uri
|
52
51
|
subject = RDF::URI.new(uri) #TODO cache
|
53
52
|
begin
|
@@ -55,6 +54,7 @@ module ActiveFedora
|
|
55
54
|
rescue URI::InvalidURIError
|
56
55
|
literal = false
|
57
56
|
end
|
57
|
+
raise ArgumentError, "Invalid target \"#{target}\". Must have namespace." unless literal || /^info/.match(target)
|
58
58
|
object = literal ? RDF::Literal.new(target) : RDF::URI.new(target)
|
59
59
|
|
60
60
|
RDF::Statement.new(subject, find_graph_predicate(predicate), object)
|
@@ -4,7 +4,7 @@ describe ActiveFedora::Base do
|
|
4
4
|
|
5
5
|
before(:each) do
|
6
6
|
@test_container = ActiveFedora::Base.new
|
7
|
-
@test_container.add_relationship(:has_collection_member, "foo:2")
|
7
|
+
@test_container.add_relationship(:has_collection_member, "info:fedora/foo:2")
|
8
8
|
@test_container.save
|
9
9
|
end
|
10
10
|
|
@@ -17,4 +17,4 @@ describe ActiveFedora::Base do
|
|
17
17
|
container_copy.collection_members(:response_format=>:id_array).should == ["foo:2"]
|
18
18
|
end
|
19
19
|
|
20
|
-
end
|
20
|
+
end
|
@@ -78,7 +78,7 @@ describe ActiveFedora::RelsExtDatastream do
|
|
78
78
|
it "should load relationships from fedora into parent object" do
|
79
79
|
class SpecNode; include ActiveFedora::SemanticNode; end
|
80
80
|
SpecNode.predicate_mappings[SpecNode.default_predicate_namespace].each_key do |p|
|
81
|
-
@test_object.add_relationship(p, "demo:#{rand(100)}")
|
81
|
+
@test_object.add_relationship(p, "info:fedora/demo:#{rand(100)}")
|
82
82
|
end
|
83
83
|
@test_object.save
|
84
84
|
# make sure that _something_ was actually added to the object's relationships hash
|
data/spec/unit/base_spec.rb
CHANGED
@@ -520,7 +520,7 @@ describe ActiveFedora::Base do
|
|
520
520
|
end
|
521
521
|
it "should call .to_solr on the RELS-EXT datastream if it is dirty" do
|
522
522
|
@mock_repo.expects(:object).with(:pid => @this_pid).returns("")
|
523
|
-
@test_object.add_relationship(:has_collection_member, "foo
|
523
|
+
@test_object.add_relationship(:has_collection_member, "info:fedora/foo:member")
|
524
524
|
rels_ext = @test_object.rels_ext
|
525
525
|
rels_ext.dirty?.should == true
|
526
526
|
rels_ext.expects(:to_solr)
|
@@ -79,7 +79,7 @@ describe ActiveFedora::RelsExtDatastream do
|
|
79
79
|
@test_obj.delete
|
80
80
|
end
|
81
81
|
it "should handle un-mapped predicates gracefully" do
|
82
|
-
@test_obj.add_relationship("foo", "foo:bar")
|
82
|
+
@test_obj.add_relationship("foo", "info:fedora/foo:bar")
|
83
83
|
@test_obj.save
|
84
84
|
@test_obj.relationships.size.should == 5
|
85
85
|
@test_obj.ids_for_outbound("foo").should == ["foo:bar"]
|
@@ -15,600 +15,586 @@ class SpecNode2
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe ActiveFedora::SemanticNode do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
describe "build_statement" do
|
19
|
+
before do
|
20
|
+
@node = SpecNode2.new
|
21
|
+
end
|
22
|
+
it "should raise an error when the target is a pid, not a uri" do
|
23
|
+
lambda { @node.build_statement('info:fedora/spec:9', :is_part_of, 'spec:7') }.should raise_error ArgumentError
|
24
|
+
end
|
25
|
+
it "should run the happy path" do
|
26
|
+
stm = @node.build_statement('info:fedora/spec:9', :is_part_of, 'info:fedora/spec:7')
|
27
|
+
stm.object.to_s.should == "info:fedora/spec:7"
|
28
|
+
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
describe "with a bunch of objects" do
|
32
|
+
def increment_pid
|
33
|
+
@@last_pid += 1
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
36
|
+
before(:all) do
|
37
|
+
@pid = "test:sample_pid"
|
38
|
+
@uri = "info:fedora/#{@pid}"
|
39
|
+
@sample_solr_hits = [{"id"=>"_PID1_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
|
40
|
+
{"id"=>"_PID2_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
|
41
|
+
{"id"=>"_PID3_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]}]
|
43
42
|
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
|
44
|
+
before(:each) do
|
45
|
+
class SpecNode
|
46
|
+
include ActiveFedora::RelationshipsHelper
|
47
|
+
include ActiveFedora::SemanticNode
|
48
|
+
|
49
|
+
attr_accessor :pid
|
50
|
+
def initialize (params={})
|
51
|
+
self.pid = params[:pid]
|
52
|
+
end
|
53
|
+
def internal_uri
|
54
|
+
'info:fedora/' + pid.to_s
|
55
|
+
end
|
49
56
|
end
|
50
|
-
|
51
|
-
|
57
|
+
|
58
|
+
class AudioRecord
|
59
|
+
attr_accessor :pid
|
60
|
+
def initialize (params={})
|
61
|
+
self.pid = params[:pid]
|
62
|
+
end
|
63
|
+
def internal_uri
|
64
|
+
'info:fedora/' + pid.to_s
|
65
|
+
end
|
52
66
|
end
|
67
|
+
|
68
|
+
@node = SpecNode.new
|
69
|
+
@node.stubs(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>''))
|
70
|
+
@node.pid = increment_pid
|
71
|
+
@test_object = SpecNode2.new
|
72
|
+
@test_object.pid = increment_pid
|
73
|
+
@test_object.stubs(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>''))
|
74
|
+
@stub_relationship = stub("mock_relationship", :subject => @pid, :predicate => "isMemberOf", :object => "demo:8", :class => ActiveFedora::Relationship)
|
75
|
+
@test_relationship = ActiveFedora::Relationship.new(:subject => @pid, :predicate => "isMemberOf", :object => "demo:9")
|
76
|
+
@test_relationship1 = ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "demo:10")
|
77
|
+
@test_relationship2 = ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_part_of, :object => "demo:11")
|
78
|
+
@test_relationship3 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => :has_part, :object => "demo:12")
|
79
|
+
@test_cmodel_relationship1 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => :has_model, :object => "afmodel:SampleModel")
|
80
|
+
@test_cmodel_relationship2 = ActiveFedora::Relationship.new(:subject => @pid, :predicate => "hasModel", :object => "afmodel:OtherModel")
|
53
81
|
end
|
54
82
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
@test_object2.delete
|
78
|
-
rescue
|
79
|
-
end
|
80
|
-
begin
|
81
|
-
@test_object3.delete
|
82
|
-
rescue
|
83
|
+
after(:each) do
|
84
|
+
Object.send(:remove_const, :SpecNode)
|
85
|
+
begin
|
86
|
+
@test_object.delete
|
87
|
+
rescue
|
88
|
+
end
|
89
|
+
begin
|
90
|
+
@test_object2.delete
|
91
|
+
rescue
|
92
|
+
end
|
93
|
+
begin
|
94
|
+
@test_object3.delete
|
95
|
+
rescue
|
96
|
+
end
|
97
|
+
begin
|
98
|
+
@test_object4.delete
|
99
|
+
rescue
|
100
|
+
end
|
101
|
+
begin
|
102
|
+
@test_object5.delete
|
103
|
+
rescue
|
104
|
+
end
|
83
105
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
106
|
+
|
107
|
+
it 'should provide .default_predicate_namespace' do
|
108
|
+
SpecNode.should respond_to(:default_predicate_namespace)
|
109
|
+
SpecNode.default_predicate_namespace.should == 'info:fedora/fedora-system:def/relations-external#'
|
87
110
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
111
|
+
|
112
|
+
it 'should provide .predicate_mappings' do
|
113
|
+
SpecNode.should respond_to(:predicate_mappings)
|
91
114
|
end
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should provide .default_predicate_namespace' do
|
95
|
-
SpecNode.should respond_to(:default_predicate_namespace)
|
96
|
-
SpecNode.default_predicate_namespace.should == 'info:fedora/fedora-system:def/relations-external#'
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should provide .predicate_mappings' do
|
100
|
-
SpecNode.should respond_to(:predicate_mappings)
|
101
|
-
end
|
102
115
|
|
103
|
-
|
116
|
+
describe "#predicate_mappings" do
|
104
117
|
|
105
|
-
|
106
|
-
|
107
|
-
|
118
|
+
it 'should return a hash' do
|
119
|
+
SpecNode.predicate_mappings.should be_kind_of Hash
|
120
|
+
end
|
108
121
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
122
|
+
it "should provide mappings to the fedora ontology via the info:fedora/fedora-system:def/relations-external default namespace mapping" do
|
123
|
+
SpecNode.predicate_mappings.keys.include?(SpecNode.default_predicate_namespace).should be_true
|
124
|
+
SpecNode.predicate_mappings[SpecNode.default_predicate_namespace].should be_kind_of Hash
|
125
|
+
end
|
113
126
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
127
|
+
it 'should provide predicate mappings for entire Fedora Relationship Ontology' do
|
128
|
+
desired_mappings = Hash[:is_member_of => "isMemberOf",
|
129
|
+
:has_member => "hasMember",
|
130
|
+
:is_part_of => "isPartOf",
|
131
|
+
:has_part => "hasPart",
|
132
|
+
:is_member_of_collection => "isMemberOfCollection",
|
133
|
+
:has_collection_member => "hasCollectionMember",
|
134
|
+
:is_constituent_of => "isConstituentOf",
|
135
|
+
:has_constituent => "hasConstituent",
|
136
|
+
:is_subset_of => "isSubsetOf",
|
137
|
+
:has_subset => "hasSubset",
|
138
|
+
:is_derivation_of => "isDerivationOf",
|
139
|
+
:has_derivation => "hasDerivation",
|
140
|
+
:is_dependent_of => "isDependentOf",
|
141
|
+
:has_dependent => "hasDependent",
|
142
|
+
:is_description_of => "isDescriptionOf",
|
143
|
+
:has_description => "hasDescription",
|
144
|
+
:is_metadata_for => "isMetadataFor",
|
145
|
+
:has_metadata => "hasMetadata",
|
146
|
+
:is_annotation_of => "isAnnotationOf",
|
147
|
+
:has_annotation => "hasAnnotation",
|
148
|
+
:has_equivalent => "hasEquivalent",
|
149
|
+
:conforms_to => "conformsTo",
|
150
|
+
:has_model => "hasModel"]
|
151
|
+
desired_mappings.each_pair do |k,v|
|
152
|
+
SpecNode.predicate_mappings[SpecNode.default_predicate_namespace].should have_key(k)
|
153
|
+
SpecNode.predicate_mappings[SpecNode.default_predicate_namespace][k].should == v
|
154
|
+
end
|
141
155
|
end
|
142
156
|
end
|
143
|
-
end
|
144
157
|
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'should provide #has_relationship' do
|
150
|
-
SpecNode.should respond_to(:has_relationship)
|
151
|
-
SpecNode.should respond_to(:has_relationship)
|
152
|
-
end
|
153
|
-
|
154
|
-
describe '#has_relationship' do
|
155
|
-
it "should create finders based on provided relationship name" do
|
156
|
-
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
157
|
-
local_node = SpecNode.new
|
158
|
-
local_node.should respond_to(:parts_ids)
|
159
|
-
local_node.should respond_to(:parts_query)
|
160
|
-
# local_node.should respond_to(:parts)
|
161
|
-
local_node.should_not respond_to(:containers)
|
162
|
-
SpecNode.has_relationship("containers", :is_member_of)
|
163
|
-
local_node.should respond_to(:containers_ids)
|
164
|
-
local_node.should respond_to(:containers_query)
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should add a subject and predicate to the relationships array" do
|
168
|
-
SpecNode.has_relationship("parents", :is_part_of)
|
169
|
-
SpecNode.relationships.should have_key(:self)
|
170
|
-
SpecNode.relationships[:self].should have_key(:is_part_of)
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should use :inbound as the subject if :inbound => true" do
|
174
|
-
SpecNode.has_relationship("parents", :is_part_of, :inbound => true)
|
175
|
-
SpecNode.relationships.should have_key(:inbound)
|
176
|
-
SpecNode.relationships[:inbound].should have_key(:is_part_of)
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'should create inbound relationship finders' do
|
180
|
-
SpecNode.expects(:create_inbound_relationship_finders)
|
181
|
-
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
158
|
+
it 'should provide .internal_uri' do
|
159
|
+
@node.should respond_to(:internal_uri)
|
182
160
|
end
|
183
161
|
|
184
|
-
it 'should
|
185
|
-
SpecNode.
|
186
|
-
SpecNode.
|
187
|
-
SpecNode.has_relationship("container", :is_member_of)
|
162
|
+
it 'should provide #has_relationship' do
|
163
|
+
SpecNode.should respond_to(:has_relationship)
|
164
|
+
SpecNode.should respond_to(:has_relationship)
|
188
165
|
end
|
189
166
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
167
|
+
describe '#has_relationship' do
|
168
|
+
it "should create finders based on provided relationship name" do
|
169
|
+
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
170
|
+
local_node = SpecNode.new
|
171
|
+
local_node.should respond_to(:parts_ids)
|
172
|
+
local_node.should respond_to(:parts_query)
|
173
|
+
# local_node.should respond_to(:parts)
|
174
|
+
local_node.should_not respond_to(:containers)
|
175
|
+
SpecNode.has_relationship("containers", :is_member_of)
|
176
|
+
local_node.should respond_to(:containers_ids)
|
177
|
+
local_node.should respond_to(:containers_query)
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should add a subject and predicate to the relationships array" do
|
181
|
+
SpecNode.has_relationship("parents", :is_part_of)
|
182
|
+
SpecNode.relationships.should have_key(:self)
|
183
|
+
SpecNode.relationships[:self].should have_key(:is_part_of)
|
184
|
+
end
|
194
185
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
186
|
+
it "should use :inbound as the subject if :inbound => true" do
|
187
|
+
SpecNode.has_relationship("parents", :is_part_of, :inbound => true)
|
188
|
+
SpecNode.relationships.should have_key(:inbound)
|
189
|
+
SpecNode.relationships[:inbound].should have_key(:is_part_of)
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should create inbound relationship finders' do
|
193
|
+
SpecNode.expects(:create_inbound_relationship_finders)
|
194
|
+
SpecNode.has_relationship("parts", :is_part_of, :inbound => true)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'should create outbound relationship finders' do
|
198
|
+
SpecNode.expects(:create_outbound_relationship_finders).times(2)
|
199
|
+
SpecNode.has_relationship("parts", :is_part_of, :inbound => false)
|
200
|
+
SpecNode.has_relationship("container", :is_member_of)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should create outbound relationship finders that return an array of fedora PIDs" do
|
204
|
+
SpecNode.has_relationship("containers", :is_member_of, :inbound => false)
|
205
|
+
local_node = SpecNode.new
|
206
|
+
local_node.internal_uri = "info:fedora/#{@pid}"
|
207
|
+
|
208
|
+
# local_node.add_relationship(ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/container:A") )
|
209
|
+
# local_node.add_relationship(ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/container:B") )
|
210
|
+
local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
211
|
+
local_node.add_relationship(:is_member_of, "info:fedora/container:A")
|
212
|
+
local_node.add_relationship(:is_member_of, "info:fedora/container:B")
|
200
213
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
class MockHasRelationship < SpecNode2
|
208
|
-
has_relationship "testing", :has_part, :type=>SpecNode2
|
209
|
-
has_relationship "testing2", :has_member, :type=>SpecNode2
|
210
|
-
has_relationship "testing_inbound", :has_part, :type=>SpecNode2, :inbound=>true
|
211
|
-
end
|
214
|
+
containers_result = local_node.containers_ids
|
215
|
+
containers_result.should be_instance_of(Array)
|
216
|
+
containers_result.should include("container:A")
|
217
|
+
containers_result.should include("container:B")
|
218
|
+
end
|
212
219
|
|
213
|
-
|
214
|
-
|
215
|
-
class MockHasRelationshipDuplicatePredicate < SpecNode2
|
216
|
-
has_relationship "testing", :has_member, :type=>SpecNode2
|
217
|
-
had_exception = false
|
218
|
-
begin
|
220
|
+
class MockHasRelationship < SpecNode2
|
221
|
+
has_relationship "testing", :has_part, :type=>SpecNode2
|
219
222
|
has_relationship "testing2", :has_member, :type=>SpecNode2
|
220
|
-
|
221
|
-
had_exception = true
|
223
|
+
has_relationship "testing_inbound", :has_part, :type=>SpecNode2, :inbound=>true
|
222
224
|
end
|
223
|
-
|
224
|
-
|
225
|
-
=
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
225
|
+
|
226
|
+
it 'should create relationship descriptions both inbound and outbound' do
|
227
|
+
@test_object2 = MockHasRelationship.new
|
228
|
+
@test_object2.pid = increment_pid
|
229
|
+
@test_object2.stubs(:testing_inbound).returns({})
|
230
|
+
@test_object2.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content =>'')).at_least_once
|
231
|
+
@test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2))
|
232
|
+
@test_object2.should respond_to(:testing_append)
|
233
|
+
@test_object2.should respond_to(:testing_remove)
|
234
|
+
@test_object2.should respond_to(:testing2_append)
|
235
|
+
@test_object2.should respond_to(:testing2_remove)
|
236
|
+
#make sure append/remove method not created for inbound rel
|
237
|
+
@test_object2.should_not respond_to(:testing_inbound_append)
|
238
|
+
@test_object2.should_not respond_to(:testing_inbound_remove)
|
239
|
+
|
240
|
+
@test_object2.relationships_desc.should ==
|
241
|
+
{:inbound=>{"testing_inbound"=>{:type=>SpecNode2,
|
242
|
+
:predicate=>:has_part,
|
243
|
+
:inbound=>true,
|
244
|
+
:singular=>nil}},
|
245
|
+
:self=>{"testing"=>{:type=>SpecNode2,
|
246
|
+
:predicate=>:has_part,
|
247
|
+
:inbound=>false,
|
248
|
+
:singular=>nil},
|
249
|
+
"testing2"=>{:type=>SpecNode2,
|
250
|
+
:predicate=>:has_member,
|
251
|
+
:inbound=>false,
|
252
|
+
:singular=>nil}}}
|
236
253
|
end
|
237
|
-
raise "Did not raise exception if duplicate predicate used" unless had_exception
|
238
254
|
end
|
239
|
-
=end
|
240
255
|
|
241
|
-
|
242
|
-
@test_object2 = MockHasRelationship.new
|
243
|
-
@test_object2.pid = increment_pid
|
244
|
-
@test_object2.stubs(:testing_inbound).returns({})
|
245
|
-
@test_object2.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content =>'')).at_least_once
|
246
|
-
@test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode2))
|
247
|
-
@test_object2.should respond_to(:testing_append)
|
248
|
-
@test_object2.should respond_to(:testing_remove)
|
249
|
-
@test_object2.should respond_to(:testing2_append)
|
250
|
-
@test_object2.should respond_to(:testing2_remove)
|
251
|
-
#make sure append/remove method not created for inbound rel
|
252
|
-
@test_object2.should_not respond_to(:testing_inbound_append)
|
253
|
-
@test_object2.should_not respond_to(:testing_inbound_remove)
|
256
|
+
describe '#create_inbound_relationship_finders' do
|
254
257
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
:predicate=>:has_part,
|
262
|
-
:inbound=>false,
|
263
|
-
:singular=>nil},
|
264
|
-
"testing2"=>{:type=>SpecNode2,
|
265
|
-
:predicate=>:has_member,
|
266
|
-
:inbound=>false,
|
267
|
-
:singular=>nil}}}
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
describe '#create_inbound_relationship_finders' do
|
272
|
-
|
273
|
-
it 'should respond to #create_inbound_relationship_finders' do
|
274
|
-
SpecNode.should respond_to(:create_inbound_relationship_finders)
|
275
|
-
end
|
276
|
-
|
277
|
-
it "should create finders based on provided relationship name" do
|
278
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
279
|
-
local_node = SpecNode.new
|
280
|
-
local_node.should respond_to(:parts_ids)
|
281
|
-
local_node.should_not respond_to(:containers)
|
282
|
-
SpecNode.create_inbound_relationship_finders("containers", :is_member_of, :inbound => true)
|
283
|
-
local_node.should respond_to(:containers_ids)
|
284
|
-
local_node.should respond_to(:containers)
|
285
|
-
local_node.should respond_to(:containers_from_solr)
|
286
|
-
local_node.should respond_to(:containers_query)
|
287
|
-
end
|
288
|
-
|
289
|
-
it "resulting finder should search against solr and use Model#load_instance to build an array of objects" do
|
290
|
-
solr_result = (mock("solr result", :is_a? => true, :hits => @sample_solr_hits))
|
291
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
292
|
-
local_node = SpecNode.new()
|
293
|
-
local_node.expects(:pid).returns("test:sample_pid")
|
294
|
-
SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
|
295
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(solr_result)
|
296
|
-
local_node.parts.map(&:pid).should == ["_PID1_", "_PID2_", "_PID3_"]
|
297
|
-
end
|
298
|
-
|
299
|
-
it "resulting finder should accept :solr as :response_format value and return the raw Solr Result" do
|
300
|
-
solr_result = mock("solr result")
|
301
|
-
SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
|
302
|
-
local_node = SpecNode.new
|
303
|
-
mock_repo = mock("repo")
|
304
|
-
mock_repo.expects(:find_model).never
|
305
|
-
local_node.expects(:pid).returns("test:sample_pid")
|
306
|
-
SpecNode.expects(:relationships_desc).returns({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}}).at_least_once()
|
307
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid", :rows=>101).returns(solr_result)
|
308
|
-
local_node.constituents(:response_format => :solr, :rows=>101).should equal(solr_result)
|
309
|
-
end
|
310
|
-
|
311
|
-
|
312
|
-
it "resulting _ids finder should search against solr and return an array of fedora PIDs" do
|
313
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
314
|
-
local_node = SpecNode.new
|
315
|
-
local_node.expects(:pid).returns("test:sample_pid")
|
316
|
-
SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
|
317
|
-
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"]]))
|
318
|
-
local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
|
319
|
-
end
|
320
|
-
|
321
|
-
it "resulting _ids finder should call the basic finder with :result_format => :id_array" do
|
322
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
323
|
-
local_node = SpecNode.new
|
324
|
-
local_node.expects(:parts).with(:response_format => :id_array)
|
325
|
-
local_node.parts_ids
|
326
|
-
end
|
327
|
-
|
328
|
-
it "resulting _query finder should call relationship_query" do
|
329
|
-
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
330
|
-
local_node = SpecNode.new
|
331
|
-
local_node.expects(:relationship_query).with("parts")
|
332
|
-
local_node.parts_query
|
333
|
-
end
|
334
|
-
|
335
|
-
it "resulting finder should provide option of filtering results by :type"
|
336
|
-
end
|
337
|
-
|
338
|
-
describe '#create_outbound_relationship_finders' do
|
339
|
-
|
340
|
-
it 'should respond to #create_outbound_relationship_finders' do
|
341
|
-
SpecNode.should respond_to(:create_outbound_relationship_finders)
|
342
|
-
end
|
343
|
-
|
344
|
-
it "should create finders based on provided relationship name" do
|
345
|
-
SpecNode.create_outbound_relationship_finders("parts", :is_part_of)
|
346
|
-
local_node = SpecNode.new
|
347
|
-
local_node.should respond_to(:parts_ids)
|
348
|
-
#local_node.should respond_to(:parts) #.with(:type => "AudioRecord")
|
349
|
-
local_node.should_not respond_to(:containers)
|
350
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
351
|
-
local_node.should respond_to(:containers_ids)
|
352
|
-
local_node.should respond_to(:containers)
|
353
|
-
local_node.should respond_to(:containers_from_solr)
|
354
|
-
local_node.should respond_to(:containers_query)
|
355
|
-
end
|
356
|
-
|
357
|
-
describe " resulting finder" do
|
358
|
-
it "should read from relationships array and use Repository.find_model to build an array of objects" do
|
359
|
-
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
258
|
+
it 'should respond to #create_inbound_relationship_finders' do
|
259
|
+
SpecNode.should respond_to(:create_inbound_relationship_finders)
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should create finders based on provided relationship name" do
|
263
|
+
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
360
264
|
local_node = SpecNode.new
|
361
|
-
local_node.
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
ActiveFedora::SolrService.instance.conn.expects(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").returns(solr_result)
|
370
|
-
local_node.containers.map(&:pid).should == ["my:_PID1_", "my:_PID2_", "my:_PID3_"]
|
265
|
+
local_node.should respond_to(:parts_ids)
|
266
|
+
local_node.should_not respond_to(:containers)
|
267
|
+
SpecNode.create_inbound_relationship_finders("containers", :is_member_of, :inbound => true)
|
268
|
+
local_node.should respond_to(:containers_ids)
|
269
|
+
local_node.should respond_to(:containers)
|
270
|
+
local_node.should respond_to(:containers_from_solr)
|
271
|
+
local_node.should respond_to(:containers_query)
|
371
272
|
end
|
372
|
-
|
373
|
-
it "should
|
273
|
+
|
274
|
+
it "resulting finder should search against solr and use Model#load_instance to build an array of objects" do
|
275
|
+
solr_result = (mock("solr result", :is_a? => true, :hits => @sample_solr_hits))
|
276
|
+
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
277
|
+
local_node = SpecNode.new()
|
278
|
+
local_node.expects(:pid).returns("test:sample_pid")
|
279
|
+
SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
|
280
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_part_of_s:info\\:fedora/test\\:sample_pid", :rows=>25).returns(solr_result)
|
281
|
+
local_node.parts.map(&:pid).should == ["_PID1_", "_PID2_", "_PID3_"]
|
282
|
+
end
|
283
|
+
|
284
|
+
it "resulting finder should accept :solr as :response_format value and return the raw Solr Result" do
|
374
285
|
solr_result = mock("solr result")
|
375
|
-
SpecNode.
|
286
|
+
SpecNode.create_inbound_relationship_finders("constituents", :is_constituent_of, :inbound => true)
|
376
287
|
local_node = SpecNode.new
|
377
288
|
mock_repo = mock("repo")
|
378
289
|
mock_repo.expects(:find_model).never
|
379
|
-
local_node.expects(:
|
380
|
-
|
381
|
-
|
290
|
+
local_node.expects(:pid).returns("test:sample_pid")
|
291
|
+
SpecNode.expects(:relationships_desc).returns({:inbound=>{"constituents"=>{:predicate=>:is_constituent_of}}}).at_least_once()
|
292
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("is_constituent_of_s:info\\:fedora/test\\:sample_pid", :rows=>101).returns(solr_result)
|
293
|
+
local_node.constituents(:response_format => :solr, :rows=>101).should equal(solr_result)
|
382
294
|
end
|
383
295
|
|
384
|
-
|
385
|
-
|
296
|
+
|
297
|
+
it "resulting _ids finder should search against solr and return an array of fedora PIDs" do
|
298
|
+
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
386
299
|
local_node = SpecNode.new
|
387
|
-
local_node.expects(:
|
388
|
-
|
300
|
+
local_node.expects(:pid).returns("test:sample_pid")
|
301
|
+
SpecNode.expects(:relationships_desc).returns({:inbound=>{"parts"=>{:predicate=>:is_part_of}}}).at_least_once()
|
302
|
+
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"]]))
|
303
|
+
local_node.parts(:response_format => :id_array).should == ["pid1", "pid2"]
|
389
304
|
end
|
390
|
-
|
391
|
-
it "
|
392
|
-
SpecNode.
|
305
|
+
|
306
|
+
it "resulting _ids finder should call the basic finder with :result_format => :id_array" do
|
307
|
+
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
393
308
|
local_node = SpecNode.new
|
394
|
-
local_node.expects(:
|
395
|
-
local_node.
|
396
|
-
|
397
|
-
|
398
|
-
|
309
|
+
local_node.expects(:parts).with(:response_format => :id_array)
|
310
|
+
local_node.parts_ids
|
311
|
+
end
|
312
|
+
|
313
|
+
it "resulting _query finder should call relationship_query" do
|
314
|
+
SpecNode.create_inbound_relationship_finders("parts", :is_part_of, :inbound => true)
|
315
|
+
local_node = SpecNode.new
|
316
|
+
local_node.expects(:relationship_query).with("parts")
|
317
|
+
local_node.parts_query
|
399
318
|
end
|
400
319
|
|
401
|
-
it "should provide option of filtering results by :type"
|
320
|
+
it "resulting finder should provide option of filtering results by :type"
|
402
321
|
end
|
403
322
|
|
404
|
-
describe
|
405
|
-
|
323
|
+
describe '#create_outbound_relationship_finders' do
|
324
|
+
|
325
|
+
it 'should respond to #create_outbound_relationship_finders' do
|
326
|
+
SpecNode.should respond_to(:create_outbound_relationship_finders)
|
327
|
+
end
|
328
|
+
|
329
|
+
it "should create finders based on provided relationship name" do
|
406
330
|
SpecNode.create_outbound_relationship_finders("parts", :is_part_of)
|
407
331
|
local_node = SpecNode.new
|
408
|
-
local_node.
|
409
|
-
local_node.
|
332
|
+
local_node.should respond_to(:parts_ids)
|
333
|
+
#local_node.should respond_to(:parts) #.with(:type => "AudioRecord")
|
334
|
+
local_node.should_not respond_to(:containers)
|
335
|
+
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
336
|
+
local_node.should respond_to(:containers_ids)
|
337
|
+
local_node.should respond_to(:containers)
|
338
|
+
local_node.should respond_to(:containers_from_solr)
|
339
|
+
local_node.should respond_to(:containers_query)
|
410
340
|
end
|
411
|
-
|
341
|
+
|
342
|
+
describe " resulting finder" do
|
343
|
+
it "should read from relationships array and use Repository.find_model to build an array of objects" do
|
344
|
+
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
345
|
+
local_node = SpecNode.new
|
346
|
+
local_node.expects(:ids_for_outbound).with(:is_member_of).returns(["my:_PID1_", "my:_PID2_", "my:_PID3_"])
|
347
|
+
mock_repo = mock("repo")
|
348
|
+
solr_result = mock("solr result", :is_a? => true)
|
349
|
+
solr_result.expects(:hits).returns(
|
350
|
+
[{"id"=> "my:_PID1_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
|
351
|
+
{"id"=> "my:_PID2_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
|
352
|
+
{"id"=> "my:_PID3_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]}])
|
412
353
|
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
354
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").returns(solr_result)
|
355
|
+
local_node.containers.map(&:pid).should == ["my:_PID1_", "my:_PID2_", "my:_PID3_"]
|
356
|
+
end
|
357
|
+
|
358
|
+
it "should accept :solr as :response_format value and return the raw Solr Result" do
|
359
|
+
solr_result = mock("solr result")
|
360
|
+
SpecNode.create_outbound_relationship_finders("constituents", :is_constituent_of)
|
361
|
+
local_node = SpecNode.new
|
362
|
+
mock_repo = mock("repo")
|
363
|
+
mock_repo.expects(:find_model).never
|
364
|
+
local_node.expects(:rels_ext).returns(stub('rels-ext', :content=>''))
|
365
|
+
ActiveFedora::SolrService.instance.conn.expects(:query).returns(solr_result)
|
366
|
+
local_node.constituents(:response_format => :solr).should equal(solr_result)
|
367
|
+
end
|
368
|
+
|
369
|
+
it "(:response_format => :id_array) should read from relationships array" do
|
370
|
+
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
371
|
+
local_node = SpecNode.new
|
372
|
+
local_node.expects(:ids_for_outbound).with(:is_member_of).returns([])
|
373
|
+
local_node.containers_ids
|
374
|
+
end
|
375
|
+
|
376
|
+
it "(:response_format => :id_array) should return an array of fedora PIDs" do
|
377
|
+
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
378
|
+
local_node = SpecNode.new
|
379
|
+
local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
380
|
+
local_node.add_relationship(@test_relationship1.predicate, @test_relationship1.object)
|
381
|
+
result = local_node.containers_ids
|
382
|
+
result.should be_instance_of(Array)
|
383
|
+
result.should include("demo:10")
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should provide option of filtering results by :type"
|
387
|
+
end
|
388
|
+
|
389
|
+
describe " resulting _ids finder" do
|
390
|
+
it "should call the basic finder with :result_format => :id_array" do
|
391
|
+
SpecNode.create_outbound_relationship_finders("parts", :is_part_of)
|
392
|
+
local_node = SpecNode.new
|
393
|
+
local_node.expects(:parts).with(:response_format => :id_array)
|
394
|
+
local_node.parts_ids
|
395
|
+
end
|
396
|
+
end
|
450
397
|
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
@local_node.relationship_names.include?("all_parts_inbound").should == true
|
458
|
-
@local_node.relationship_names.include?("all_parts_outbound").should == true
|
398
|
+
it "resulting _query finder should call relationship_query" do
|
399
|
+
SpecNode.create_outbound_relationship_finders("containers", :is_member_of)
|
400
|
+
local_node = SpecNode.new
|
401
|
+
local_node.expects(:relationship_query).with("containers")
|
402
|
+
local_node.containers_query
|
403
|
+
end
|
459
404
|
end
|
405
|
+
|
406
|
+
describe ".create_bidirectional_relationship_finder" do
|
407
|
+
before(:each) do
|
408
|
+
SpecNode.create_bidirectional_relationship_finders("all_parts", :has_part, :is_part_of)
|
409
|
+
@local_node = SpecNode.new
|
410
|
+
@local_node.pid = @pid
|
411
|
+
@local_node.internal_uri = @uri
|
412
|
+
end
|
413
|
+
it "should create inbound & outbound finders" do
|
414
|
+
@local_node.should respond_to(:all_parts_inbound)
|
415
|
+
@local_node.should respond_to(:all_parts_outbound)
|
416
|
+
end
|
417
|
+
it "should rely on inbound & outbound finders" do
|
418
|
+
@local_node.expects(:all_parts_inbound).with(:rows => 25).returns(["foo1"])
|
419
|
+
@local_node.expects(:all_parts_outbound).with(:rows => 25).returns(["foo2"])
|
420
|
+
@local_node.all_parts.should == ["foo1", "foo2"]
|
421
|
+
end
|
422
|
+
it "(:response_format => :id_array) should rely on inbound & outbound finders" do
|
423
|
+
@local_node.expects(:all_parts_inbound).with(:response_format=>:id_array, :rows => 34).returns(["fooA"])
|
424
|
+
@local_node.expects(:all_parts_outbound).with(:response_format=>:id_array, :rows => 34).returns(["fooB"])
|
425
|
+
@local_node.all_parts(:response_format=>:id_array, :rows => 34).should == ["fooA", "fooB"]
|
426
|
+
end
|
427
|
+
it "(:response_format => :solr) should construct a solr query that combines inbound and outbound searches" do
|
428
|
+
# get the id array for outbound relationships then construct solr query by combining id array with inbound relationship search
|
429
|
+
@local_node.expects(:ids_for_outbound).with(:has_part).returns(["mypid:1"])
|
430
|
+
id_array_query = ActiveFedora::SolrService.construct_query_for_pids(["mypid:1"])
|
431
|
+
solr_result = mock("solr result")
|
432
|
+
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)
|
433
|
+
@local_node.all_parts(:response_format=>:solr)
|
434
|
+
end
|
460
435
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
436
|
+
it "should register both inbound and outbound predicate components" do
|
437
|
+
@local_node.class.relationships[:inbound].has_key?(:is_part_of).should == true
|
438
|
+
@local_node.class.relationships[:self].has_key?(:has_part).should == true
|
439
|
+
end
|
440
|
+
|
441
|
+
it "should register relationship names for inbound, outbound" do
|
442
|
+
@local_node.relationship_names.include?("all_parts_inbound").should == true
|
443
|
+
@local_node.relationship_names.include?("all_parts_outbound").should == true
|
444
|
+
end
|
467
445
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
end
|
475
|
-
|
476
|
-
describe "#has_bidirectional_relationship" do
|
477
|
-
it "should ..." do
|
478
|
-
SpecNode.expects(:create_bidirectional_relationship_finders).with("all_parts", :has_part, :is_part_of, {})
|
479
|
-
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
480
|
-
end
|
446
|
+
it "should register finder methods for the bidirectional relationship name" do
|
447
|
+
@local_node.should respond_to(:all_parts)
|
448
|
+
@local_node.should respond_to(:all_parts_ids)
|
449
|
+
@local_node.should respond_to(:all_parts_query)
|
450
|
+
@local_node.should respond_to(:all_parts_from_solr)
|
451
|
+
end
|
481
452
|
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode)})
|
489
|
-
@local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
490
|
-
@local_node.add_relationship(r.predicate, r.object)
|
491
|
-
@local_node2.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
492
|
-
@local_node2.add_relationship(r.predicate, r.object)
|
493
|
-
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@local_node2})
|
494
|
-
@local_node.add_relationship(r2.predicate, r2.object)
|
495
|
-
r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@local_node})
|
496
|
-
@local_node2.add_relationship(r3.predicate, r3.object)
|
497
|
-
@local_node.ids_for_outbound(:has_part).should == [@local_node2.pid]
|
498
|
-
@local_node.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
499
|
-
@local_node2.ids_for_outbound(:has_part).should == [@local_node.pid]
|
500
|
-
@local_node2.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
501
|
-
@local_node.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[r2.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
502
|
-
@local_node2.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[r3.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
453
|
+
it "resulting _query finder should call relationship_query" do
|
454
|
+
SpecNode.create_bidirectional_relationship_finders("containers", :is_member_of, :has_member)
|
455
|
+
local_node = SpecNode.new
|
456
|
+
local_node.expects(:relationship_query).with("containers")
|
457
|
+
local_node.containers_query
|
458
|
+
end
|
503
459
|
end
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
460
|
+
|
461
|
+
describe "#has_bidirectional_relationship" do
|
462
|
+
it "should ..." do
|
463
|
+
SpecNode.expects(:create_bidirectional_relationship_finders).with("all_parts", :has_part, :is_part_of, {})
|
464
|
+
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
465
|
+
end
|
466
|
+
|
467
|
+
it "should have relationships_by_name and relationships hashes contain bidirectionally related objects" do
|
468
|
+
SpecNode.has_bidirectional_relationship("all_parts", :has_part, :is_part_of)
|
469
|
+
@local_node = SpecNode.new
|
470
|
+
@local_node.pid = "mypid1"
|
471
|
+
@local_node2 = SpecNode.new
|
472
|
+
@local_node2.pid = "mypid2"
|
473
|
+
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_model,:object=>ActiveFedora::ContentModel.pid_from_ruby_class(SpecNode)})
|
474
|
+
@local_node.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
475
|
+
@local_node.add_relationship(r.predicate, r.object)
|
476
|
+
@local_node2.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
477
|
+
@local_node2.add_relationship(r.predicate, r.object)
|
478
|
+
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@local_node2})
|
479
|
+
@local_node.add_relationship(r2.predicate, r2.object)
|
480
|
+
r3 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>@local_node})
|
481
|
+
@local_node2.add_relationship(r3.predicate, r3.object)
|
482
|
+
@local_node.ids_for_outbound(:has_part).should == [@local_node2.pid]
|
483
|
+
@local_node.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
484
|
+
@local_node2.ids_for_outbound(:has_part).should == [@local_node.pid]
|
485
|
+
@local_node2.ids_for_outbound(:has_model).should == ['afmodel:SpecNode']
|
486
|
+
@local_node.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[r2.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
487
|
+
@local_node2.relationships_by_name(false).should == {:self=>{"all_parts_outbound"=>[r3.object]},:inbound=>{"all_parts_inbound"=>[]}}
|
488
|
+
end
|
510
489
|
end
|
511
490
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
491
|
+
describe ".add_relationship" do
|
492
|
+
it "should add relationship to the relationships hash" do
|
493
|
+
@node.add_relationship(@test_relationship.predicate, @test_relationship.object)
|
494
|
+
@node.ids_for_outbound("isMemberOf").should == ['demo:9']
|
495
|
+
end
|
496
|
+
|
497
|
+
it "adding relationship to an instance should not affect class-level relationships hash" do
|
498
|
+
local_test_node1 = SpecNode.new
|
499
|
+
local_test_node2 = SpecNode.new
|
500
|
+
local_test_node1.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).at_least_once
|
501
|
+
local_test_node1.add_relationship(@test_relationship1.predicate, @test_relationship1.object)
|
502
|
+
local_test_node2.expects(:rels_ext).returns(stub('rels-ext', :content=>''))
|
503
|
+
|
504
|
+
local_test_node1.ids_for_outbound(:is_member_of).should == ["demo:10"]
|
505
|
+
local_test_node2.ids_for_outbound(:is_member_of).should == []
|
506
|
+
end
|
518
507
|
|
519
|
-
local_test_node1.ids_for_outbound(:is_member_of).should == ["demo:10"]
|
520
|
-
local_test_node2.ids_for_outbound(:is_member_of).should == []
|
521
508
|
end
|
522
509
|
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
SpecNode.relationships.class.should == Hash
|
529
|
-
end
|
510
|
+
describe '#relationships' do
|
511
|
+
|
512
|
+
it "should return a hash" do
|
513
|
+
SpecNode.relationships.class.should == Hash
|
514
|
+
end
|
530
515
|
|
531
|
-
|
516
|
+
end
|
532
517
|
|
533
|
-
|
534
|
-
it "should provide a relationship setter"
|
535
|
-
it "should provide a relationship getter"
|
536
|
-
it "should provide a relationship deleter"
|
537
518
|
|
538
|
-
|
539
|
-
it
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
519
|
+
it "should provide a relationship setter"
|
520
|
+
it "should provide a relationship getter"
|
521
|
+
it "should provide a relationship deleter"
|
522
|
+
|
523
|
+
describe '.register_triple' do
|
524
|
+
it 'should add triples to the relationships hash' do
|
525
|
+
@node.register_triple(@node.internal_uri, :is_part_of, "info:fedora/demo:10")
|
526
|
+
@node.register_triple(@node.internal_uri, :is_member_of, "info:fedora/demo:11")
|
527
|
+
@node.ids_for_outbound(:is_part_of).should == ['demo:10']
|
528
|
+
@node.ids_for_outbound(:is_member_of).should == ['demo:11']
|
529
|
+
end
|
530
|
+
|
531
|
+
it "should not be a class level method"
|
544
532
|
end
|
545
533
|
|
546
|
-
it
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
it "should provide .outbound_relationships" do
|
563
|
-
@node.should respond_to(:outbound_relationships)
|
564
|
-
end
|
565
|
-
|
534
|
+
it 'should provide #predicate_lookup that maps symbols to common RELS-EXT predicates' do
|
535
|
+
SpecNode.should respond_to(:predicate_lookup)
|
536
|
+
SpecNode.predicate_lookup(:is_part_of).should == "isPartOf"
|
537
|
+
SpecNode.predicate_lookup(:is_member_of).should == "isMemberOf"
|
538
|
+
SpecNode.predicate_lookup("isPartOfCollection").should == "isPartOfCollection"
|
539
|
+
SpecNode.predicate_config[:predicate_mapping].merge!({"some_namespace"=>{:has_foo=>"hasFOO"}})
|
540
|
+
SpecNode.find_predicate(:has_foo).should == ["hasFOO","some_namespace"]
|
541
|
+
SpecNode.predicate_lookup(:has_foo,"some_namespace").should == "hasFOO"
|
542
|
+
#SpecNode.predicate_lookup(:has_foo)
|
543
|
+
lambda { SpecNode.predicate_lookup(:has_foo) }.should raise_error ActiveFedora::UnregisteredPredicateError
|
544
|
+
end
|
545
|
+
|
546
|
+
|
547
|
+
it "should provide .outbound_relationships" do
|
548
|
+
@node.should respond_to(:outbound_relationships)
|
549
|
+
end
|
566
550
|
|
567
|
-
describe '#remove_relationship' do
|
568
|
-
it 'should remove a relationship from the relationships hash' do
|
569
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/3"})
|
570
|
-
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/4"})
|
571
|
-
@test_object.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).times(6)
|
572
|
-
@test_object.add_relationship(r.predicate, r.object)
|
573
|
-
@test_object.add_relationship(r2.predicate, r2.object)
|
574
|
-
#check both are there
|
575
|
-
@test_object.ids_for_outbound(:has_part).should include "3", "4"
|
576
|
-
@test_object.remove_relationship(r.predicate, r.object)
|
577
|
-
#check returns false if relationship does not exist and does nothing with different predicate
|
578
|
-
rBad = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>"info:fedora/4"})
|
579
|
-
@test_object.remove_relationship(rBad.predicate, rBad.object)
|
580
|
-
#check only one item removed
|
581
|
-
@test_object.ids_for_outbound(:has_part).should == ['4']
|
582
|
-
@test_object.remove_relationship(r2.predicate, r2.object)
|
583
|
-
#check last item removed and predicate removed since now emtpy
|
584
|
-
@test_object.ids_for_outbound(:has_part).should == []
|
585
551
|
|
552
|
+
describe '#remove_relationship' do
|
553
|
+
it 'should remove a relationship from the relationships hash' do
|
554
|
+
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/3"})
|
555
|
+
r2 = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_part,:object=>"info:fedora/4"})
|
556
|
+
@test_object.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true, :content=>'')).times(6)
|
557
|
+
@test_object.add_relationship(r.predicate, r.object)
|
558
|
+
@test_object.add_relationship(r2.predicate, r2.object)
|
559
|
+
#check both are there
|
560
|
+
@test_object.ids_for_outbound(:has_part).should include "3", "4"
|
561
|
+
@test_object.remove_relationship(r.predicate, r.object)
|
562
|
+
#check returns false if relationship does not exist and does nothing with different predicate
|
563
|
+
rBad = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>"info:fedora/4"})
|
564
|
+
@test_object.remove_relationship(rBad.predicate, rBad.object)
|
565
|
+
#check only one item removed
|
566
|
+
@test_object.ids_for_outbound(:has_part).should == ['4']
|
567
|
+
@test_object.remove_relationship(r2.predicate, r2.object)
|
568
|
+
#check last item removed and predicate removed since now emtpy
|
569
|
+
@test_object.ids_for_outbound(:has_part).should == []
|
570
|
+
|
571
|
+
end
|
586
572
|
end
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
573
|
+
|
574
|
+
describe '#relationship_exists?' do
|
575
|
+
it 'should return true if a relationship does exist' do
|
576
|
+
@test_object3 = SpecNode2.new
|
577
|
+
@test_object3.pid = increment_pid
|
578
|
+
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>@test_object3})
|
579
|
+
@test_object.relationship_exists?(@test_object.internal_uri,r.predicate,r.object).should == false
|
580
|
+
@test_object.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
|
581
|
+
@test_object.add_relationship(r.predicate, r.object)
|
582
|
+
@test_object.relationship_exists?(@test_object.internal_uri,r.predicate,r.object).should == true
|
583
|
+
end
|
598
584
|
end
|
599
|
-
end
|
600
585
|
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
586
|
+
describe '#assert_kind_of' do
|
587
|
+
it 'should raise an exception if object supplied is not the correct type' do
|
588
|
+
had_exception = false
|
589
|
+
begin
|
590
|
+
@test_object.assert_kind_of 'SpecNode2', @test_object, ActiveFedora::Base
|
591
|
+
rescue
|
592
|
+
had_exception = true
|
593
|
+
end
|
594
|
+
raise "Failed to throw exception with kind of mismatch" unless had_exception
|
595
|
+
#now should not throw any exception
|
596
|
+
@test_object.assert_kind_of 'SpecNode2', @test_object, SpecNode2
|
608
597
|
end
|
609
|
-
raise "Failed to throw exception with kind of mismatch" unless had_exception
|
610
|
-
#now should not throw any exception
|
611
|
-
@test_object.assert_kind_of 'SpecNode2', @test_object, SpecNode2
|
612
598
|
end
|
613
599
|
end
|
614
600
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 1923832005
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 3
|
8
8
|
- 1
|
9
9
|
- 0
|
10
10
|
- pre
|
11
|
-
-
|
12
|
-
version: 3.1.0.
|
11
|
+
- 14
|
12
|
+
version: 3.1.0.pre14
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Matt Zumwalt
|