active-fedora 10.2.1 → 11.0.0

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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +6 -7
  4. data/.rubocop_todo.yml +55 -0
  5. data/active-fedora.gemspec +6 -10
  6. data/lib/active_fedora/aggregation/list_source.rb +2 -0
  7. data/lib/active_fedora/associations/association_scope.rb +1 -1
  8. data/lib/active_fedora/associations/builder/aggregation.rb +1 -1
  9. data/lib/active_fedora/associations/builder/association.rb +1 -1
  10. data/lib/active_fedora/associations/builder/orders.rb +11 -3
  11. data/lib/active_fedora/associations/collection_association.rb +3 -3
  12. data/lib/active_fedora/associations/contained_finder.rb +2 -2
  13. data/lib/active_fedora/associations/has_many_association.rb +2 -2
  14. data/lib/active_fedora/associations/orders_association.rb +4 -0
  15. data/lib/active_fedora/associations/rdf.rb +2 -0
  16. data/lib/active_fedora/attribute_assignment.rb +0 -1
  17. data/lib/active_fedora/attribute_methods/dirty.rb +1 -1
  18. data/lib/active_fedora/attributes.rb +1 -1
  19. data/lib/active_fedora/base.rb +4 -8
  20. data/lib/active_fedora/change_set.rb +6 -2
  21. data/lib/active_fedora/core.rb +22 -27
  22. data/lib/active_fedora/fedora_attributes.rb +1 -1
  23. data/lib/active_fedora/file/streaming.rb +1 -1
  24. data/lib/active_fedora/indexing.rb +0 -17
  25. data/lib/active_fedora/indexing_service.rb +0 -9
  26. data/lib/active_fedora/loadable_from_json.rb +12 -1
  27. data/lib/active_fedora/nested_attributes.rb +2 -2
  28. data/lib/active_fedora/orders/list_node.rb +2 -2
  29. data/lib/active_fedora/orders/ordered_list.rb +7 -3
  30. data/lib/active_fedora/orders/target_proxy.rb +4 -0
  31. data/lib/active_fedora/querying.rb +1 -1
  32. data/lib/active_fedora/railtie.rb +2 -2
  33. data/lib/active_fedora/rdf/persistence.rb +1 -0
  34. data/lib/active_fedora/rdf.rb +0 -1
  35. data/lib/active_fedora/relation/delegation.rb +4 -0
  36. data/lib/active_fedora/solr_hit.rb +0 -13
  37. data/lib/active_fedora/solr_query_builder.rb +17 -13
  38. data/lib/active_fedora/version.rb +1 -1
  39. data/lib/active_fedora.rb +0 -12
  40. data/lib/generators/active_fedora/model/model_generator.rb +1 -1
  41. data/lib/generators/active_fedora/model/templates/model.rb.erb +4 -4
  42. data/lib/tasks/active_fedora_dev.rake +1 -1
  43. data/spec/config_helper.rb +1 -1
  44. data/spec/integration/associations_spec.rb +23 -24
  45. data/spec/integration/attached_files_spec.rb +18 -8
  46. data/spec/integration/attributes_spec.rb +12 -16
  47. data/spec/integration/autosave_association_spec.rb +6 -6
  48. data/spec/integration/base_spec.rb +3 -3
  49. data/spec/integration/basic_contains_association_spec.rb +1 -1
  50. data/spec/integration/clean_connection_spec.rb +1 -1
  51. data/spec/integration/collection_association_spec.rb +2 -5
  52. data/spec/integration/date_time_properties_spec.rb +1 -17
  53. data/spec/integration/direct_container_spec.rb +12 -12
  54. data/spec/integration/directly_contains_one_association_spec.rb +11 -13
  55. data/spec/integration/fedora_solr_sync_spec.rb +2 -2
  56. data/spec/integration/file_fixity_spec.rb +6 -8
  57. data/spec/integration/file_spec.rb +32 -34
  58. data/spec/integration/has_and_belongs_to_many_associations_spec.rb +5 -5
  59. data/spec/integration/has_many_associations_spec.rb +9 -11
  60. data/spec/integration/indexing_spec.rb +2 -2
  61. data/spec/integration/indirect_container_spec.rb +11 -12
  62. data/spec/integration/json_serialization_spec.rb +4 -4
  63. data/spec/integration/query_result_builder_spec.rb +9 -21
  64. data/spec/integration/rdf_nested_attributes_spec.rb +7 -7
  65. data/spec/integration/relation_delegation_spec.rb +8 -10
  66. data/spec/integration/relation_spec.rb +13 -16
  67. data/spec/integration/scoped_query_spec.rb +3 -3
  68. data/spec/integration/solr_hit_spec.rb +4 -15
  69. data/spec/integration/versionable_spec.rb +73 -327
  70. data/spec/integration/with_metadata_spec.rb +1 -1
  71. data/spec/spec_helper.rb +52 -10
  72. data/spec/unit/active_fedora_spec.rb +1 -1
  73. data/spec/unit/aggregation/list_source_spec.rb +37 -37
  74. data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
  75. data/spec/unit/association_hash_spec.rb +17 -31
  76. data/spec/unit/attached_files_spec.rb +35 -32
  77. data/spec/unit/attributes_spec.rb +25 -25
  78. data/spec/unit/base_active_model_spec.rb +8 -8
  79. data/spec/unit/base_cma_spec.rb +1 -1
  80. data/spec/unit/base_extra_spec.rb +7 -22
  81. data/spec/unit/base_spec.rb +16 -23
  82. data/spec/unit/callback_spec.rb +2 -2
  83. data/spec/unit/change_set_spec.rb +5 -5
  84. data/spec/unit/checksum_spec.rb +2 -2
  85. data/spec/unit/code_configurator_spec.rb +1 -1
  86. data/spec/unit/core_spec.rb +62 -26
  87. data/spec/unit/default_model_mapper_spec.rb +6 -6
  88. data/spec/unit/fedora_spec.rb +3 -4
  89. data/spec/unit/file_configurator_spec.rb +96 -96
  90. data/spec/unit/file_path_builder_spec.rb +1 -1
  91. data/spec/unit/file_spec.rb +61 -61
  92. data/spec/unit/files_hash_spec.rb +9 -9
  93. data/spec/unit/filter_spec.rb +3 -3
  94. data/spec/unit/finder_methods_spec.rb +3 -3
  95. data/spec/unit/forbidden_attributes_protection_spec.rb +2 -2
  96. data/spec/unit/has_and_belongs_to_many_association_spec.rb +14 -15
  97. data/spec/unit/has_many_association_spec.rb +26 -11
  98. data/spec/unit/indexers/global_indexer_spec.rb +6 -6
  99. data/spec/unit/indexing_service_spec.rb +5 -5
  100. data/spec/unit/indexing_spec.rb +6 -6
  101. data/spec/unit/inheritance_spec.rb +11 -7
  102. data/spec/unit/loadable_from_json_spec.rb +4 -4
  103. data/spec/unit/logger_spec.rb +1 -1
  104. data/spec/unit/model_classifier_spec.rb +5 -5
  105. data/spec/unit/ordered_spec.rb +144 -147
  106. data/spec/unit/orders/list_node_spec.rb +21 -21
  107. data/spec/unit/orders/ordered_list_spec.rb +96 -96
  108. data/spec/unit/orders/reflection_spec.rb +4 -4
  109. data/spec/unit/pathing_spec.rb +4 -4
  110. data/spec/unit/persistence_spec.rb +28 -28
  111. data/spec/unit/property_spec.rb +2 -2
  112. data/spec/unit/query_spec.rb +6 -6
  113. data/spec/unit/rdf/indexing_service_spec.rb +29 -29
  114. data/spec/unit/readonly_spec.rb +5 -4
  115. data/spec/unit/reflection_spec.rb +3 -3
  116. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
  117. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
  118. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
  119. data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
  120. data/spec/unit/serializers_spec.rb +3 -4
  121. data/spec/unit/solr_config_options_spec.rb +13 -16
  122. data/spec/unit/solr_hit_spec.rb +9 -9
  123. data/spec/unit/solr_service_spec.rb +4 -10
  124. data/spec/unit/sparql_insert_spec.rb +2 -2
  125. data/spec/unit/validations_spec.rb +9 -9
  126. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
  127. data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
  128. metadata +17 -91
  129. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  130. data/lib/active_fedora/datastreams.rb +0 -6
  131. data/lib/active_fedora/nom_datastream.rb +0 -73
  132. data/lib/active_fedora/om_datastream.rb +0 -118
  133. data/lib/active_fedora/profile_indexing_service.rb +0 -11
  134. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  135. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  136. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  137. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -167
  138. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  139. data/lib/active_fedora/solr_instance_loader.rb +0 -47
  140. data/spec/fixtures/damsObjectModel.xml +0 -38
  141. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
  142. data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
  143. data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
  144. data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
  145. data/spec/integration/complex_rdf_datastream_spec.rb +0 -228
  146. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -179
  147. data/spec/integration/ntriples_datastream_spec.rb +0 -203
  148. data/spec/integration/om_datastream_spec.rb +0 -78
  149. data/spec/integration/solr_instance_loader_spec.rb +0 -156
  150. data/spec/samples/hydra-mods_article_datastream.rb +0 -517
  151. data/spec/samples/models/mods_article.rb +0 -9
  152. data/spec/samples/oral_history_sample.xml +0 -38
  153. data/spec/samples/oral_history_xml.xml +0 -35
  154. data/spec/samples/samples.rb +0 -2
  155. data/spec/unit/nom_datastream_spec.rb +0 -60
  156. data/spec/unit/ntriples_datastream_spec.rb +0 -170
  157. data/spec/unit/om_datastream_spec.rb +0 -294
  158. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  159. data/spec/unit/rdf_datastream_spec.rb +0 -84
  160. data/spec/unit/rdf_resource_datastream_spec.rb +0 -204
  161. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -1,228 +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.first.label).to eq ["Alternator"]
68
- expect(ds.parts.last.label).to eq ["Crankshaft"]
69
- end
70
-
71
- it "is able to clear complex objects" do
72
- comp1 = SpecDatastream::Component.new nil, ds.graph
73
- comp1.label = ["Alternator"]
74
- comp2 = SpecDatastream::Component.new nil, ds.graph
75
- comp2.label = ["Crankshaft"]
76
- ds.parts = [comp1, comp2]
77
- ds.parts = []
78
- expect(ds.parts).to eq []
79
- end
80
-
81
- it "loads complex objects" do
82
- ds.content = <<END
83
- _:g70350851837440 <http://purl.org/dc/terms/title> "Alternator" .
84
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851837440 .
85
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/hasPart> _:g70350851833380 .
86
- _:g70350851833380 <http://purl.org/dc/terms/title> "Crankshaft" .
87
- END
88
- expect(ds.parts.first.label).to eq ["Alternator"]
89
- end
90
-
91
- it "builds complex objects when a parent node doesn't exist" do
92
- part = ds.parts.build
93
- expect(part).to be_kind_of SpecDatastream::Component
94
- part.label = "Wheel bearing"
95
- expect(ds.parts.first.label).to eq ['Wheel bearing']
96
- end
97
-
98
- it "does not create a child node when hitting the accessor" do
99
- ds.parts
100
- expect(ds.parts.first).to be_nil
101
- expect(ds.serialize).to eq ''
102
- end
103
-
104
- it "builds complex objects when a parent node exists" do
105
- part = ds.parts.build
106
- expect(part).to be_kind_of SpecDatastream::Component
107
- part.label = "Wheel bearing"
108
- expect(ds.parts.first.label).to eq ['Wheel bearing']
109
- end
110
-
111
- describe "#first_or_create" do
112
- it "returns a result if the predicate exists" do
113
- part1 = ds.parts.build
114
- ds.parts.build
115
- expect(ds.parts.first_or_create).to eq part1
116
- end
117
-
118
- it "creates a new result if the predicate doesn't exist" do
119
- expect(ds.parts).to eq []
120
- part = ds.parts.first_or_create(label: 'Front control arm bushing')
121
- expect(part.label).to eq ['Front control arm bushing']
122
- expect(ds.parts).to eq [part]
123
- end
124
- end
125
- end
126
-
127
- describe "with type" do
128
- describe "one class per assertion" do
129
- before(:each) do
130
- class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
131
- property :mediator, predicate: ::RDF::Vocab::DC.mediator, class_name: 'MediatorUser'
132
-
133
- class MediatorUser < ActiveTriples::Resource
134
- configure type: ::RDF::Vocab::DC.AgentClass
135
- property :title, predicate: ::RDF::Vocab::DC.title
136
- end
137
- end
138
- end
139
-
140
- after(:each) do
141
- Object.send(:remove_const, :SpecDatastream)
142
- end
143
- let(:ds) { SpecDatastream.new("#{ActiveFedora.fedora.host}/test/test:124/descMd") }
144
-
145
- it "stores the type of complex objects when type is specified" do
146
- comp = SpecDatastream::MediatorUser.new nil, ds.graph
147
- comp.title = ["Doctor"]
148
- ds.mediator = comp
149
- expect(ds.mediator.first.type.first).to be_instance_of ::RDF::URI
150
- expect(ds.mediator.first.type.first.to_s).to eq "http://purl.org/dc/terms/AgentClass"
151
- expect(ds.mediator.first.title.first).to eq 'Doctor'
152
- end
153
-
154
- it "adds the type of complex object when it is not provided" do
155
- ds.content = <<END
156
- _:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Person" .
157
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
158
- END
159
- expect(ds.mediator.first.type.first.to_s).to eq "http://purl.org/dc/terms/AgentClass"
160
- end
161
-
162
- it "adds load the type of complex objects when provided (superceeding what is specified by the class)" do
163
- ds.content = <<END
164
- _:g70350851837440 <http://purl.org/dc/terms/title> "Mediation Orgainzation" .
165
- _:g70350851837440 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.ebu.ch/metadata/ontologies/ebucore#Organisation> .
166
- <#{ActiveFedora.fedora.host}/test/test:124> <http://purl.org/dc/terms/mediator> _:g70350851837440 .
167
- END
168
- expect(ds.mediator.first.type.first.to_s).to eq "http://www.ebu.ch/metadata/ontologies/ebucore#Organisation"
169
- end
170
- end
171
-
172
- describe "shared assertion to different classes" do
173
- before(:each) do
174
- class EbuCore < RDF::Vocabulary("http://www.ebu.ch/metadata/ontologies/ebucore#")
175
- property :isEpisodeOf
176
- property :title
177
- end
178
-
179
- class SpecContainer < ActiveFedora::Base
180
- has_subresource :info, class_name: 'SpecDatastream'
181
- end
182
-
183
- class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
184
- property :series, predicate: EbuCore.isEpisodeOf, class_name: 'Series'
185
- property :program, predicate: EbuCore.isEpisodeOf, class_name: 'Program'
186
-
187
- class Series < ActiveTriples::Resource
188
- configure type: 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
189
- property :title, predicate: EbuCore.title
190
- end
191
-
192
- class Program < ActiveTriples::Resource
193
- configure type: 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
194
- property :title, predicate: EbuCore.title
195
- end
196
- end
197
- end
198
-
199
- after(:each) do
200
- Object.send(:remove_const, :SpecDatastream)
201
- Object.send(:remove_const, :SpecContainer)
202
- end
203
-
204
- let(:parent) { SpecContainer.new id: '124' }
205
- let(:file) { parent.info }
206
-
207
- it "stores the type of complex objects when type is specified" do
208
- series = SpecDatastream::Series.new nil, file.graph
209
- series.title = ["renovating bathrooms"]
210
- file.series = series
211
-
212
- program = SpecDatastream::Program.new nil, file.graph
213
- program.title = ["This old House"]
214
- file.program = program
215
-
216
- expect(file.program.first.type.size).to eq 1
217
- expect(file.program.first.type.first.to_s).to eq 'http://www.ebu.ch/metadata/ontologies/ebucore#Programme'
218
- expect(file.series.first.type.size).to eq 1
219
- expect(file.series.first.type.first.to_s).to eq 'http://www.ebu.ch/metadata/ontologies/ebucore#Series'
220
- end
221
-
222
- it "creates an object of the correct type" do
223
- expect(file.program.build).to be_kind_of SpecDatastream::Program
224
- expect(file.series.build).to be_kind_of SpecDatastream::Series
225
- end
226
- end
227
- end
228
- end
@@ -1,179 +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 { 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
- }
96
- end
97
-
98
- describe "on lists" do
99
- subject { ComplexRDFDatastream::PersonalName.new(nil) }
100
- it "accepts a hash" do
101
- subject.elementList_attributes = [{ topicElement_attributes: { '0' => { elementValue: "Quantum Behavior" }, '1' => { elementValue: "Wave Function" } } }]
102
- expect(subject.elementList.first[0].elementValue).to eq ["Quantum Behavior"]
103
- expect(subject.elementList.first[1].elementValue).to eq ["Wave Function"]
104
- end
105
- it "accepts an array" do
106
- subject.elementList_attributes = [{ topicElement_attributes: [{ elementValue: "Quantum Behavior" }, { elementValue: "Wave Function" }] }]
107
- expect(subject.elementList.first[0].elementValue).to eq ["Quantum Behavior"]
108
- expect(subject.elementList.first[1].elementValue).to eq ["Wave Function"]
109
- end
110
- end
111
-
112
- context "from nested objects" do
113
- before do
114
- # Replace the graph's contents with the Hash
115
- subject.attributes = params[:myResource]
116
- end
117
-
118
- it 'has attributes' do
119
- expect(subject.topic[0].elementList.first[0].elementValue).to eq ["Cosmology"]
120
- expect(subject.topic[1].elementList.first[0].elementValue).to eq ["Quantum Behavior"]
121
- expect(subject.personalName.first.elementList.first.fullNameElement).to eq ["Jefferson, Thomas"]
122
- expect(subject.personalName.first.elementList.first.dateNameElement).to eq ["1743-1826"]
123
- end
124
-
125
- it 'builds nodes with ids' do
126
- expect(subject.topic[0].elementList.first[0].rdf_subject).to eq 'http://library.ucsd.edu/ark:/20775/bb3333333x'
127
- expect(subject.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 { subject.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 { subject.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 { SpecDatastream.new }
158
- before do
159
- subject.attributes = { parts_attributes: [
160
- { label: 'Alternator' },
161
- { label: 'Distributor' },
162
- { label: 'Transmission' },
163
- { label: 'Fuel Filter' }] }
164
- end
165
- let(:replace_object_id) { subject.parts[1].rdf_subject.to_s }
166
- let(:remove_object_id) { subject.parts[3].rdf_subject.to_s }
167
-
168
- it "updates nested objects" do
169
- subject.parts_attributes = [{ id: replace_object_id, label: "Universal Joint" }, { label: "Oil Pump" }, { id: remove_object_id, _destroy: '1', label: "bar1 uno" }]
170
-
171
- expect(subject.parts.map { |p| p.label.first }).to eq ['Alternator', 'Universal Joint', 'Transmission', 'Oil Pump']
172
- end
173
- it "create a new object when the id is provided" do
174
- subject.parts_attributes = [{ id: 'http://example.com/part#1', label: "Universal Joint" }]
175
- expect(subject.parts.last.rdf_subject).to eq RDF::URI('http://example.com/part#1')
176
- end
177
- end
178
- end
179
- end
@@ -1,203 +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
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
10
- property :title, predicate: ::RDF::Vocab::DC.title
11
- property :date_uploaded, predicate: ::RDF::Vocab::DC.dateSubmitted
12
- property :filesize, predicate: FileVocabulary.size
13
- property :part, predicate: ::RDF::Vocab::DC.hasPart
14
- property :based_near, predicate: ::RDF::FOAF.based_near
15
- property :related_url, predicate: ::RDF::RDFS.seeAlso
16
- end
17
-
18
- class RdfTest < ActiveFedora::Base
19
- has_subresource 'rdf', class_name: 'MyDatastream'
20
- end
21
- end
22
-
23
- subject { MyDatastream.new(described_class.id_to_uri('test:1')) }
24
-
25
- after do
26
- Object.send(:remove_const, :RdfTest)
27
- Object.send(:remove_const, :MyDatastream)
28
- Object.send(:remove_const, :FileVocabulary)
29
- end
30
-
31
- let(:remote_content) do
32
- <<EOF
33
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/created> "2010-12-31"^^<http://www.w3.org/2001/XMLSchema#date> .
34
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/title> "Title of work" .
35
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/publisher> "Penn State" .
36
- <#{ActiveFedora.fedora.host}/test/test:1> <http://xmlns.com/foaf/0.1/based_near> "New York, NY, US" .
37
- <#{ActiveFedora.fedora.host}/test/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://google.com/> .
38
- <#{ActiveFedora.fedora.host}/test/test:1/content> <http://purl.org/dc/terms/title> "Title of datastream" .
39
- EOF
40
- end
41
-
42
- it "delegates as_json to the fields" do
43
- subject.title = "Title of work"
44
- expect(subject.title.as_json).to eq ["Title of work"]
45
- expect(subject.title.to_json).to eq "\[\"Title of work\"\]"
46
- end
47
-
48
- describe "serializing" do
49
- it "handles dates" do
50
- subject.date_uploaded = [Date.parse('2012-11-02')]
51
- expect(subject.date_uploaded.first).to be_kind_of Date
52
- end
53
- it "handles integers" do
54
- subject.filesize = 12_345
55
- expect(subject.filesize).to be_kind_of Array
56
- expect(subject.filesize.first).to be_kind_of Fixnum
57
- end
58
- end
59
-
60
- it "sets and recall values" do
61
- subject.title = 'War and Peace'
62
- expect(subject).to be_changed
63
- subject.based_near = ["Moscow, Russia"]
64
- subject.related_url = ["http://en.wikipedia.org/wiki/War_and_Peace"]
65
- subject.part = ["this is a part"]
66
- subject.save
67
- expect(subject.title).to eq ['War and Peace']
68
- expect(subject.based_near).to eq ["Moscow, Russia"]
69
- expect(subject.related_url).to eq ["http://en.wikipedia.org/wiki/War_and_Peace"]
70
- expect(subject.part).to eq ["this is a part"]
71
- end
72
-
73
- it "set, persist, and recall values" do
74
- subject.title = 'War and Peace'
75
- subject.based_near = ["Moscow, Russia"]
76
- subject.related_url = ["http://en.wikipedia.org/wiki/War_and_Peace"]
77
- subject.part = ["this is a part"]
78
- subject.save
79
-
80
- loaded = MyDatastream.new(subject.uri)
81
- expect(loaded.title).to eq ['War and Peace']
82
- expect(loaded.based_near).to eq ['Moscow, Russia']
83
- expect(loaded.related_url).to eq ['http://en.wikipedia.org/wiki/War_and_Peace']
84
- expect(loaded.part).to eq ['this is a part']
85
- end
86
-
87
- it "sets multiple values" do
88
- subject.part = ["part 1", "part 2"]
89
- subject.save
90
-
91
- loaded = MyDatastream.new(subject.uri)
92
- expect(loaded.part).to eq ['part 1', 'part 2']
93
- end
94
-
95
- it "appends values" do
96
- subject.part = ["thing 1"]
97
- subject.save
98
-
99
- subject.part << "thing 2"
100
- expect(subject.part).to eq ["thing 1", "thing 2"]
101
- end
102
-
103
- it "loads n-triples into the graph" do
104
- ntrip = '<http://oregondigital.org/ns/62> <http://purl.org/dc/terms/type> "Image" .
105
- <http://oregondigital.org/ns/62> <http://purl.org/dc/terms/spatial> "Benton County (Ore.)" .
106
- '
107
- subject.content = ntrip
108
- expect(subject.graph.dump(:ntriples)).to eq ntrip
109
- end
110
-
111
- describe "using rdf_subject" do
112
- before do
113
- # reopening existing class
114
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
115
- rdf_subject { |ds| RDF::URI.new("http://oregondigital.org/ns/#{parent_uri(ds).split('/')[-1].split(':')[1]}") }
116
- property :dctype, predicate: ::RDF::Vocab::DC.type
117
- end
118
- subject.rdf.dctype = "Frog"
119
- subject.save!
120
- end
121
-
122
- after do
123
- subject.destroy
124
- end
125
-
126
- subject { RdfTest.new(id: '/test:99') }
127
-
128
- it "writes rdf with proper subjects" do
129
- subject.reload
130
- expect(subject.rdf.graph.dump(:ntriples)).to eq "<http://oregondigital.org/ns/99> <http://purl.org/dc/terms/type> \"Frog\" .\n"
131
- subject.rdf.dctype == ['Frog']
132
- end
133
- end
134
-
135
- it "deletes values" do
136
- subject.title = "Hamlet"
137
- subject.related_url = ["http://psu.edu/"]
138
- subject.related_url << "http://projecthydra.org/"
139
-
140
- expect(subject.title).to eq ["Hamlet"]
141
- expect(subject.related_url).to include("http://psu.edu/")
142
- expect(subject.related_url).to include("http://projecthydra.org/")
143
-
144
- subject.title = "" # empty string can be meaningful, don't assume delete.
145
- expect(subject.title).to eq ['']
146
-
147
- subject.title = nil
148
- subject.related_url.delete("http://projecthydra.org/")
149
-
150
- expect(subject.title).to eq []
151
- expect(subject.related_url).to eq ["http://psu.edu/"]
152
- end
153
-
154
- it "deletes multiple values at once" do
155
- subject.part = ["MacBeth"]
156
- subject.part << "Hamlet"
157
- subject.part << "Romeo & Juliet"
158
- expect(subject.part.first).to eq "MacBeth"
159
- subject.part.delete("MacBeth", "Romeo & Juliet")
160
- expect(subject.part).to eq ["Hamlet"]
161
- expect(subject.part.first).to eq "Hamlet"
162
- end
163
- it "ignores values to be deleted that do not exist" do
164
- subject.part = ["title1", "title2", "title3"]
165
- subject.part.delete("title2", "title4", "title6")
166
- expect(subject.part).to eq ["title1", "title3"]
167
- end
168
-
169
- describe "term proxy methods" do
170
- before(:each) do
171
- class TitleDatastream < ActiveFedora::NtriplesRDFDatastream
172
- property :title, predicate: ::RDF::Vocab::DC.title
173
- end
174
- end
175
- subject { TitleDatastream.new }
176
- before { subject.title = ["title1", "title2", "title3"] }
177
-
178
- after(:each) do
179
- Object.send(:remove_const, :TitleDatastream)
180
- end
181
-
182
- it "supports the count method to determine # of values" do
183
- expect(subject.title.count).to eq 3
184
- end
185
- it "iterates over multiple values" do
186
- expect(subject.title).to respond_to(:each)
187
- end
188
- it "gets the first value" do
189
- expect(subject.title.first).to eq "title1"
190
- end
191
- it "evaluates equality predictably" do
192
- expect(subject.title).to eq ["title1", "title2", "title3"]
193
- end
194
- it "supports the empty? method" do
195
- expect(subject.title).to_not be_empty
196
- subject.title.delete("title1", "title2", "title3")
197
- expect(subject.title).to be_empty
198
- end
199
- it "supports the is_a? method" do
200
- expect(subject.title.is_a?(Array)).to eq true
201
- end
202
- end
203
- end
@@ -1,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::OmDatastream do
4
- before(:all) do
5
- class ModsArticle2 < ActiveFedora::Base
6
- # Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
7
- has_subresource "descMetadata", class_name: 'Hydra::ModsArticleDatastream'
8
- end
9
- end
10
-
11
- after(:all) do
12
- Object.send(:remove_const, :ModsArticle2)
13
- end
14
-
15
- let(:obj) { ModsArticle2.create.reload }
16
-
17
- after(:each) do
18
- obj.destroy
19
- end
20
-
21
- subject { obj.descMetadata }
22
-
23
- describe "#changed?" do
24
- it "is not changed when no fields have been set" do
25
- expect(subject).to_not be_content_changed
26
- end
27
- it "is changed when a field has been set" do
28
- subject.title = 'Foobar'
29
- expect(subject).to be_content_changed
30
- end
31
- it "is not changed if the new xml matches the old xml" do
32
- subject.content = subject.content
33
- expect(subject).to_not be_content_changed
34
- end
35
-
36
- it "is changed if there are minor differences in whitespace" do
37
- subject.content = "<a><b>1</b></a>"
38
- obj.save
39
- expect(subject).to_not be_content_changed
40
- subject.content = "<a>\n<b>1</b>\n</a>"
41
- expect(subject).to be_content_changed
42
- end
43
- end
44
-
45
- describe "empty datastream content" do
46
- it "does not break when there is empty datastream content" do
47
- subject.content = ""
48
- obj.save
49
- end
50
- end
51
-
52
- describe '.update_values' do
53
- before do
54
- subject.content = File.read(fixture('mods_articles/mods_article1.xml'))
55
- obj.save
56
- obj.reload
57
- end
58
-
59
- it "is not dirty after .update_values is saved" do
60
- obj.descMetadata.update_values([{ name: 0 }, { role: 0 }, :text] => "Funder")
61
- expect(obj.descMetadata).to be_content_changed
62
- obj.save
63
- expect(obj.descMetadata).to_not be_content_changed
64
- expect(obj.descMetadata.term_values({ name: 0 }, { role: 0 }, :text)).to eq ["Funder"]
65
- end
66
- end
67
-
68
- describe ".to_solr" do
69
- before do
70
- subject.journal.issue.publication_date = Date.parse('2012-11-02')
71
- obj.save!
72
- obj.reload
73
- end
74
- it "solrizes terms with :type=>'date' to *_dt solr terms" do
75
- expect(obj.to_solr[ActiveFedora.index_field_mapper.solr_name('desc_metadata__journal_issue_publication_date', type: :date)]).to eq ['2012-11-02T00:00:00Z']
76
- end
77
- end
78
- end