active-fedora 7.0.0.rc2 → 7.0.0.rc3
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.
- checksums.yaml +4 -4
- data/.travis.yml +13 -3
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +2 -3
- data/active-fedora.gemspec +4 -3
- data/gemfiles/rails3.gemfile +1 -7
- data/gemfiles/rails4.1.gemfile +5 -0
- data/gemfiles/rails4.gemfile +1 -6
- data/lib/active_fedora.rb +6 -6
- data/lib/active_fedora/associations/association_scope.rb +1 -1
- data/lib/active_fedora/base.rb +2 -0
- data/lib/active_fedora/datastream.rb +29 -2
- data/lib/active_fedora/datastream_collections.rb +2 -2
- data/lib/active_fedora/datastream_hash.rb +1 -1
- data/lib/active_fedora/datastreams.rb +4 -23
- data/lib/active_fedora/file_configurator.rb +8 -7
- data/lib/active_fedora/om_datastream.rb +1 -1
- data/lib/active_fedora/rdf.rb +9 -0
- data/lib/active_fedora/rdf/configurable.rb +59 -0
- data/lib/active_fedora/rdf/identifiable.rb +59 -0
- data/lib/active_fedora/rdf/indexing.rb +24 -23
- data/lib/active_fedora/rdf/list.rb +154 -0
- data/lib/active_fedora/{ntriples_rdf_datastream.rb → rdf/ntriples_rdf_datastream.rb} +0 -0
- data/lib/active_fedora/rdf/object_resource.rb +20 -0
- data/lib/active_fedora/rdf/properties.rb +108 -0
- data/lib/active_fedora/rdf/rdf_datastream.rb +113 -0
- data/lib/active_fedora/{rdfxml_rdf_datastream.rb → rdf/rdfxml_rdf_datastream.rb} +0 -0
- data/lib/active_fedora/rdf/repositories.rb +36 -0
- data/lib/active_fedora/rdf/resource.rb +324 -0
- data/lib/active_fedora/rdf/term.rb +188 -0
- data/lib/active_fedora/relation.rb +1 -0
- data/lib/active_fedora/relation/finder_methods.rb +16 -17
- data/lib/active_fedora/relation/merger.rb +1 -1
- data/lib/active_fedora/relation/query_methods.rb +13 -5
- data/lib/active_fedora/reload_on_save.rb +16 -0
- data/lib/active_fedora/rubydora_connection.rb +0 -1
- data/lib/active_fedora/sharding.rb +1 -1
- data/lib/active_fedora/version.rb +1 -1
- data/script/console +10 -11
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/solr_rdf_descMetadata.nt +1 -1
- data/spec/integration/auditable_spec.rb +1 -1
- data/spec/integration/base_spec.rb +21 -3
- data/spec/integration/complex_rdf_datastream_spec.rb +32 -55
- data/spec/integration/field_to_solr_name_spec.rb +6 -8
- data/spec/integration/has_many_associations_spec.rb +10 -3
- data/spec/integration/load_from_solr_spec.rb +15 -17
- data/spec/integration/ntriples_datastream_spec.rb +19 -23
- data/spec/integration/om_datastream_spec.rb +1 -1
- data/spec/integration/rdf_nested_attributes_spec.rb +51 -70
- data/spec/integration/relation_spec.rb +24 -11
- data/spec/integration/scoped_query_spec.rb +5 -1
- data/spec/samples/hydra-mods_article_datastream.rb +4 -0
- data/spec/samples/hydra-rights_metadata_datastream.rb +5 -0
- data/spec/samples/marpa-dc_datastream.rb +6 -1
- data/spec/samples/special_thing.rb +5 -5
- data/spec/spec_helper.rb +0 -3
- data/spec/support/an_active_model.rb +5 -12
- data/spec/unit/active_fedora_spec.rb +2 -2
- data/spec/unit/attributes_spec.rb +4 -8
- data/spec/unit/base_datastream_management_spec.rb +5 -29
- data/spec/unit/base_spec.rb +4 -0
- data/spec/unit/code_configurator_spec.rb +2 -2
- data/spec/unit/config_spec.rb +2 -2
- data/spec/unit/core_spec.rb +2 -4
- data/spec/unit/datastream_spec.rb +15 -0
- data/spec/unit/datastreams_spec.rb +1 -12
- data/spec/unit/file_configurator_spec.rb +1 -1
- data/spec/unit/ntriples_datastream_spec.rb +52 -57
- data/spec/unit/om_datastream_spec.rb +3 -3
- data/spec/unit/query_spec.rb +3 -4
- data/spec/unit/rdf_configurable_spec.rb +37 -0
- data/spec/unit/rdf_datastream_spec.rb +5 -7
- data/spec/unit/rdf_list_nested_attributes_spec.rb +22 -36
- data/spec/unit/rdf_list_spec.rb +26 -38
- data/spec/unit/rdf_properties_spec.rb +70 -0
- data/spec/unit/rdf_repositories_spec.rb +28 -0
- data/spec/unit/rdf_resource_datastream_spec.rb +287 -0
- data/spec/unit/rdf_resource_spec.rb +341 -0
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +10 -26
- data/spec/unit/reload_on_save_spec.rb +24 -0
- data/spec/unit/solr_service_spec.rb +3 -3
- metadata +45 -16
- data/lib/active_fedora/rdf_datastream.rb +0 -113
- data/lib/active_fedora/rdf_list.rb +0 -162
- data/lib/active_fedora/rdf_node.rb +0 -332
- data/lib/active_fedora/rdf_node/term_proxy.rb +0 -141
- data/lib/active_fedora/rdf_object.rb +0 -24
- data/lib/active_fedora/yaml_adaptor.rb +0 -12
- data/spec/unit/rdf_node_spec.rb +0 -36
@@ -0,0 +1,287 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::RDFDatastream do
|
4
|
+
before do
|
5
|
+
class DummySubnode < ActiveFedora::Rdf::Resource
|
6
|
+
property :title, :predicate => RDF::DC[:title], :class_name => RDF::Literal
|
7
|
+
property :relation, :predicate => RDF::DC[:relation]
|
8
|
+
end
|
9
|
+
|
10
|
+
class DummyAsset < ActiveFedora::Base; end;
|
11
|
+
|
12
|
+
class DummyResource < ActiveFedora::RDFDatastream
|
13
|
+
property :title, :predicate => RDF::DC[:title], :class_name => RDF::Literal do |index|
|
14
|
+
index.as :searchable, :displayable
|
15
|
+
end
|
16
|
+
property :license, :predicate => RDF::DC[:license], :class_name => DummySubnode do |index|
|
17
|
+
index.as :searchable, :displayable
|
18
|
+
end
|
19
|
+
property :creator, :predicate => RDF::DC[:creator], :class_name => DummyAsset do |index|
|
20
|
+
index.as :searchable
|
21
|
+
end
|
22
|
+
def serialization_format
|
23
|
+
:ntriples
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class DummyAsset < ActiveFedora::Base
|
28
|
+
has_metadata :name => 'descMetadata', :type => DummyResource
|
29
|
+
has_attributes :title, datastream: 'descMetadata', multiple: true
|
30
|
+
has_attributes :license, :datastream => 'descMetadata', :multiple => true
|
31
|
+
has_attributes :relation, :datastream => 'descMetadata', :at => [:license, :relation], :multiple => false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
after do
|
36
|
+
Object.send(:remove_const, "DummyAsset") if Object
|
37
|
+
Object.send(:remove_const, "DummyResource") if Object
|
38
|
+
Object.send(:remove_const, "DummySubnode") if Object
|
39
|
+
end
|
40
|
+
|
41
|
+
subject {DummyAsset.new}
|
42
|
+
|
43
|
+
describe "#to_solr" do
|
44
|
+
before do
|
45
|
+
subject.descMetadata.title = "bla"
|
46
|
+
subject.descMetadata.license = DummySubnode.new('http://example.org/blah')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should not be blank" do
|
50
|
+
expect(subject.to_solr).not_to be_blank
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should solrize" do
|
54
|
+
expect(subject.to_solr["desc_metadata__title_teim"]).to eq ["bla"]
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should solrize uris" do
|
58
|
+
expect(subject.to_solr["desc_metadata__license_teim"]).to eq ['http://example.org/blah']
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "delegation" do
|
63
|
+
it "should retrieve values" do
|
64
|
+
subject.descMetadata.title = "bla"
|
65
|
+
expect(subject.title).to eq ["bla"]
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should set values" do
|
69
|
+
subject.title = "blah"
|
70
|
+
expect(subject.descMetadata.title).to eq ["blah"]
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when the delegation is deep" do
|
74
|
+
before(:each) do
|
75
|
+
dummy = DummySubnode.new
|
76
|
+
dummy.relation = 'subbla'
|
77
|
+
subject.descMetadata.license = dummy
|
78
|
+
end
|
79
|
+
|
80
|
+
# This test is pending. For now we have no use case for deep delegation into an RDF graph.
|
81
|
+
xit "should retrieve values" do
|
82
|
+
expect(subject.relation).to eq ["subbla"]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "attribute setting" do
|
88
|
+
context "on text attributes" do
|
89
|
+
before do
|
90
|
+
subject.descMetadata.title = "bla"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should let you access" do
|
94
|
+
expect(subject.descMetadata.title).to eq ["bla"]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should mark it as changed" do
|
98
|
+
expect(subject.descMetadata).to be_changed
|
99
|
+
end
|
100
|
+
|
101
|
+
context "after it is persisted" do
|
102
|
+
before do
|
103
|
+
subject.save
|
104
|
+
subject.reload
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should be persisted" do
|
108
|
+
expect(subject.descMetadata.resource.persisted?).to be_true
|
109
|
+
end
|
110
|
+
|
111
|
+
context "and it's reloaded" do
|
112
|
+
before do
|
113
|
+
subject.reload
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should be accessible after being saved" do
|
117
|
+
expect(subject.descMetadata.title).to eq ["bla"]
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should serialize to content" do
|
121
|
+
expect(subject.descMetadata.content).not_to be_blank
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "and it is found again" do
|
126
|
+
before do
|
127
|
+
@object = DummyAsset.find(subject.pid)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should serialize to content" do
|
131
|
+
expect(@object.descMetadata.content).not_to be_blank
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should be accessible after being saved" do
|
135
|
+
expect(@object.descMetadata.title).to eq ["bla"]
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should have datastream content" do
|
139
|
+
expect(@object.descMetadata.datastream_content).not_to be_blank
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "on rdf resource attributes" do
|
146
|
+
context "persisted to parent" do
|
147
|
+
before do
|
148
|
+
dummy = DummySubnode.new
|
149
|
+
dummy.title = 'subbla'
|
150
|
+
subject.descMetadata.license = dummy
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should let you access" do
|
154
|
+
expect(subject.descMetadata.license.first.title).to eq ['subbla']
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should mark it as changed" do
|
158
|
+
expect(subject.descMetadata).to be_changed
|
159
|
+
end
|
160
|
+
end
|
161
|
+
context "persisted to repository" do
|
162
|
+
before do
|
163
|
+
DummySubnode.configure :repository => :default
|
164
|
+
DummySubnode.any_instance.stub(:repository).and_return(RDF::Repository.new)
|
165
|
+
dummy = DummySubnode.new(RDF::URI('http://example.org/dummy/blah'))
|
166
|
+
dummy.title = 'subbla'
|
167
|
+
# We want to have to manually persist to the repository.
|
168
|
+
# Parent objects shouldn't be persisting children they share with other parents
|
169
|
+
dummy.persist!
|
170
|
+
subject.descMetadata.license = dummy
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should let you access" do
|
174
|
+
expect(subject.descMetadata.license.first.title).to eq ['subbla']
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should mark it as changed" do
|
178
|
+
expect(subject.descMetadata).to be_changed
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "asset.load_instance_from_solr" do
|
185
|
+
before do
|
186
|
+
subject.descMetadata.title = "Monkeys"
|
187
|
+
subject.save
|
188
|
+
@loaded_object = DummyAsset.load_instance_from_solr(subject.pid)
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should load the datastream" do
|
192
|
+
expect(@loaded_object.title).to eq ["Monkeys"]
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "relationships" do
|
197
|
+
before do
|
198
|
+
@new_object = DummyAsset.new
|
199
|
+
@new_object.title = "subbla"
|
200
|
+
@new_object.save
|
201
|
+
subject.title = "bla"
|
202
|
+
subject.descMetadata.creator = @new_object
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should have accessible relationship attributes" do
|
206
|
+
expect(subject.descMetadata.creator.first.title).to eq ["subbla"]
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should let me get to an AF:Base object" do
|
210
|
+
subject.save
|
211
|
+
subject.reload
|
212
|
+
expect(subject.descMetadata.creator.first).to be_kind_of(ActiveFedora::Base)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should allow for deep attributes to be set directly" do
|
216
|
+
subject.descMetadata.creator.first.title = "Bla"
|
217
|
+
expect(subject.descMetadata.creator.first.title).to eq ["Bla"]
|
218
|
+
end
|
219
|
+
|
220
|
+
context "when the subject is set with base_uri" do
|
221
|
+
before do
|
222
|
+
DummyResource.resource_class.configure :base_uri => 'http://example.org/'
|
223
|
+
new_object = DummyAsset.new
|
224
|
+
new_object.save
|
225
|
+
subject.descMetadata.creator = new_object
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should let me get to an AF:Base object" do
|
229
|
+
subject.save
|
230
|
+
subject.reload
|
231
|
+
expect(subject.descMetadata.creator.first).to be_kind_of(ActiveFedora::Base)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context "when the object with a relationship is saved" do
|
236
|
+
before do
|
237
|
+
subject.save
|
238
|
+
@object = subject.class.find(subject.pid)
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should be retrievable" do
|
242
|
+
expect(subject.descMetadata.creator.first.title).to eq ["subbla"]
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
context "when the object with a relationship is frozen" do
|
247
|
+
before do
|
248
|
+
subject.save
|
249
|
+
@object = subject.class.find(subject.pid)
|
250
|
+
@object.freeze
|
251
|
+
subject.freeze
|
252
|
+
end
|
253
|
+
|
254
|
+
it "should be retrievable" do
|
255
|
+
expect(subject.descMetadata.creator.first.title).to eq ["subbla"]
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when the object has no Rdf::Resource' do
|
260
|
+
before do
|
261
|
+
class DummyOmAsset < ActiveFedora::Base
|
262
|
+
has_metadata :name => 'descMetadata', :type => OmDatastream
|
263
|
+
end
|
264
|
+
|
265
|
+
@new_object = DummyOmAsset.new
|
266
|
+
@new_object.save
|
267
|
+
subject.title = "bla"
|
268
|
+
subject.descMetadata.creator = @new_object
|
269
|
+
subject.save
|
270
|
+
subject.reload
|
271
|
+
end
|
272
|
+
|
273
|
+
after do
|
274
|
+
Object.send(:remove_const, "DummyOmAsset") if Object
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should let me get to an AF:Base object" do
|
278
|
+
expect(subject.descMetadata.creator.first).to be_kind_of(ActiveFedora::Base)
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should not allow writing to the graph" do
|
282
|
+
expect{@new_object.resource << RDF::Statement.new(RDF::Node.new, RDF::DC.title, 'title')
|
283
|
+
}.to raise_error TypeError
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
@@ -0,0 +1,341 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
describe ActiveFedora::Rdf::Resource do
|
3
|
+
|
4
|
+
before do
|
5
|
+
class DummyLicense < ActiveFedora::Rdf::Resource
|
6
|
+
property :title, :predicate => RDF::DC.title
|
7
|
+
end
|
8
|
+
|
9
|
+
class DummyResource < ActiveFedora::Rdf::Resource
|
10
|
+
configure :type => RDF::URI('http://example.org/SomeClass')
|
11
|
+
property :license, :predicate => RDF::DC.license, :class_name => DummyLicense
|
12
|
+
property :title, :predicate => RDF::DC.title
|
13
|
+
end
|
14
|
+
end
|
15
|
+
after do
|
16
|
+
Object.send(:remove_const, "DummyResource") if Object
|
17
|
+
Object.send(:remove_const, "DummyLicense") if Object
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { DummyResource.new }
|
21
|
+
|
22
|
+
describe 'rdf_subject' do
|
23
|
+
it "should be a blank node if we haven't set it" do
|
24
|
+
expect(subject.rdf_subject.node?).to be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be settable" do
|
28
|
+
subject.set_subject! RDF::URI('http://example.org/moomin')
|
29
|
+
expect(subject.rdf_subject).to eq RDF::URI('http://example.org/moomin')
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'when changing subject' do
|
33
|
+
before do
|
34
|
+
subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland'))
|
35
|
+
subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject)
|
36
|
+
subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land')
|
37
|
+
subject.set_subject! RDF::URI('http://example.org/moomin')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should update graph subjects' do
|
41
|
+
expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should update graph objects' do
|
45
|
+
expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be_true
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should leave other uris alone' do
|
49
|
+
expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'with URI subject' do
|
54
|
+
before do
|
55
|
+
subject.set_subject! RDF::URI('http://example.org/moomin')
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not be settable' do
|
59
|
+
expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }.to raise_error
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#persisted?" do
|
65
|
+
before do
|
66
|
+
repository = RDF::Repository.new
|
67
|
+
subject.stub(:repository).and_return(repository)
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when the object is new" do
|
71
|
+
it "should return false" do
|
72
|
+
expect(subject).not_to be_persisted
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "when it is saved" do
|
77
|
+
before do
|
78
|
+
subject.title = "bla"
|
79
|
+
subject.persist!
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should return true" do
|
83
|
+
expect(subject).to be_persisted
|
84
|
+
end
|
85
|
+
|
86
|
+
context "and then modified" do
|
87
|
+
before do
|
88
|
+
subject.title = "newbla"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return true" do
|
92
|
+
expect(subject).to be_persisted
|
93
|
+
end
|
94
|
+
end
|
95
|
+
context "and then reloaded" do
|
96
|
+
before do
|
97
|
+
subject.reload
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should reset the title" do
|
101
|
+
expect(subject.title).to eq ["bla"]
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should be persisted" do
|
105
|
+
expect(subject).to be_persisted
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "#persist!" do
|
112
|
+
context "when the repository is set" do
|
113
|
+
context "and the item is not a blank node" do
|
114
|
+
|
115
|
+
subject {DummyResource.new("info:fedora/example:pid")}
|
116
|
+
|
117
|
+
before do
|
118
|
+
@repo = RDF::Repository.new
|
119
|
+
subject.class.stub(:repository).and_return(nil)
|
120
|
+
subject.stub(:repository).and_return(@repo)
|
121
|
+
subject.title = "bla"
|
122
|
+
subject.persist!
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should persist to the repository" do
|
126
|
+
expect(@repo.statements.first).to eq subject.statements.first
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should delete from the repository" do
|
130
|
+
subject.reload
|
131
|
+
expect(subject.title).to eq ["bla"]
|
132
|
+
subject.title = []
|
133
|
+
expect(subject.title).to eq []
|
134
|
+
subject.persist!
|
135
|
+
subject.reload
|
136
|
+
expect(subject.title).to eq []
|
137
|
+
expect(@repo.statements.to_a.length).to eq 1 # Only the type statement
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'property methods' do
|
144
|
+
it 'should set and get properties' do
|
145
|
+
subject.title = 'Comet in Moominland'
|
146
|
+
expect(subject.title).to eq ['Comet in Moominland']
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe 'child nodes' do
|
151
|
+
it 'should return an object of the correct class when the value is a URI' do
|
152
|
+
subject.license = DummyLicense.new('http://example.org/license')
|
153
|
+
expect(subject.license.first).to be_kind_of DummyLicense
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should return an object with the correct URI when the value is a URI ' do
|
157
|
+
subject.license = DummyLicense.new('http://example.org/license')
|
158
|
+
expect(subject.license.first.rdf_subject).to eq RDF::URI("http://example.org/license")
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should return an object of the correct class when the value is a bnode' do
|
162
|
+
subject.license = DummyLicense.new
|
163
|
+
expect(subject.license.first).to be_kind_of DummyLicense
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe '#set_value' do
|
168
|
+
it 'should set a value in the graph' do
|
169
|
+
subject.set_value(RDF::DC.title, 'Comet in Moominland')
|
170
|
+
subject.query(:subject => subject.rdf_subject, :predicate => RDF::DC.title).each_statement do |s|
|
171
|
+
expect(s.object.to_s).to eq 'Comet in Moominland'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should set a value in the when given a registered property symbol' do
|
176
|
+
subject.set_value(:title, 'Comet in Moominland')
|
177
|
+
expect(subject.title).to eq ['Comet in Moominland']
|
178
|
+
end
|
179
|
+
|
180
|
+
it "raise an error if the value is not a URI, Node, Literal, RdfResource, or string" do
|
181
|
+
expect{subject.set_value(RDF::DC.title, Object.new)}.to raise_error
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should be able to accept a subject" do
|
185
|
+
expect{subject.set_value(RDF::URI("http://opaquenamespace.org/jokes"), RDF::DC.title, 'Comet in Moominland')}.not_to raise_error
|
186
|
+
expect(subject.query(:subject => RDF::URI("http://opaquenamespace.org/jokes"), :predicate => RDF::DC.title).statements.to_a.length).to eq 1
|
187
|
+
end
|
188
|
+
end
|
189
|
+
describe '#get_values' do
|
190
|
+
before do
|
191
|
+
subject.title = ['Comet in Moominland', "Finn Family Moomintroll"]
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should return values for a predicate uri' do
|
195
|
+
expect(subject.get_values(RDF::DC.title)).to eq ['Comet in Moominland', 'Finn Family Moomintroll']
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should return values for a registered predicate symbol' do
|
199
|
+
expect(subject.get_values(:title)).to eq ['Comet in Moominland', 'Finn Family Moomintroll']
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should return values for other subjects if asked" do
|
203
|
+
expect(subject.get_values(RDF::URI("http://opaquenamespace.org/jokes"),:title)).to eq []
|
204
|
+
subject.set_value(RDF::URI("http://opaquenamespace.org/jokes"), RDF::DC.title, 'Comet in Moominland')
|
205
|
+
expect(subject.get_values(RDF::URI("http://opaquenamespace.org/jokes"),:title)).to eq ["Comet in Moominland"]
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe '#type' do
|
210
|
+
it 'should return the type configured on the parent class' do
|
211
|
+
expect(subject.type).to eq [DummyResource.type]
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should set the type' do
|
215
|
+
subject.type = RDF::URI('http://example.org/AnotherClass')
|
216
|
+
expect(subject.type).to eq [RDF::URI('http://example.org/AnotherClass')]
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should be the type in the graph' do
|
220
|
+
subject.query(:subject => subject.rdf_subject, :predicate => RDF.type).statements do |s|
|
221
|
+
expect(s.object).to eq RDF::URI('http://example.org/AnotherClass')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe '#rdf_label' do
|
227
|
+
it 'should return an array of label values' do
|
228
|
+
expect(subject.rdf_label).to be_kind_of Array
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'should return the default label values' do
|
232
|
+
subject.title = 'Comet in Moominland'
|
233
|
+
expect(subject.rdf_label).to eq ['Comet in Moominland']
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'should prioritize configured label values' do
|
237
|
+
custom_label = RDF::URI('http://example.org/custom_label')
|
238
|
+
subject.class.configure :rdf_label => custom_label
|
239
|
+
subject << RDF::Statement(subject.rdf_subject, custom_label, RDF::Literal('New Label'))
|
240
|
+
subject.title = 'Comet in Moominland'
|
241
|
+
expect(subject.rdf_label).to eq ['New Label']
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe '#solrize' do
|
246
|
+
it 'should return a label for bnodes' do
|
247
|
+
expect(subject.solrize).to eq subject.rdf_label
|
248
|
+
end
|
249
|
+
|
250
|
+
it 'should return a string of the resource uri' do
|
251
|
+
subject.set_subject! 'http://example.org/moomin'
|
252
|
+
expect(subject.solrize).to eq 'http://example.org/moomin'
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
describe 'editing the graph' do
|
257
|
+
it 'should write properties when statements are added' do
|
258
|
+
subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
|
259
|
+
expect(subject.title).to include 'Comet in Moominland'
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'should delete properties when statements are removed' do
|
263
|
+
subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
|
264
|
+
subject.delete RDF::Statement.new(subject.rdf_subject, RDF::DC.title, 'Comet in Moominland')
|
265
|
+
expect(subject.title).to eq []
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
describe 'big complex graphs' do
|
270
|
+
before do
|
271
|
+
class DummyPerson < ActiveFedora::Rdf::Resource
|
272
|
+
configure :type => RDF::URI('http://example.org/Person')
|
273
|
+
property :name, :predicate => RDF::FOAF.name
|
274
|
+
property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
|
275
|
+
property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
|
276
|
+
end
|
277
|
+
|
278
|
+
class DummyDocument < ActiveFedora::Rdf::Resource
|
279
|
+
configure :type => RDF::URI('http://example.org/Document')
|
280
|
+
property :title, :predicate => RDF::DC.title
|
281
|
+
property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson'
|
282
|
+
end
|
283
|
+
|
284
|
+
DummyResource.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument
|
285
|
+
end
|
286
|
+
|
287
|
+
subject { DummyResource.new }
|
288
|
+
|
289
|
+
let (:document1) do
|
290
|
+
d = DummyDocument.new
|
291
|
+
d.title = 'Document One'
|
292
|
+
d
|
293
|
+
end
|
294
|
+
|
295
|
+
let (:document2) do
|
296
|
+
d = DummyDocument.new
|
297
|
+
d.title = 'Document Two'
|
298
|
+
d
|
299
|
+
end
|
300
|
+
|
301
|
+
let (:person1) do
|
302
|
+
p = DummyPerson.new
|
303
|
+
p.name = 'Alice'
|
304
|
+
p
|
305
|
+
end
|
306
|
+
|
307
|
+
let (:person2) do
|
308
|
+
p = DummyPerson.new
|
309
|
+
p.name = 'Bob'
|
310
|
+
p
|
311
|
+
end
|
312
|
+
|
313
|
+
let (:data) { <<END
|
314
|
+
_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeClass> .
|
315
|
+
_:1 <http://purl.org/dc/terms/relation> _:2 .
|
316
|
+
_:2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Document> .
|
317
|
+
_:2 <http://purl.org/dc/terms/title> "Document One" .
|
318
|
+
_:2 <http://purl.org/dc/terms/creator> _:3 .
|
319
|
+
_:2 <http://purl.org/dc/terms/creator> _:4 .
|
320
|
+
_:4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
|
321
|
+
_:4 <http://xmlns.com/foaf/0.1/name> "Bob" .
|
322
|
+
_:3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
|
323
|
+
_:3 <http://xmlns.com/foaf/0.1/name> "Alice" .
|
324
|
+
_:3 <http://xmlns.com/foaf/0.1/knows> _:4 ."
|
325
|
+
END
|
326
|
+
}
|
327
|
+
|
328
|
+
after do
|
329
|
+
Object.send(:remove_const, "DummyDocument")
|
330
|
+
Object.send(:remove_const, "DummyPerson")
|
331
|
+
end
|
332
|
+
|
333
|
+
it 'should allow access to deep nodes' do
|
334
|
+
document1.creator = [person1, person2]
|
335
|
+
document2.creator = person1
|
336
|
+
person1.knows = person2
|
337
|
+
subject.item = [document1]
|
338
|
+
expect(subject.item.first.creator.first.knows.first.name).to eq ['Bob']
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|