active-fedora 11.0.0.rc6 → 11.0.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/active-fedora.gemspec +0 -3
  3. data/lib/active_fedora.rb +0 -10
  4. data/lib/active_fedora/associations/has_many_association.rb +1 -1
  5. data/lib/active_fedora/attributes.rb +1 -1
  6. data/lib/active_fedora/base.rb +3 -7
  7. data/lib/active_fedora/querying.rb +1 -1
  8. data/lib/active_fedora/rdf.rb +0 -1
  9. data/lib/active_fedora/version.rb +1 -1
  10. data/spec/integration/attached_files_spec.rb +14 -4
  11. data/spec/integration/file_spec.rb +22 -23
  12. data/spec/integration/versionable_spec.rb +0 -254
  13. data/spec/spec_helper.rb +0 -7
  14. data/spec/unit/attached_files_spec.rb +10 -7
  15. data/spec/unit/base_spec.rb +3 -1
  16. data/spec/unit/has_many_association_spec.rb +23 -8
  17. data/spec/unit/inheritance_spec.rb +11 -7
  18. data/spec/unit/model_classifier_spec.rb +1 -1
  19. data/spec/unit/rdf/indexing_service_spec.rb +9 -9
  20. data/spec/unit/solr_config_options_spec.rb +12 -15
  21. metadata +2 -67
  22. data/lib/active_fedora/datastreams.rb +0 -6
  23. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  24. data/lib/active_fedora/nom_datastream.rb +0 -73
  25. data/lib/active_fedora/om_datastream.rb +0 -118
  26. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  27. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  28. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  29. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -173
  30. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  31. data/spec/integration/complex_rdf_datastream_spec.rb +0 -227
  32. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -180
  33. data/spec/integration/ntriples_datastream_spec.rb +0 -215
  34. data/spec/integration/om_datastream_spec.rb +0 -78
  35. data/spec/samples/hydra-mods_article_datastream.rb +0 -515
  36. data/spec/samples/models/mods_article.rb +0 -9
  37. data/spec/samples/samples.rb +0 -2
  38. data/spec/unit/nom_datastream_spec.rb +0 -60
  39. data/spec/unit/ntriples_datastream_spec.rb +0 -167
  40. data/spec/unit/om_datastream_spec.rb +0 -294
  41. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  42. data/spec/unit/rdf_datastream_spec.rb +0 -84
  43. data/spec/unit/rdf_resource_datastream_spec.rb +0 -208
  44. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -1,13 +0,0 @@
1
- require 'rdf/rdfxml'
2
-
3
- module ActiveFedora
4
- class RDFXMLDatastream < RDFDatastream
5
- def serialization_format
6
- :rdfxml
7
- end
8
-
9
- def mime_type
10
- 'text/xml'
11
- end
12
- end
13
- end
@@ -1,227 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Nested Rdf Objects" do
4
- describe "without type" do
5
- before do
6
- class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
7
- property :parts, predicate: ::RDF::Vocab::DC.hasPart, class_name: 'Component'
8
-
9
- class Component < ActiveTriples::Resource
10
- property :label, predicate: ::RDF::Vocab::DC.title
11
- end
12
- end
13
- end
14
-
15
- after do
16
- Object.send(:remove_const, :SpecDatastream)
17
- end
18
-
19
- let(:ds) do
20
- SpecDatastream.new("#{ActiveFedora.fedora.host}/test/test:124/descMd")
21
- end
22
-
23
- describe "#new_record?" do
24
- it "is true when its built" do
25
- v = ds.parts.build(label: 'Alternator')
26
- expect(v).to be_new_record
27
- end
28
-
29
- it "does not be new when it's loaded from fedora" do
30
- ds.content = "_:g70324142325120 <http://purl.org/dc/terms/title> \"Alternator\" .
31
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70324142325120 ."
32
- ds.resource.persist!
33
- expect(ds.parts.first).to_not be_new_record
34
- end
35
- end
36
-
37
- it "is able to nest a complex object" do
38
- comp = SpecDatastream::Component.new(nil, ds.graph)
39
- comp.label = ["Alternator"]
40
- ds.parts = comp
41
- expect(ds.parts.first.label).to eq ["Alternator"]
42
- end
43
-
44
- it "is able to replace attributes" do
45
- ds.parts.build(label: 'Alternator')
46
- expect(ds.parts.first.label).to eq ['Alternator']
47
- ds.parts.first.label = ['Distributor']
48
- expect(ds.parts.first.label).to eq ['Distributor']
49
- end
50
-
51
- it "is able to replace objects" do
52
- ds.parts.build(label: 'Alternator')
53
- ds.parts.build(label: 'Distributor')
54
- expect(ds.parts.size).to eq 2
55
- comp = SpecDatastream::Component.new(nil, ds.graph)
56
- comp.label = "Injector port"
57
- ds.parts = [comp]
58
- expect(ds.parts.size).to eq 1
59
- end
60
-
61
- it "is able to nest many complex objects" do
62
- comp1 = SpecDatastream::Component.new nil, ds.graph
63
- comp1.label = ["Alternator"]
64
- comp2 = SpecDatastream::Component.new nil, ds.graph
65
- comp2.label = ["Crankshaft"]
66
- ds.parts = [comp1, comp2]
67
- expect(ds.parts.map(&:label)).to contain_exactly ["Alternator"], ["Crankshaft"]
68
- end
69
-
70
- it "is able to clear complex objects" do
71
- comp1 = SpecDatastream::Component.new nil, ds.graph
72
- comp1.label = ["Alternator"]
73
- comp2 = SpecDatastream::Component.new nil, ds.graph
74
- comp2.label = ["Crankshaft"]
75
- ds.parts = [comp1, comp2]
76
- ds.parts = []
77
- expect(ds.parts).to eq []
78
- end
79
-
80
- it "loads complex objects" do
81
- ds.content = <<END
82
- _:g70350851837440 <http://purl.org/dc/terms/title> "Alternator" .
83
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851837440 .
84
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851833380 .
85
- _:g70350851833380 <http://purl.org/dc/terms/title> "Crankshaft" .
86
- END
87
- expect(ds.parts.map(&:label)).to contain_exactly ["Alternator"], ["Crankshaft"]
88
- end
89
-
90
- it "builds complex objects when a parent node doesn't exist" do
91
- part = ds.parts.build
92
- expect(part).to be_kind_of SpecDatastream::Component
93
- part.label = "Wheel bearing"
94
- expect(ds.parts.first.label).to eq ['Wheel bearing']
95
- end
96
-
97
- it "does not create a child node when hitting the accessor" do
98
- ds.parts
99
- expect(ds.parts.first).to be_nil
100
- expect(ds.serialize).to eq ''
101
- end
102
-
103
- it "builds complex objects when a parent node exists" do
104
- part = ds.parts.build
105
- expect(part).to be_kind_of SpecDatastream::Component
106
- part.label = "Wheel bearing"
107
- expect(ds.parts.first.label).to eq ['Wheel bearing']
108
- end
109
-
110
- describe "#first_or_create" do
111
- it "returns a result if the predicate exists" do
112
- part1 = ds.parts.build
113
- expect(ds.parts.first_or_create).to eq part1
114
- end
115
-
116
- it "creates a new result if the predicate doesn't exist" do
117
- expect(ds.parts).to eq []
118
- part = ds.parts.first_or_create(label: 'Front control arm bushing')
119
- expect(part.label).to eq ['Front control arm bushing']
120
- expect(ds.parts).to eq [part]
121
- end
122
- end
123
- end
124
-
125
- describe "with type" do
126
- describe "one class per assertion" do
127
- before(:each) do
128
- class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
129
- property :mediator, predicate: ::RDF::Vocab::DC.mediator, class_name: 'MediatorUser'
130
-
131
- class MediatorUser < ActiveTriples::Resource
132
- configure type: ::RDF::Vocab::DC.AgentClass
133
- property :title, predicate: ::RDF::Vocab::DC.title
134
- end
135
- end
136
- end
137
-
138
- after(:each) do
139
- Object.send(:remove_const, :SpecDatastream)
140
- end
141
- let(:ds) { SpecDatastream.new("#{ActiveFedora.fedora.host}/test/test:124/descMd") }
142
-
143
- it "stores the type of complex objects when type is specified" do
144
- comp = SpecDatastream::MediatorUser.new nil, ds.graph
145
- comp.title = ["Doctor"]
146
- ds.mediator = comp
147
- expect(ds.mediator.first.type.first).to be_instance_of ::RDF::URI
148
- expect(ds.mediator.first.type.first.to_s).to eq "http://purl.org/dc/terms/AgentClass"
149
- expect(ds.mediator.first.title.first).to eq 'Doctor'
150
- end
151
-
152
- it "adds the type of complex object when it is not provided" do
153
- ds.content = <<END
154
- _:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Person" .
155
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
156
- END
157
- expect(ds.mediator.first.type.first.to_s).to eq "http://purl.org/dc/terms/AgentClass"
158
- end
159
-
160
- it "adds load the type of complex objects when provided (superceeding what is specified by the class)" do
161
- ds.content = <<END
162
- _:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Orgainzation" .
163
- _:g70350851837440 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ebu.ch/metadata/ontologies/ebucore#Organisation> .
164
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
165
- END
166
- expect(ds.mediator.first.type.map(&:to_s)).to include "http://www.ebu.ch/metadata/ontologies/ebucore#Organisation"
167
- end
168
- end
169
-
170
- describe "shared assertion to different classes" do
171
- before(:each) do
172
- class EbuCore < RDF::Vocabulary("http://www.ebu.ch/metadata/ontologies/ebucore#")
173
- property :isEpisodeOf
174
- property :title
175
- end
176
-
177
- class SpecContainer < ActiveFedora::Base
178
- has_subresource :info, class_name: 'SpecDatastream'
179
- end
180
-
181
- class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
182
- property :series, predicate: EbuCore.isEpisodeOf, class_name: 'Series'
183
- property :program, predicate: EbuCore.isEpisodeOf, class_name: 'Program'
184
-
185
- class Series < ActiveTriples::Resource
186
- configure type: 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
187
- property :title, predicate: EbuCore.title
188
- end
189
-
190
- class Program < ActiveTriples::Resource
191
- configure type: 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
192
- property :title, predicate: EbuCore.title
193
- end
194
- end
195
- end
196
-
197
- after(:each) do
198
- Object.send(:remove_const, :SpecDatastream)
199
- Object.send(:remove_const, :SpecContainer)
200
- end
201
-
202
- let(:parent) { SpecContainer.new id: '124' }
203
- let(:file) { parent.info }
204
-
205
- it "stores the type of complex objects when type is specified" do
206
- pending "This is no longer supported by ActiveTriples - can we deprecate this altogether?"
207
- series = SpecDatastream::Series.new nil, file.graph
208
- series.title = ["renovating bathrooms"]
209
- file.series = series
210
-
211
- program = SpecDatastream::Program.new nil, file.graph
212
- program.title = ["This old House"]
213
- file.program = program
214
-
215
- expect(file.program.first.type.size).to eq 1
216
- expect(file.program.first.type.first.to_s).to eq 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
217
- expect(file.series.first.type.size).to eq 1
218
- expect(file.series.first.type.first.to_s).to eq 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
219
- end
220
-
221
- it "creates an object of the correct type" do
222
- expect(file.program.build).to be_kind_of SpecDatastream::Program
223
- expect(file.series.build).to be_kind_of SpecDatastream::Series
224
- end
225
- end
226
- end
227
- end
@@ -1,180 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Nesting attribute behavior of RDFDatastream" do
4
- describe ".attributes=" do
5
- context "complex properties in a datastream" do
6
- before do
7
- class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
8
- # TODO: this test is order dependent. It expects to use the object created in the previous test
9
- # componentList and Types of components
10
- property :componentList
11
- property :Topic
12
- property :Temporal
13
- property :PersonalName
14
- property :CorporateName
15
- property :ComplexSubject
16
-
17
- # elementList and elementList values
18
- property :elementList
19
- property :elementValue
20
- property :TopicElement
21
- property :TemporalElement
22
- property :NameElement
23
- property :FullNameElement
24
- property :DateNameElement
25
- end
26
-
27
- class ComplexRDFDatastream < ActiveFedora::NtriplesRDFDatastream
28
- property :topic, predicate: DummyMADS.Topic, class_name: "Topic"
29
- property :personalName, predicate: DummyMADS.PersonalName, class_name: "PersonalName"
30
- property :title, predicate: ::RDF::Vocab::DC.title
31
-
32
- accepts_nested_attributes_for :topic, :personalName
33
-
34
- class Topic < ActiveTriples::Resource
35
- property :elementList, predicate: DummyMADS.elementList, class_name: "ComplexRDFDatastream::ElementList"
36
- accepts_nested_attributes_for :elementList
37
- end
38
- class PersonalName < ActiveTriples::Resource
39
- property :elementList, predicate: DummyMADS.elementList, class_name: "ComplexRDFDatastream::ElementList"
40
- property :extraProperty, predicate: DummyMADS.elementValue, class_name: "ComplexRDFDatastream::Topic"
41
- accepts_nested_attributes_for :elementList, :extraProperty
42
- end
43
- class ElementList < ActiveTriples::List
44
- configure type: DummyMADS.elementList
45
- property :topicElement, predicate: DummyMADS.TopicElement, class_name: "ComplexRDFDatastream::MadsTopicElement"
46
- property :temporalElement, predicate: DummyMADS.TemporalElement
47
- property :fullNameElement, predicate: DummyMADS.FullNameElement
48
- property :dateNameElement, predicate: DummyMADS.DateNameElement
49
- property :nameElement, predicate: DummyMADS.NameElement
50
- property :elementValue, predicate: DummyMADS.elementValue
51
- accepts_nested_attributes_for :topicElement
52
- end
53
- class MadsTopicElement < ActiveTriples::Resource
54
- configure type: DummyMADS.TopicElement
55
- property :elementValue, predicate: DummyMADS.elementValue
56
- end
57
- end
58
- end
59
- after do
60
- Object.send(:remove_const, :ComplexRDFDatastream)
61
- Object.send(:remove_const, :DummyMADS)
62
- end
63
- subject(:complex_datastream) { ComplexRDFDatastream.new }
64
- let(:params) do
65
- { myResource:
66
- {
67
- topic_attributes: {
68
- '0' =>
69
- {
70
- elementList_attributes: [{
71
- topicElement_attributes: [{
72
- id: 'http://library.ucsd.edu/ark:/20775/bb3333333x',
73
- elementValue: "Cosmology"
74
- }]
75
- }]
76
- },
77
- '1' =>
78
- {
79
- elementList_attributes: [{
80
- topicElement_attributes: { '0' => { elementValue: "Quantum Behavior" } }
81
- }]
82
- }
83
- },
84
- personalName_attributes: [
85
- {
86
- id: 'http://library.ucsd.edu/ark:20775/jefferson',
87
- elementList_attributes: [{
88
- fullNameElement: "Jefferson, Thomas",
89
- dateNameElement: "1743-1826"
90
- }]
91
- }
92
- # , "Hemings, Sally"
93
- ]
94
- } }
95
- end
96
-
97
- describe "on lists" do
98
- subject(:personal_name) { ComplexRDFDatastream::PersonalName.new(nil) }
99
- it "accepts a hash" do
100
- personal_name.elementList_attributes = [{ topicElement_attributes: { '0' => { elementValue: "Quantum Behavior" }, '1' => { elementValue: "Wave Function" } } }]
101
- expect(personal_name.elementList.first[0].elementValue).to eq ["Quantum Behavior"]
102
- expect(personal_name.elementList.first[1].elementValue).to eq ["Wave Function"]
103
- end
104
- it "accepts an array" do
105
- personal_name.elementList_attributes = [{ topicElement_attributes: [{ elementValue: "Quantum Behavior" }, { elementValue: "Wave Function" }] }]
106
- element_values = personal_name.elementList.first.map(&:elementValue)
107
- expect(element_values).to contain_exactly ["Quantum Behavior"], ["Wave Function"]
108
- end
109
- end
110
-
111
- context "from nested objects" do
112
- before do
113
- # Replace the graph's contents with the Hash
114
- complex_datastream.attributes = params[:myResource]
115
- end
116
-
117
- it 'has attributes' do
118
- element_values = complex_datastream.topic.map { |x| x.elementList.first[0].elementValue }
119
- expect(element_values).to contain_exactly ["Cosmology"], ["Quantum Behavior"]
120
- expect(complex_datastream.personalName.first.elementList.first.fullNameElement).to contain_exactly "Jefferson, Thomas"
121
- expect(complex_datastream.personalName.first.elementList.first.dateNameElement).to contain_exactly "1743-1826"
122
- end
123
-
124
- it 'builds nodes with ids' do
125
- element_list_elements = complex_datastream.topic.flat_map { |y| y.elementList.first[0].rdf_subject }
126
- expect(element_list_elements).to include 'http://library.ucsd.edu/ark:/20775/bb3333333x'
127
- expect(complex_datastream.personalName.first.rdf_subject).to eq 'http://library.ucsd.edu/ark:20775/jefferson'
128
- end
129
-
130
- it 'fails when writing to a non-predicate' do
131
- attributes = { topic_attributes: { '0' => { elementList_attributes: [{ topicElement_attributes: [{ fake_predicate: "Cosmology" }] }] } } }
132
- expect { complex_datastream.attributes = attributes }.to raise_error ArgumentError
133
- end
134
-
135
- it 'fails when writing to a non-predicate with a setter method' do
136
- attributes = { topic_attributes: { '0' => { elementList_attributes: [{ topicElement_attributes: [{ name: "Cosmology" }] }] } } }
137
- expect { complex_datastream.attributes = attributes }.to raise_error ArgumentError
138
- end
139
- end
140
- end
141
-
142
- describe "with an existing object" do
143
- before(:each) do
144
- class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
145
- property :parts, predicate: ::RDF::Vocab::DC.hasPart, class_name: 'Component'
146
- accepts_nested_attributes_for :parts, allow_destroy: true
147
-
148
- class Component < ActiveTriples::Resource
149
- property :label, predicate: ::RDF::Vocab::DC.title
150
- end
151
- end
152
- end
153
-
154
- after(:each) do
155
- Object.send(:remove_const, :SpecDatastream)
156
- end
157
- subject(:spec_datastream) { SpecDatastream.new }
158
- before do
159
- spec_datastream.attributes = { parts_attributes: [
160
- { label: 'Alternator' },
161
- { label: 'Distributor' },
162
- { label: 'Transmission' },
163
- { label: 'Fuel Filter' }
164
- ] }
165
- end
166
- let(:replace_object_id) { spec_datastream.parts.find { |x| x.label == ['Distributor'] }.rdf_subject.to_s }
167
- let(:remove_object_id) { spec_datastream.parts.find { |x| x.label == ['Fuel Filter'] }.rdf_subject.to_s }
168
-
169
- it "updates nested objects" do
170
- spec_datastream.parts_attributes = [{ id: replace_object_id, label: "Universal Joint" }, { label: "Oil Pump" }, { id: remove_object_id, _destroy: '1', label: "bar1 uno" }]
171
-
172
- expect(spec_datastream.parts.map { |p| p.label.first }).to contain_exactly 'Alternator', 'Universal Joint', 'Transmission', 'Oil Pump'
173
- end
174
- it "create a new object when the id is provided" do
175
- spec_datastream.parts_attributes = [{ id: 'http://example.com/part#1', label: "Universal Joint" }]
176
- expect(spec_datastream.parts.map(&:rdf_subject)).to include RDF::URI('http://example.com/part#1')
177
- end
178
- end
179
- end
180
- end
@@ -1,215 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::NtriplesRDFDatastream do
4
- before do
5
- class FileVocabulary < RDF::Vocabulary("http://downlode.org/Code/RDF/File_Properties/schema#")
6
- property :size
7
- end
8
-
9
- Deprecation.silence(ActiveFedora::RDFDatastream) do
10
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
11
- property :title, predicate: ::RDF::Vocab::DC.title do |index|
12
- index.as :stored_searchable, :facetable
13
- end
14
- property :date_uploaded, predicate: ::RDF::Vocab::DC.dateSubmitted do |index|
15
- index.type :date
16
- index.as :stored_searchable, :sortable
17
- end
18
- property :filesize, predicate: FileVocabulary.size do |index|
19
- index.type :integer
20
- index.as :stored_sortable
21
- end
22
- property :part, predicate: ::RDF::Vocab::DC.hasPart
23
- property :based_near, predicate: ::RDF::Vocab::FOAF.based_near
24
- property :related_url, predicate: ::RDF::RDFS.seeAlso
25
- end
26
- end
27
-
28
- class RdfTest < ActiveFedora::Base
29
- has_subresource 'rdf', class_name: 'MyDatastream'
30
- end
31
- end
32
-
33
- subject(:my_datastream) { MyDatastream.new(described_class.id_to_uri('test:1')) }
34
-
35
- after do
36
- Object.send(:remove_const, :RdfTest)
37
- Object.send(:remove_const, :MyDatastream)
38
- Object.send(:remove_const, :FileVocabulary)
39
- end
40
-
41
- let(:remote_content) do
42
- <<EOF
43
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/created> "2010-12-31"^^<http://www.w3.org/2001/XMLSchema#date> .
44
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/title> "Title of work" .
45
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/publisher> "Penn State" .
46
- <#{ActiveFedora.fedora.host}/test/test:1> <http://xmlns.com/foaf/0.1/based_near> "New York, NY, US" .
47
- <#{ActiveFedora.fedora.host}/test/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://google.com/> .
48
- <#{ActiveFedora.fedora.host}/test/test:1/content> <http://purl.org/dc/terms/title> "Title of datastream" .
49
- EOF
50
- end
51
-
52
- it "delegates as_json to the fields" do
53
- my_datastream.title = "Title of work"
54
- expect(my_datastream.title.as_json).to eq ["Title of work"]
55
- expect(my_datastream.title.to_json).to eq "\[\"Title of work\"\]"
56
- end
57
-
58
- describe "serializing" do
59
- it "handles dates" do
60
- my_datastream.date_uploaded = [Date.parse('2012-11-02')]
61
- expect(my_datastream.date_uploaded.first).to be_kind_of Date
62
- end
63
- it "handles integers" do
64
- my_datastream.filesize = 12_345
65
- expect(my_datastream.filesize).to eq [12_345]
66
- expect(my_datastream.filesize.first).to be_kind_of Fixnum
67
- end
68
- end
69
-
70
- it "sets and recall values" do
71
- my_datastream.title = 'War and Peace'
72
- expect(my_datastream).to be_changed
73
- my_datastream.based_near = ["Moscow, Russia"]
74
- my_datastream.related_url = ["http://en.wikipedia.org/wiki/War_and_Peace"]
75
- my_datastream.part = ["this is a part"]
76
- my_datastream.save
77
- expect(my_datastream.title).to eq ['War and Peace']
78
- expect(my_datastream.based_near).to eq ["Moscow, Russia"]
79
- expect(my_datastream.related_url).to eq ["http://en.wikipedia.org/wiki/War_and_Peace"]
80
- expect(my_datastream.part).to eq ["this is a part"]
81
- end
82
-
83
- it "set, persist, and recall values" do
84
- my_datastream.title = 'War and Peace'
85
- my_datastream.based_near = ["Moscow, Russia"]
86
- my_datastream.related_url = ["http://en.wikipedia.org/wiki/War_and_Peace"]
87
- my_datastream.part = ["this is a part"]
88
- my_datastream.save
89
-
90
- loaded = MyDatastream.new(my_datastream.uri)
91
- expect(loaded.title).to eq ['War and Peace']
92
- expect(loaded.based_near).to eq ['Moscow, Russia']
93
- expect(loaded.related_url).to eq ['http://en.wikipedia.org/wiki/War_and_Peace']
94
- expect(loaded.part).to eq ['this is a part']
95
- end
96
-
97
- it "sets multiple values" do
98
- my_datastream.part = ["part 1", "part 2"]
99
- my_datastream.save
100
-
101
- loaded = MyDatastream.new(my_datastream.uri)
102
- expect(loaded.part).to contain_exactly 'part 1', 'part 2'
103
- end
104
-
105
- it "appends values" do
106
- my_datastream.part = ["thing 1"]
107
- my_datastream.save
108
-
109
- my_datastream.part << "thing 2"
110
- expect(my_datastream.part).to contain_exactly "thing 1", "thing 2"
111
- end
112
-
113
- it "is able to save a blank document" do
114
- my_datastream.title = ""
115
- my_datastream.save
116
- end
117
-
118
- it "loads n-triples into the graph" do
119
- ntrip = '<http://oregondigital.org/ns/62> <http://purl.org/dc/terms/type> "Image" .
120
- <http://oregondigital.org/ns/62> <http://purl.org/dc/terms/spatial> "Benton County (Ore.)" .
121
- '
122
- my_datastream.content = ntrip
123
- expect(my_datastream.graph.statements.to_a).to contain_exactly(*RDF::NTriples::Reader.new(ntrip).statements.to_a)
124
- end
125
-
126
- describe "using rdf_subject" do
127
- before do
128
- # reopening existing class
129
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
130
- rdf_subject { |ds| RDF::URI.new("http://oregondigital.org/ns/#{parent_uri(ds).split('/')[-1].split(':')[1]}") }
131
- property :dctype, predicate: ::RDF::Vocab::DC.type
132
- end
133
- rdf_test.rdf.dctype = "Frog"
134
- rdf_test.save!
135
- end
136
-
137
- after do
138
- rdf_test.destroy
139
- end
140
-
141
- subject(:rdf_test) { RdfTest.new(id: '/test:99') }
142
-
143
- it "writes rdf with proper subjects" do
144
- rdf_test.reload
145
- expect(rdf_test.rdf.graph.dump(:ntriples)).to eq "<http://oregondigital.org/ns/99> <http://purl.org/dc/terms/type> \"Frog\" .\n"
146
- rdf_test.rdf.dctype == ['Frog']
147
- end
148
- end
149
-
150
- it "deletes values" do
151
- my_datastream.title = "Hamlet"
152
- my_datastream.related_url = ["http://psu.edu/"]
153
- my_datastream.related_url << "http://projecthydra.org/"
154
-
155
- expect(my_datastream.title).to eq ["Hamlet"]
156
- expect(my_datastream.related_url).to include("http://psu.edu/")
157
- expect(my_datastream.related_url).to include("http://projecthydra.org/")
158
-
159
- my_datastream.title = "" # empty string can be meaningful, don't assume delete.
160
- expect(my_datastream.title).to eq ['']
161
-
162
- my_datastream.title = nil
163
- my_datastream.related_url.delete("http://projecthydra.org/")
164
-
165
- expect(my_datastream.title).to eq []
166
- expect(my_datastream.related_url).to eq ["http://psu.edu/"]
167
- end
168
-
169
- it "deletes multiple values at once" do
170
- my_datastream.part = ["MacBeth"]
171
- my_datastream.part << "Hamlet"
172
- my_datastream.part << "Romeo & Juliet"
173
- expect(my_datastream.part).to include "MacBeth"
174
- my_datastream.part.subtract(["MacBeth", "Romeo & Juliet"])
175
- expect(my_datastream.part).to eq ["Hamlet"]
176
- expect(my_datastream.part.first).to eq "Hamlet"
177
- end
178
- it "ignores values to be deleted that do not exist" do
179
- my_datastream.part = ["title1", "title2", "title3"]
180
- my_datastream.part.subtract(["title2", "title4", "title6"])
181
- expect(my_datastream.part).to contain_exactly "title1", "title3"
182
- end
183
-
184
- describe "term proxy methods" do
185
- before(:each) do
186
- class TitleDatastream < ActiveFedora::NtriplesRDFDatastream
187
- property :title, predicate: ::RDF::Vocab::DC.title
188
- end
189
- end
190
- subject(:title_datastream) { TitleDatastream.new }
191
- before { title_datastream.title = ["title1", "title2", "title3"] }
192
-
193
- after(:each) do
194
- Object.send(:remove_const, :TitleDatastream)
195
- end
196
-
197
- it "supports the count method to determine # of values" do
198
- expect(title_datastream.title.count).to eq 3
199
- end
200
- it "iterates over multiple values" do
201
- expect(title_datastream.title).to respond_to(:each)
202
- end
203
- it "evaluates equality predictably" do
204
- expect(title_datastream.title).to contain_exactly "title1", "title2", "title3"
205
- end
206
- it "supports the empty? method" do
207
- expect(title_datastream.title).to_not be_empty
208
- title_datastream.title.subtract(["title1", "title2", "title3"])
209
- expect(title_datastream.title).to be_empty
210
- end
211
- it "supports the each method" do
212
- expect(title_datastream.title.respond_to?(:each)).to eq true
213
- end
214
- end
215
- end