ld4l-ore_rdf 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +25 -0
  4. data/.travis.yml +12 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +14 -0
  7. data/README.md +171 -0
  8. data/Rakefile +2 -0
  9. data/ld4l-ore_rdf.gemspec +45 -0
  10. data/lib/ld4l/ore_rdf/configuration.rb +41 -0
  11. data/lib/ld4l/ore_rdf/models/aggregation.rb +50 -0
  12. data/lib/ld4l/ore_rdf/models/aggregation_resource.rb +98 -0
  13. data/lib/ld4l/ore_rdf/models/proxy_resource.rb +54 -0
  14. data/lib/ld4l/ore_rdf/services/aggregation/add_aggregated_resource.rb +49 -0
  15. data/lib/ld4l/ore_rdf/services/aggregation/add_aggregated_resources.rb +28 -0
  16. data/lib/ld4l/ore_rdf/services/aggregation/create.rb +39 -0
  17. data/lib/ld4l/ore_rdf/services/aggregation/destroy.rb +47 -0
  18. data/lib/ld4l/ore_rdf/services/aggregation/destroy_with_id.rb +22 -0
  19. data/lib/ld4l/ore_rdf/services/aggregation/find.rb +72 -0
  20. data/lib/ld4l/ore_rdf/services/aggregation/persist.rb +34 -0
  21. data/lib/ld4l/ore_rdf/services/aggregation/resume.rb +30 -0
  22. data/lib/ld4l/ore_rdf/services/proxy/create.rb +64 -0
  23. data/lib/ld4l/ore_rdf/services/proxy/find.rb +93 -0
  24. data/lib/ld4l/ore_rdf/version.rb +5 -0
  25. data/lib/ld4l/ore_rdf/vocab/co.rb +27 -0
  26. data/lib/ld4l/ore_rdf/vocab/dcterms.rb +6 -0
  27. data/lib/ld4l/ore_rdf/vocab/iana.rb +9 -0
  28. data/lib/ld4l/ore_rdf/vocab/ore.rb +16 -0
  29. data/lib/ld4l/ore_rdf.rb +76 -0
  30. data/spec/ld4l/ore_rdf/configuration_spec.rb +174 -0
  31. data/spec/ld4l/ore_rdf/models/aggregation_resource_spec.rb +830 -0
  32. data/spec/ld4l/ore_rdf/models/aggregation_spec.rb +9 -0
  33. data/spec/ld4l/ore_rdf/models/proxy_resource_spec.rb +690 -0
  34. data/spec/ld4l/ore_rdf/services/aggregation/add_aggregated_resource_spec.rb +36 -0
  35. data/spec/ld4l/ore_rdf/services/aggregation/add_aggregated_resources_spec.rb +78 -0
  36. data/spec/ld4l/ore_rdf/services/aggregation/create_spec.rb +62 -0
  37. data/spec/ld4l/ore_rdf/services/aggregation/destroy_spec.rb +169 -0
  38. data/spec/ld4l/ore_rdf/services/aggregation/find_spec.rb +198 -0
  39. data/spec/ld4l/ore_rdf/services/aggregation/persist_spec.rb +13 -0
  40. data/spec/ld4l/ore_rdf/services/aggregation/resume_spec.rb +46 -0
  41. data/spec/ld4l/ore_rdf/services/proxy/create_spec.rb +143 -0
  42. data/spec/ld4l/ore_rdf/services/proxy/find_spec.rb +138 -0
  43. data/spec/ld4l/ore_rdf_spec.rb +53 -0
  44. data/spec/spec_helper.rb +23 -0
  45. metadata +259 -0
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LD4L::OreRDF::Aggregation' do
4
+
5
+ xit "should have tests -- SO WRITE SOME" do
6
+
7
+ end
8
+
9
+ end
@@ -0,0 +1,690 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'LD4L::OreRDF::ProxyResource' do
4
+
5
+ subject { LD4L::OreRDF::ProxyResource.new } # new virtual collection without a subject
6
+
7
+ describe 'rdf_subject' do
8
+ it "should be a blank node if we haven't set it" do
9
+ expect(subject.rdf_subject.node?).to be true
10
+ end
11
+
12
+ it "should be settable when it has not been set yet" do
13
+ subject.set_subject! RDF::URI('http://example.org/moomin')
14
+ expect(subject.rdf_subject).to eq RDF::URI('http://example.org/moomin')
15
+ end
16
+
17
+ it "should append to base URI when setting to non-URI subject" do
18
+ subject.set_subject! '123'
19
+ expect(subject.rdf_subject).to eq RDF::URI("#{LD4L::OreRDF::ProxyResource.base_uri}123")
20
+ end
21
+
22
+ describe 'when changing subject' do
23
+ before do
24
+ subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland'))
25
+ subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject)
26
+ subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land')
27
+ subject.set_subject! RDF::URI('http://example.org/moomin')
28
+ end
29
+
30
+ it 'should update graph subjects' do
31
+ expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true
32
+ end
33
+
34
+ it 'should update graph objects' do
35
+ expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true
36
+ end
37
+
38
+ it 'should leave other uris alone' do
39
+ 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
40
+ end
41
+ end
42
+
43
+ describe 'created with URI subject' do
44
+ before do
45
+ subject.set_subject! RDF::URI('http://example.org/moomin')
46
+ end
47
+
48
+ it 'should not be settable' do
49
+ expect{ subject.set_subject! RDF::URI('http://example.org/moomin2') }.to raise_error
50
+ end
51
+ end
52
+ end
53
+
54
+
55
+ # -------------------------------------------------
56
+ # START -- Test attributes specific to this model
57
+ # -------------------------------------------------
58
+
59
+ describe 'type' do
60
+ it "should be an RDFVocabularies::ORE.Proxy" do
61
+ expect(subject.type.first.value).to eq RDFVocabularies::ORE.Proxy.value
62
+ end
63
+ end
64
+
65
+ describe 'proxy_for' do
66
+ it "should be empty array if we haven't set it" do
67
+ expect(subject.proxy_for).to match_array([])
68
+ end
69
+
70
+ it "should be settable" do
71
+ subject.proxy_for = RDF::URI("http://example.org/b1")
72
+ expect(subject.proxy_for.first.rdf_subject).to eq RDF::URI("http://example.org/b1")
73
+ end
74
+
75
+ it "should be changeable" do
76
+ orig_proxy_for = RDF::URI("http://example.org/b1")
77
+ new_proxy_for = RDF::URI("http://example.org/b1_NEW")
78
+ subject.proxy_for = orig_proxy_for
79
+ subject.proxy_for = new_proxy_for
80
+ expect(subject.proxy_for.first.rdf_subject).to eq new_proxy_for
81
+ end
82
+ end
83
+
84
+ describe 'proxy_in' do
85
+ it "should be empty array if we haven't set it" do
86
+ expect(subject.proxy_in).to match_array([])
87
+ end
88
+
89
+ it "should be settable" do
90
+ an_aggregation = LD4L::OreRDF::AggregationResource.new('1')
91
+ subject.proxy_in = an_aggregation
92
+ expect(subject.proxy_in.first).to eq an_aggregation
93
+ end
94
+
95
+ it "should be changeable" do
96
+ orig_aggregation = LD4L::OreRDF::AggregationResource.new('1')
97
+ new_aggregation = LD4L::OreRDF::AggregationResource.new('2')
98
+ subject.proxy_in = orig_aggregation
99
+ subject.proxy_in = new_aggregation
100
+ expect(subject.proxy_in.first).to eq new_aggregation
101
+ end
102
+ end
103
+
104
+ describe 'next_proxy' do
105
+ it "should be empty array if we haven't set it" do
106
+ expect(subject.next_proxy).to match_array([])
107
+ end
108
+
109
+ it "should be settable" do
110
+ an_proxy = LD4L::OreRDF::ProxyResource.new('1')
111
+ subject.next_proxy = an_proxy
112
+ expect(subject.next_proxy.first).to eq an_proxy
113
+ end
114
+
115
+ it "should be changeable" do
116
+ orig_proxy = LD4L::OreRDF::ProxyResource.new('1')
117
+ new_proxy = LD4L::OreRDF::ProxyResource.new('2')
118
+ subject.next_proxy = orig_proxy
119
+ subject.next_proxy = new_proxy
120
+ expect(subject.next_proxy.first).to eq new_proxy
121
+ end
122
+ end
123
+
124
+ describe 'prev_proxy' do
125
+ it "should be empty array if we haven't set it" do
126
+ expect(subject.prev_proxy).to match_array([])
127
+ end
128
+
129
+ it "should be settable" do
130
+ an_proxy = LD4L::OreRDF::ProxyResource.new('1')
131
+ subject.prev_proxy = an_proxy
132
+ expect(subject.prev_proxy.first).to eq an_proxy
133
+ end
134
+
135
+ it "should be changeable" do
136
+ orig_proxy = LD4L::OreRDF::ProxyResource.new('1')
137
+ new_proxy = LD4L::OreRDF::ProxyResource.new('2')
138
+ subject.prev_proxy = orig_proxy
139
+ subject.prev_proxy = new_proxy
140
+ expect(subject.prev_proxy.first).to eq new_proxy
141
+ end
142
+ end
143
+
144
+ describe 'contributor' do
145
+ it "should be empty array if we haven't set it" do
146
+ expect(subject.contributor).to match_array([])
147
+ end
148
+
149
+ it "should be settable" do
150
+ a_person = LD4L::FoafRDF::Person.new('1')
151
+ subject.contributor = a_person
152
+ expect(subject.contributor.first).to eq a_person
153
+ end
154
+
155
+ it "should be changeable" do
156
+ orig_person = LD4L::FoafRDF::Person.new('1')
157
+ new_person = LD4L::FoafRDF::Person.new('2')
158
+ subject.contributor = orig_person
159
+ subject.contributor = new_person
160
+ expect(subject.contributor.first).to eq new_person
161
+ end
162
+ end
163
+
164
+ # -----------------------------------------------
165
+ # END -- Test attributes specific to this model
166
+ # -----------------------------------------------
167
+
168
+
169
+ # -----------------------------------------------------
170
+ # START -- Test helper methods specific to this model
171
+ # -----------------------------------------------------
172
+
173
+
174
+ ########### NEED TO MOVE TO SERVICE OBJECT ####################
175
+
176
+
177
+ describe "#get_range" do
178
+ context "when collection has 0 items" do
179
+ it "should return empty array when no items exist" do
180
+ vc = LD4L::OreRDF::AggregationResource.new
181
+ vc.aggregates = []
182
+ vci_array = LD4L::OreRDF::ProxyResource.get_range(vc)
183
+ expect(vci_array).to eq []
184
+ end
185
+ end
186
+
187
+ context "when collection has items" do
188
+ before do
189
+ vc.aggregates = []
190
+ vc.persist!
191
+
192
+
193
+ ### TODO need to update add_items_with_content to use new service
194
+
195
+
196
+ # vci_array = vc.add_items_with_content([RDF::URI("http://example.org/individual/b1"),
197
+ # RDF::URI("http://example.org/individual/b2"),
198
+ # RDF::URI("http://example.org/individual/b3")])
199
+
200
+
201
+
202
+ vc.persist!
203
+ vci_array.each { |vci| vci.persist! }
204
+ end
205
+
206
+ let(:vc) { LD4L::OreRDF::AggregationResource.new }
207
+
208
+ xit "should return array" do
209
+
210
+
211
+ ### TODO need to update add_items_with_content in BEFORE to use new service
212
+
213
+
214
+ vci_array = LD4L::OreRDF::ProxyResource.get_range(vc)
215
+ expect(vci_array).to be_a(Array)
216
+ expect(vci_array.size).to eq(3)
217
+ end
218
+
219
+ xit "should return array of LD4L::OreRDF::ProxyResource instances" do
220
+
221
+
222
+ ### TODO need to update add_items_with_content in BEFORE to use new service
223
+
224
+
225
+ vci_array = LD4L::OreRDF::ProxyResource.get_range(vc)
226
+ vci_array.each do |vci|
227
+ expect(vci).to be_a(LD4L::OreRDF::ProxyResource)
228
+ end
229
+ expect(vci_array.size).to eq(3)
230
+ end
231
+ end
232
+
233
+ context "when start and limit are not specified" do
234
+ context "and objects not persisted" do
235
+ before do
236
+ vc.aggregates = []
237
+ vc.persist!
238
+
239
+
240
+ ### TODO need to update add_items_with_content to use new service
241
+
242
+
243
+ # vc.add_items_with_content([RDF::URI("http://example.org/individual/b1"),
244
+ # RDF::URI("http://example.org/individual/b2"),
245
+ # RDF::URI("http://example.org/individual/b3")])
246
+ end
247
+
248
+ let(:vc) { LD4L::OreRDF::AggregationResource.new }
249
+
250
+ xit "should return empty array" do
251
+
252
+
253
+ ### TODO need to update add_items_with_content in BEFORE to use new service
254
+
255
+
256
+ vci_array = LD4L::OreRDF::ProxyResource.get_range(vc)
257
+ expect(vci_array.size).to eq(0)
258
+ end
259
+ end
260
+
261
+ context "and objects are persisted" do
262
+ before do
263
+ vc.aggregates = []
264
+ vc.persist!
265
+
266
+
267
+ ### TODO need to update add_items_with_content to use new service
268
+
269
+
270
+ # vci_array = vc.add_items_with_content([RDF::URI("http://example.org/individual/b1"),
271
+ # RDF::URI("http://example.org/individual/b2"),
272
+ # RDF::URI("http://example.org/individual/b3")])
273
+ vc.persist!
274
+ vci_array.each { |vci| vci.persist! }
275
+ end
276
+
277
+ let(:vc) { LD4L::OreRDF::AggregationResource.new }
278
+
279
+ xit "should return array of all LD4L::OreRDF::ProxyResource instances for content aggregated by subject" do
280
+
281
+
282
+ ### TODO need to update add_items_with_content in BEFORE to use new service
283
+
284
+
285
+ vci_array = LD4L::OreRDF::ProxyResource.get_range(vc)
286
+ vci_array.each do |vci|
287
+ expect(vci).to be_a(LD4L::OreRDF::ProxyResource)
288
+ expect(vci.proxy_in.first).to eq vc
289
+ end
290
+ results = []
291
+ vci_array.each { |vci| results << vci.proxy_for.first }
292
+ expect(results).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b1"))
293
+ expect(results).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b2"))
294
+ expect(results).to include ActiveTriples::Resource.new(RDF::URI("http://example.org/individual/b3"))
295
+ expect(vci_array.size).to eq(3)
296
+ end
297
+
298
+ xit "should not return any LD4L::OreRDF::ProxyResource instances for content not aggregated by subject" do
299
+ pending "this needs to be implemented"
300
+ end
301
+ end
302
+ end
303
+
304
+ context "when limit is specified" do
305
+ xit "should return array of LD4L::OreRDF::ProxyResource instances with max size=limit" do
306
+ pending "this needs to be implemented"
307
+ end
308
+ end
309
+
310
+ context "when start is specified" do
311
+ xit "should return array of LD4L::OreRDF::ProxyResource instances_beginning with item at position=start" do
312
+ # TODO: What does _start_ mean in ActiveTriples? Does it support this kind of query?
313
+ pending "this needs to be implemented"
314
+ end
315
+ end
316
+
317
+ context "when start and limit are specified" do
318
+ xit "should return an array of LD4L::OreRDF::ProxyResource instances with max size=limit beginning with item at position=start" do
319
+ pending "this needs to be implemented"
320
+ end
321
+ end
322
+ end
323
+
324
+ # ---------------------------------------------------
325
+ # END -- Test helper methods specific to this model
326
+ # ---------------------------------------------------
327
+
328
+
329
+ describe "#persisted?" do
330
+ context 'with a repository' do
331
+ before do
332
+ # Create inmemory repository
333
+ repository = RDF::Repository.new
334
+ allow(subject).to receive(:repository).and_return(repository)
335
+ end
336
+
337
+ context "when the object is new" do
338
+ it "should return false" do
339
+ expect(subject).not_to be_persisted
340
+ end
341
+ end
342
+
343
+ context "when it is saved" do
344
+ before do
345
+ subject.contributor = "John Smith"
346
+ subject.persist!
347
+ end
348
+
349
+ it "should return true" do
350
+ expect(subject).to be_persisted
351
+ end
352
+
353
+ context "and then modified" do
354
+ before do
355
+ subject.contributor = "New Smith"
356
+ end
357
+
358
+ it "should return true" do
359
+ expect(subject).to be_persisted
360
+ end
361
+ end
362
+ context "and then reloaded" do
363
+ before do
364
+ subject.reload
365
+ end
366
+
367
+ it "should reset the contributor" do
368
+ expect(subject.contributor).to eq ["John Smith"]
369
+ end
370
+
371
+ it "should be persisted" do
372
+ expect(subject).to be_persisted
373
+ end
374
+ end
375
+ end
376
+ end
377
+ end
378
+
379
+ describe "#persist!" do
380
+ context "when the repository is set" do
381
+ context "and the item is not a blank node" do
382
+
383
+ subject {LD4L::OreRDF::ProxyResource.new("123")}
384
+
385
+ before do
386
+ # Create inmemory repository
387
+ @repo = RDF::Repository.new
388
+ allow(subject.class).to receive(:repository).and_return(nil)
389
+ allow(subject).to receive(:repository).and_return(@repo)
390
+ subject.contributor = "John Smith"
391
+ an_aggregation = LD4L::OreRDF::AggregationResource.new('1')
392
+ subject.proxy_in = an_aggregation
393
+ subject.proxy_for = RDF::URI("http://example.org/b1")
394
+ subject.persist!
395
+ end
396
+
397
+ it "should persist to the repository" do
398
+ expect(@repo.statements.first).to eq subject.statements.first
399
+ end
400
+
401
+ it "should delete from the repository" do
402
+ subject.reload
403
+ expect(subject.contributor).to eq ["John Smith"]
404
+ subject.contributor = []
405
+ subject.proxy_in = []
406
+ subject.proxy_for = []
407
+ expect(subject.contributor).to eq []
408
+ subject.persist!
409
+ subject.reload
410
+ expect(subject.contributor).to eq []
411
+ expect(@repo.statements.to_a.length).to eq 1 # Only the type statement
412
+ end
413
+ end
414
+
415
+ context "and the item is created by create method" do
416
+
417
+
418
+ ### TODO need to update create to use new service
419
+
420
+
421
+ # subject { LD4L::OreRDF::ProxyResource.create(id: "123", aggregation: LD4L::OreRDF::AggregationResource.new('1'), content: RDF::URI("http://example.org/b1"), contributor: "John Smith")}
422
+
423
+ before do
424
+ # Create inmemory repository
425
+ @repo = RDF::Repository.new
426
+ allow(subject.class).to receive(:repository).and_return(nil)
427
+ allow(subject).to receive(:repository).and_return(@repo)
428
+ subject.persist!
429
+ end
430
+
431
+ xit "should persist to the repository" do
432
+ expect(@repo.statements.first).to eq subject.statements.first
433
+ end
434
+
435
+ xit "should delete from the repository" do
436
+ subject.reload
437
+ expect(subject.contributor).to eq ["John Smith"]
438
+ subject.contributor = []
439
+ subject.proxy_in = []
440
+ subject.proxy_for = []
441
+ expect(subject.contributor).to eq []
442
+ subject.persist!
443
+ subject.reload
444
+ expect(subject.contributor).to eq []
445
+ expect(@repo.statements.to_a.length).to eq 1 # Only the type statement
446
+ end
447
+ end
448
+ end
449
+ end
450
+
451
+ describe '#destroy!' do
452
+ before do
453
+ subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE')
454
+ end
455
+
456
+ subject { LD4L::FoafRDF::Person.new('456')}
457
+
458
+ it 'should return true' do
459
+ expect(subject.destroy!).to be true
460
+ expect(subject.destroy).to be true
461
+ end
462
+
463
+ it 'should delete the graph' do
464
+ subject.destroy
465
+ expect(subject).to be_empty
466
+ end
467
+
468
+ context 'with a parent' do
469
+ before do
470
+ parent.contributor = subject
471
+ end
472
+
473
+ let(:parent) do
474
+ LD4L::OreRDF::ProxyResource.new('123')
475
+ end
476
+
477
+ it 'should empty the graph and remove it from the parent' do
478
+ subject.destroy
479
+ expect(parent.contributor).to be_empty
480
+ end
481
+
482
+ it 'should remove its whole graph from the parent' do
483
+ subject.destroy
484
+ subject.each_statement do |s|
485
+ expect(parent.statements).not_to include s
486
+ end
487
+ end
488
+ end
489
+ end
490
+
491
+ describe 'attributes' do
492
+ before do
493
+ subject.contributor = contributor
494
+ subject.proxy_for = 'Dummy Proxy'
495
+ end
496
+
497
+ subject {LD4L::OreRDF::ProxyResource.new("123")}
498
+
499
+ let(:contributor) { LD4L::FoafRDF::Person.new('456') }
500
+
501
+ it 'should return an attributes hash' do
502
+ expect(subject.attributes).to be_a Hash
503
+ end
504
+
505
+ it 'should contain data' do
506
+ expect(subject.attributes['proxy_for']).to eq ['Dummy Proxy']
507
+ end
508
+
509
+ it 'should contain child objects' do
510
+ expect(subject.attributes['contributor']).to eq [contributor]
511
+ end
512
+
513
+ context 'with unmodeled data' do
514
+ before do
515
+ subject << RDF::Statement(subject.rdf_subject, RDF::DC.creator, 'Tove Jansson')
516
+ subject << RDF::Statement(subject.rdf_subject, RDF::DC.relation, RDF::URI('http://example.org/moomi'))
517
+ node = RDF::Node.new
518
+ subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::DC.relation, node)
519
+ subject << RDF::Statement(node, RDF::DC.title, 'bnode')
520
+ end
521
+
522
+ it 'should include data with URIs as attribute names' do
523
+ expect(subject.attributes[RDF::DC.creator.to_s]).to eq ['Tove Jansson']
524
+ end
525
+
526
+ it 'should return generic Resources' do
527
+ expect(subject.attributes[RDF::DC.relation.to_s].first).to be_a ActiveTriples::Resource
528
+ end
529
+
530
+ it 'should build deep data for Resources' do
531
+ expect(subject.attributes[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation).
532
+ first.get_values(RDF::DC.title)).to eq ['bnode']
533
+ end
534
+
535
+ it 'should include deep data in serializable_hash' do
536
+ expect(subject.serializable_hash[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation).
537
+ first.get_values(RDF::DC.title)).to eq ['bnode']
538
+ end
539
+ end
540
+
541
+ describe 'attribute_serialization' do
542
+ describe '#to_json' do
543
+ it 'should return a string with correct objects' do
544
+ json_hash = JSON.parse(subject.to_json)
545
+ expect(json_hash['contributor'].first['id']).to eq contributor.rdf_subject.to_s
546
+ end
547
+ end
548
+ end
549
+ end
550
+
551
+ describe 'property methods' do
552
+ it 'should set and get properties' do
553
+ subject.proxy_for = 'Comet in Moominland'
554
+ expect(subject.proxy_for).to eq ['Comet in Moominland']
555
+ end
556
+ end
557
+
558
+ describe 'child nodes' do
559
+ it 'should return an object of the correct class when the value is built from the base URI' do
560
+ subject.contributor = LD4L::FoafRDF::Person.new('456')
561
+ expect(subject.contributor.first).to be_kind_of LD4L::FoafRDF::Person
562
+ end
563
+
564
+ it 'should return an object with the correct URI created with a URI' do
565
+ subject.contributor = LD4L::FoafRDF::Person.new("http://example.org/license")
566
+ expect(subject.contributor.first.rdf_subject).to eq RDF::URI("http://example.org/license")
567
+ end
568
+
569
+ it 'should return an object of the correct class when the value is a bnode' do
570
+ subject.contributor = LD4L::FoafRDF::Person.new
571
+ expect(subject.contributor.first).to be_kind_of LD4L::FoafRDF::Person
572
+ end
573
+ end
574
+
575
+ describe '#rdf_label' do
576
+ subject {LD4L::OreRDF::ProxyResource.new("123")}
577
+
578
+ it 'should return an array of label values' do
579
+ expect(subject.rdf_label).to be_kind_of Array
580
+ end
581
+
582
+ it 'should return the default label as URI when no title property exists' do
583
+ expect(subject.rdf_label.first).to eq "#{LD4L::OreRDF::ProxyResource.base_uri}123"
584
+ end
585
+
586
+ it 'should prioritize configured label values' do
587
+ custom_label = RDF::URI('http://example.org/custom_label')
588
+ subject.class.configure :rdf_label => custom_label
589
+ subject << RDF::Statement(subject.rdf_subject, custom_label, RDF::Literal('New Label'))
590
+ expect(subject.rdf_label).to eq ['New Label']
591
+ end
592
+ end
593
+
594
+ describe '#solrize' do
595
+ it 'should return a label for bnodes' do
596
+ expect(subject.solrize).to eq subject.rdf_label
597
+ end
598
+
599
+ it 'should return a string of the resource uri' do
600
+ subject.set_subject! 'http://example.org/moomin'
601
+ expect(subject.solrize).to eq 'http://example.org/moomin'
602
+ end
603
+ end
604
+
605
+ describe 'editing the graph' do
606
+ it 'should write properties when statements are added' do
607
+ subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::ORE.proxyFor, 'Comet in Moominland')
608
+ expect(subject.proxy_for).to include 'Comet in Moominland'
609
+ end
610
+
611
+ it 'should delete properties when statements are removed' do
612
+ subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::ORE.proxyFor, 'Comet in Moominland')
613
+ subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::ORE.proxyFor, 'Comet in Moominland')
614
+ expect(subject.proxy_for).to eq []
615
+ end
616
+ end
617
+
618
+ describe 'big complex graphs' do
619
+ before do
620
+ class DummyPerson < ActiveTriples::Resource
621
+ configure :type => RDF::URI('http://example.org/Person')
622
+ property :foafname, :predicate => RDF::FOAF.name
623
+ property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument'
624
+ property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson
625
+ end
626
+
627
+ class DummyDocument < ActiveTriples::Resource
628
+ configure :type => RDF::URI('http://example.org/Document')
629
+ property :title, :predicate => RDF::DC.title
630
+ property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson'
631
+ end
632
+
633
+ LD4L::OreRDF::ProxyResource.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument
634
+ end
635
+
636
+ subject { LD4L::OreRDF::ProxyResource.new }
637
+
638
+ let (:document1) do
639
+ d = DummyDocument.new
640
+ d.title = 'Document One'
641
+ d
642
+ end
643
+
644
+ let (:document2) do
645
+ d = DummyDocument.new
646
+ d.title = 'Document Two'
647
+ d
648
+ end
649
+
650
+ let (:person1) do
651
+ p = DummyPerson.new
652
+ p.foafname = 'Alice'
653
+ p
654
+ end
655
+
656
+ let (:person2) do
657
+ p = DummyPerson.new
658
+ p.foafname = 'Bob'
659
+ p
660
+ end
661
+
662
+ let (:data) { <<END
663
+ _:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/SomeClass> .
664
+ _:1 <http://purl.org/dc/terms/relation> _:2 .
665
+ _:2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Document> .
666
+ _:2 <http://purl.org/dc/terms/title> "Document One" .
667
+ _:2 <http://purl.org/dc/terms/creator> _:3 .
668
+ _:2 <http://purl.org/dc/terms/creator> _:4 .
669
+ _:4 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
670
+ _:4 <http://xmlns.com/foaf/0.1/name> "Bob" .
671
+ _:3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/Person> .
672
+ _:3 <http://xmlns.com/foaf/0.1/name> "Alice" .
673
+ _:3 <http://xmlns.com/foaf/0.1/knows> _:4 ."
674
+ END
675
+ }
676
+
677
+ after do
678
+ Object.send(:remove_const, "DummyDocument")
679
+ Object.send(:remove_const, "DummyPerson")
680
+ end
681
+
682
+ it 'should allow access to deep nodes' do
683
+ document1.creator = [person1, person2]
684
+ document2.creator = person1
685
+ person1.knows = person2
686
+ subject.item = [document1]
687
+ expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob']
688
+ end
689
+ end
690
+ end