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,38 +0,0 @@
1
- <xml>
2
- <fields>
3
- <system_create_date>2008-07-02T05:09:42.015Z</system_create_date>
4
- <system_modified_date>2008-09-29T21:21:52.892Z</system_modified_date>
5
- <active_fedora_model_field>OralHistory</active_fedora_model_field>
6
- <id>changeme:14527</id>
7
- <subject_heading>subject heading</subject_heading>
8
- <type>type</type>
9
- <rights>rights</rights>
10
- <publisher>publisher</publisher>
11
- <creation_date>creation date</creation_date>
12
- <identifier>jwa:sample_id</identifier>
13
- <format>format</format>
14
- <extent>extent</extent>
15
- <language>language</language>
16
- <description>description</description>
17
- <title>title</title>
18
- <medium>medium</medium>
19
- <spatial_coverage>spatial coverage</spatial_coverage>
20
- <alt_title>alt_title</alt_title>
21
- <temporal_coverage>temporal coverage</temporal_coverage>
22
- <subject>subject</subject>
23
- <creator>creator</creator>
24
- <abstract>abstract</abstract>
25
- <other_contributors>Sally Ride</other_contributors>
26
- <transcript_editor>Transcript Editor</transcript_editor>
27
- <restrictions>None</restrictions>
28
- <bio>Biographic info</bio>
29
- <series>My Series</series>
30
- <notes>My Note</notes>
31
- <location>location</location>
32
- <hard_copy_availability>Yes</hard_copy_availability>
33
- <narrator>Narrator</narrator>
34
- <hard_copy_location>Archives</hard_copy_location>
35
- <interviewer>Interviewer</interviewer>
36
- </fields>
37
- <content/>
38
- </xml>
@@ -1,35 +0,0 @@
1
- <doc>
2
- <field name="system_create_date">2008-07-02T05:09:42.015Z</field>
3
- <field name="system_modified_date">2008-09-29T21:21:52.892Z</field>
4
- <field name="active_fedora_model_field">OralHistory</field>
5
- <field name="id">changeme:13919</field>
6
- <field name="subject_heading_field">subject heading</field>
7
- <field name="type_field">type</field>
8
- <field name="rights_text">rights</field>
9
- <field name="publisher_field">publisher</field>
10
- <field name="creation_date">creation date</field>
11
- <field name="identifier_field">jwa:sample_id</field>
12
- <field name="format_field">format</field>
13
- <field name="extent_field">extent</field>
14
- <field name="language_field">language</field>
15
- <field name="description_field">description</field>
16
- <field name="title_field">title</field>
17
- <field name="medium_field">medium</field>
18
- <field name="spatial_coverage_field">spatial coverage</field>
19
- <field name="alt_title_field">alt_title</field>
20
- <field name="temporal_coverage_field">temporal coverage</field>
21
- <field name="subject_field">subject</field>
22
- <field name="creator_field">creator</field>
23
- <field name="abstract_text">abstract</field>
24
- <field name="other_contributors_field">Sally Ride</field>
25
- <field name="transcript_editor_text">Transcript Editor</field>
26
- <field name="restrictions_text">None</field>
27
- <field name="bio_field">Biographic info</field>
28
- <field name="series_field">My Series</field>
29
- <field name="notes_text">My Note</field>
30
- <field name="location_field">location</field>
31
- <field name="hard_copy_availability_text">Yes</field>
32
- <field name="narrator_field">Narrator</field>
33
- <field name="hard_copy_location_text">Archives</field>
34
- <field name="interviewer_integer">Interviewer</field>
35
- </doc>
@@ -1,2 +0,0 @@
1
- # require all of the files in the samples directory
2
- require 'samples/models/mods_article'
@@ -1,60 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::NomDatastream do
4
- describe "test" do
5
- subject {
6
- class MyNomDatastream < ActiveFedora::NomDatastream
7
- set_terminology do |t|
8
- t.a path: '//a', accessor: lambda { |x| x.text }, index: 'a_s'
9
- t.b path: '//b', index: 'b_s'
10
- end
11
- end
12
-
13
- MyNomDatastream.new
14
- }
15
- before do
16
- subject.content = '<root><a>123</a><b><c>asdf</c></b></root>'
17
- end
18
-
19
- it "works" do
20
- expect(subject.a).to include("123")
21
- end
22
-
23
- it "to_solrs" do
24
- expect(subject.to_solr['a_s']).to include('123')
25
- expect(subject.to_solr['b_s']).to include('asdf')
26
- end
27
- end
28
-
29
- describe "with options for .set_terminology" do
30
- subject {
31
- class TerminologyOptions < ActiveFedora::NomDatastream
32
- set_terminology(namespaces: {
33
- 'dc' => "http://purl.org/dc/elements/1.1/",
34
- 'dcterms' => "http://purl.org/dc/terms/"
35
- }) do |t|
36
- t.a path: 'a', xmlns: 'dc', accessor: lambda { |x| x.text }
37
- end
38
- end
39
-
40
- TerminologyOptions.new
41
- }
42
-
43
- before do
44
- subject.content = %(
45
- <root
46
- xmlns:dc="http://purl.org/dc/elements/1.1/"
47
- xmlns:dcterms="http://purl.org/dc/terms/"
48
- >
49
- <dc:a>123</dc:a>
50
- <dcterms:a>not-part-of-a</dcterms:a>
51
- <dcterms:b>abcd</dcterms:b>
52
- </root>
53
- )
54
- end
55
-
56
- it "scopes #a attribute to only the dc namespace" do
57
- expect(subject.a).to eq ["123"]
58
- end
59
- end
60
- end
@@ -1,170 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::NtriplesRDFDatastream do
4
- let(:remote_content) do
5
- <<EOF
6
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/created> "2010-12-31"^^<http://www.w3.org/2001/XMLSchema#date> .
7
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/title> "Title of work" .
8
- <#{ActiveFedora.fedora.host}/test/test:1> <http://purl.org/dc/terms/publisher> "Penn State" .
9
- <#{ActiveFedora.fedora.host}/test/test:1> <http://xmlns.com/foaf/0.1/based_near> "New York, NY, US" .
10
- <#{ActiveFedora.fedora.host}/test/test:1> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://google.com/> .
11
- <#{ActiveFedora.fedora.host}/test/test:1/content> <http://purl.org/dc/terms/title> "Title of datastream" .
12
- EOF
13
- end
14
-
15
- describe "an instance with content" do
16
- before do
17
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
18
- property :created, predicate: ::RDF::Vocab::DC.created
19
- property :title, predicate: ::RDF::Vocab::DC.title
20
- property :publisher, predicate: ::RDF::Vocab::DC.publisher
21
- property :creator, predicate: ::RDF::Vocab::DC.creator
22
- property :educationLevel, predicate: ::RDF::Vocab::DC.educationLevel
23
- property :based_near, predicate: ::RDF::FOAF.based_near
24
- property :related_url, predicate: ::RDF::RDFS.seeAlso
25
- end
26
- @subject = MyDatastream.new(ActiveFedora::Base.id_to_uri('/test:1/descMetadata'))
27
- @subject.content = remote_content
28
- end
29
- after do
30
- Object.send(:remove_const, :MyDatastream)
31
- end
32
- it "has a subject" do
33
- expect(@subject.rdf_subject).to eq "#{ActiveFedora.fedora.host}/test/test:1"
34
- end
35
- it "has mime_type" do
36
- expect(@subject.mime_type).to eq 'text/plain'
37
- end
38
- it "has fields" do
39
- expect(@subject.created).to eq [Date.parse('2010-12-31')]
40
- expect(@subject.title).to eq ["Title of work"]
41
- expect(@subject.publisher).to eq ["Penn State"]
42
- expect(@subject.based_near).to eq ["New York, NY, US"]
43
- expect(@subject.related_url.length).to eq 1
44
- expect(@subject.related_url.first.rdf_subject).to eq "http://google.com/"
45
- end
46
-
47
- it "is able to call enumerable methods on the fields" do
48
- expect(@subject.title.join(', ')).to eq "Title of work"
49
- expect(@subject.title.count).to eq 1
50
- expect(@subject.title.size).to eq 1
51
- expect(@subject.title[0]).to eq "Title of work"
52
- expect(@subject.title.to_a).to eq ["Title of work"]
53
- val = []
54
- @subject.title.each_with_index { |v, i| val << "#{i}. #{v}" }
55
- expect(val).to eq ["0. Title of work"]
56
- end
57
-
58
- it "returns fields that are not TermProxies" do
59
- expect(@subject.created).to be_kind_of Array
60
- end
61
- it "has method missing" do
62
- expect(lambda { @subject.frank }).to raise_exception NoMethodError
63
- end
64
-
65
- it "sets fields" do
66
- @subject.publisher = "St. Martin's Press"
67
- expect(@subject.publisher).to eq ["St. Martin's Press"]
68
- end
69
- it "sets rdf literal fields" do
70
- @subject.creator = RDF.Literal("Geoff Ryman")
71
- expect(@subject.creator).to eq ["Geoff Ryman"]
72
- end
73
- it "appends fields" do
74
- @subject.publisher << "St. Martin's Press"
75
- expect(@subject.publisher).to eq ["Penn State", "St. Martin's Press"]
76
- end
77
- it "deletes fields" do
78
- @subject.related_url.delete(RDF::URI("http://google.com/"))
79
- expect(@subject.related_url).to eq []
80
- end
81
- end
82
-
83
- describe "some dummy instances" do
84
- before do
85
- @one = ActiveFedora::RDFDatastream.new
86
- @two = ActiveFedora::RDFDatastream.new
87
- end
88
- it "generates predictable prexies" do
89
- expect(@one.send(:apply_prefix, "baz", 'myFoobar')).to eq 'my_foobar__baz'
90
- expect(@two.send(:apply_prefix, "baz", 'myQuix')).to eq 'my_quix__baz'
91
- end
92
- end
93
-
94
- describe "an instance with a custom subject" do
95
- before do
96
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
97
- rdf_subject { |ds| "#{ActiveFedora.fedora.host}/test/#{ds.id}/content" }
98
- property :created, predicate: ::RDF::Vocab::DC.created
99
- property :title, predicate: ::RDF::Vocab::DC.title
100
- property :publisher, predicate: ::RDF::Vocab::DC.publisher
101
- property :based_near, predicate: ::RDF::FOAF.based_near
102
- property :related_url, predicate: ::RDF::RDFS.seeAlso
103
- end
104
- @subject = MyDatastream.new
105
- allow(@subject).to receive(:id).and_return 'test:1'
106
- allow(@subject).to receive(:new_record?).and_return false
107
- allow(@subject).to receive(:remote_content).and_return remote_content
108
- end
109
-
110
- after do
111
- Object.send(:remove_const, :MyDatastream)
112
- end
113
-
114
- it "has fields" do
115
- expect(@subject.title).to eq ["Title of datastream"]
116
- end
117
-
118
- it "has a custom subject" do
119
- expect(@subject.rdf_subject).to eq "#{ActiveFedora.fedora.host}/test/test:1/content"
120
- end
121
- end
122
-
123
- describe "a new instance" do
124
- before do
125
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
126
- property :publisher, predicate: ::RDF::Vocab::DC.publisher
127
- end
128
- @subject = MyDatastream.new
129
- end
130
-
131
- after do
132
- Object.send(:remove_const, :MyDatastream)
133
- end
134
-
135
- it "supports to_s method" do
136
- expect(@subject.publisher.to_s).to eq [].to_s
137
- @subject.publisher = "Bob"
138
- expect(@subject.publisher.to_s).to eq ["Bob"].to_s
139
- @subject.publisher << "Jim"
140
- expect(@subject.publisher.to_s).to eq ["Bob", "Jim"].to_s
141
- end
142
- end
143
-
144
- describe "solr integration" do
145
- before(:all) do
146
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
147
- end
148
- end
149
-
150
- after(:all) do
151
- Object.send(:remove_const, :MyDatastream)
152
- end
153
-
154
- before(:each) do
155
- @subject = MyDatastream.new
156
- @subject.content = File.new('spec/fixtures/solr_rdf_descMetadata.nt').read
157
- @subject.serialize
158
- end
159
-
160
- it "provides .to_solr and return a SolrDocument" do
161
- expect(@subject).to respond_to(:to_solr)
162
- expect(@subject.to_solr).to be_kind_of(Hash)
163
- end
164
-
165
- it "optionally allows you to provide the Solr::Document to add fields to and return that document when done" do
166
- doc = {}
167
- expect(@subject.to_solr(doc)).to eq doc
168
- end
169
- end
170
- end
@@ -1,294 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::OmDatastream do
4
- subject { described_class.new }
5
- it { should be_metadata }
6
-
7
- it "includes the Solrizer::XML::TerminologyBasedSolrizer for .to_solr support" do
8
- expect(described_class.included_modules).to include(OM::XML::TerminologyBasedSolrizer)
9
- end
10
-
11
- describe '#new' do
12
- it 'loads xml from blob if provided' do
13
- test_ds1 = described_class.new
14
- test_ds1.content = "<xml><foo/></xml>"
15
- expect(test_ds1.ng_xml.to_xml).to be_equivalent_to("<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n")
16
- end
17
-
18
- it "initializes from #xml_template if no xml is provided" do
19
- expect(described_class).to receive(:xml_template).and_return("<fake template/>")
20
- n = described_class.new
21
- expect(n.ng_xml).to be_equivalent_to("<fake template/>")
22
- end
23
- end
24
-
25
- describe "#prefix" do
26
- subject { described_class.new }
27
- it "reflects the dsid" do
28
- expect(subject.send(:prefix, 'descMetadata')).to eq "desc_metadata__"
29
- end
30
- end
31
-
32
- describe '#xml_template' do
33
- subject { described_class.xml_template.to_xml }
34
- it "returns an empty xml document" do
35
- expect(subject).to be_equivalent_to("<?xml version=\"1.0\"?>\n<xml/>\n")
36
- end
37
- end
38
-
39
- describe "to_solr" do
40
- describe "with a dsid" do
41
- subject { described_class.new.to_solr }
42
- it { should be_empty }
43
- end
44
-
45
- describe "when prefix is set" do
46
- before do
47
- class MyDatastream < ActiveFedora::OmDatastream
48
- set_terminology do |t|
49
- t.root(path: "mods")
50
- t.title(index_as: [:stored_searchable])
51
- end
52
-
53
- def prefix(_)
54
- "foo__"
55
- end
56
- end
57
- subject.title = 'Science'
58
- end
59
- after do
60
- Object.send(:remove_const, :MyDatastream)
61
- end
62
- subject { MyDatastream.new }
63
- it "uses the prefix" do
64
- expect(subject.to_solr).to have_key('foo__title_tesim')
65
- end
66
- it "does not prefix fields that aren't defined by this datastream" do
67
- expect(subject.to_solr('id' => 'test:123')).to have_key('id')
68
- end
69
- end
70
- end
71
-
72
- describe ".update_indexed_attributes" do
73
- before(:each) do
74
- @mods_ds = Hydra::ModsArticleDatastream.new
75
- @mods_ds.content = fixture(File.join("mods_articles", "mods_article1.xml")).read
76
- end
77
-
78
- it "applies submitted hash to corresponding datastream field values" do
79
- result = @mods_ds.update_indexed_attributes([{ ":person" => "0" }, "role"] => { "0" => "role1", "1" => "role2", "2" => "role3" })
80
- expect(result).to eq("person_0_role" => ["role1", "role2", "role3"])
81
- expect(@mods_ds.property_values('//oxns:name[@type="personal"][1]/oxns:role')).to eq ["role1", "role2", "role3"]
82
- end
83
- it "supports single-value arguments (as opposed to a hash of values with array indexes as keys)" do
84
- # In other words, { "fubar"=>"dork" } should have the same effect as { "fubar"=>{"0"=>"dork"} }
85
- result = @mods_ds.update_indexed_attributes([{ ":person" => "0" }, "role"] => "the role")
86
- expect(result).to eq("person_0_role" => ["the role"])
87
- expect(@mods_ds.term_values('//oxns:name[@type="personal"][1]/oxns:role').first).to eq "the role"
88
- end
89
- it "does nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!" do
90
- xml_before = @mods_ds.to_xml
91
- expect(ActiveFedora::Base.logger).to receive(:warn).with "WARNING: Hydra::ModsArticleDatastream ignoring {\"fubar\" => \"the role\"} because \"fubar\" is a String (only valid OM Term Pointers will be used). Make sure your html has the correct field_selector tags in it."
92
- expect(@mods_ds.update_indexed_attributes("fubar" => "the role")).to eq({})
93
- expect(@mods_ds.to_xml).to eq xml_before
94
- end
95
- it "does nothing if there is no accessor corresponding to the given field key" do
96
- xml_before = @mods_ds.to_xml
97
- expect(@mods_ds.update_indexed_attributes([{ "fubar" => "0" }] => "the role")).to eq({})
98
- expect(@mods_ds.to_xml).to eq xml_before
99
- end
100
-
101
- ### Examples copied over form metadata_datastream_spec
102
-
103
- it "works for text fields" do
104
- att = { [{ "person" => "0" }, "description"] => { "-1" => "mork", "1" => "york" } }
105
- result = @mods_ds.update_indexed_attributes(att)
106
- expect(result).to eq("person_0_description" => ["mork", "york"])
107
- expect(@mods_ds.get_values([{ person: 0 }, :description])).to eq ['mork', 'york']
108
- att = { [{ "person" => "0" }, "description"] => { "-1" => "dork" } }
109
- result2 = @mods_ds.update_indexed_attributes(att)
110
- expect(result2).to eq("person_0_description" => ["dork"])
111
- expect(@mods_ds.get_values([{ person: 0 }, :description])).to eq ['dork']
112
- end
113
-
114
- it "allows deleting of values and should delete values so that to_xml does not return emtpy nodes" do
115
- att = { [{ "person" => "0" }, "description"] => { "0" => "york", "1" => "mangle", "2" => "mork" } }
116
- @mods_ds.update_indexed_attributes(att)
117
- expect(@mods_ds.get_values([{ "person" => "0" }, "description"])).to eq ['york', 'mangle', 'mork']
118
-
119
- @mods_ds.update_indexed_attributes([{ "person" => "0" }, { "description" => '1' }] => nil)
120
- expect(@mods_ds.get_values([{ "person" => "0" }, "description"])).to eq ['york', 'mork']
121
-
122
- @mods_ds.update_indexed_attributes([{ "person" => "0" }, { "description" => '0' }] => :delete)
123
- expect(@mods_ds.get_values([{ "person" => "0" }, "description"])).to eq ['mork']
124
- end
125
-
126
- it "sets changed to true" do
127
- expect(@mods_ds.get_values([{ title_info: 0 }, :main_title])).to eq ["ARTICLE TITLE", "TITLE OF HOST JOURNAL"]
128
- @mods_ds.update_indexed_attributes [{ "title_info" => "0" }, "main_title"] => { "-1" => "mork" }
129
- expect(@mods_ds).to be_changed
130
- end
131
- end
132
-
133
- describe ".get_values" do
134
- before(:each) do
135
- @mods_ds = Hydra::ModsArticleDatastream.new
136
- @mods_ds.content = fixture(File.join("mods_articles", "mods_article1.xml")).read
137
- end
138
-
139
- it "calls lookup with field_name and return the text values from each resulting node" do
140
- expect(@mods_ds).to receive(:term_values).with("--my xpath--").and_return(["value1", "value2"])
141
- expect(@mods_ds.get_values("--my xpath--")).to eq ["value1", "value2"]
142
- end
143
- it "assumes that field_names that are strings are xpath queries" do
144
- expect(described_class).to receive(:accessor_xpath).never
145
- expect(@mods_ds).to receive(:term_values).with("--my xpath--").and_return(["abstract1", "abstract2"])
146
- expect(@mods_ds.get_values("--my xpath--")).to eq ["abstract1", "abstract2"]
147
- end
148
- end
149
-
150
- describe '.save' do
151
- let(:base_path) { '/foo' }
152
-
153
- let(:ldp_source) { Ldp::Resource.new(mock_client, nil, nil, base_path) }
154
-
155
- let(:conn_stubs) do
156
- Faraday::Adapter::Test::Stubs.new do |stub|
157
- stub.post(base_path) { [200, { 'Last-Modified' => 'Tue, 22 Jul 2014 02:23:32 GMT' }] }
158
- end
159
- end
160
-
161
- let(:mock_conn) do
162
- Faraday.new do |builder|
163
- builder.adapter :test, conn_stubs do |_stub|
164
- end
165
- end
166
- end
167
-
168
- let :mock_client do
169
- Ldp::Client.new mock_conn
170
- end
171
-
172
- before do
173
- allow(subject).to receive(:ldp_source).and_return(ldp_source)
174
- end
175
-
176
- it "persists the product of .to_xml in fedora" do
177
- subject.serialize!
178
- subject.save
179
- expect(subject.mime_type).to eq 'text/xml'
180
- end
181
- end
182
-
183
- describe 'setting content' do
184
- subject { described_class.new }
185
- before { subject.content = "<a />" }
186
-
187
- it "updates the content" do
188
- expect(subject.content).to eq "<?xml version=\"1.0\"?>\n<a/>"
189
- end
190
-
191
- it "marks the object as changed" do
192
- expect(subject).to be_changed
193
- end
194
-
195
- it "update ngxml and mark the xml as loaded" do
196
- expect(subject.ng_xml.to_xml).to match(/<a\/>/)
197
- expect(subject.xml_loaded).to be true
198
- end
199
- end
200
-
201
- describe 'ng_xml=' do
202
- let(:sample_raw_xml) { "<foo><xmlelement/></foo>" }
203
-
204
- subject { described_class.new }
205
-
206
- it "parses raw xml for you" do
207
- subject.ng_xml = sample_raw_xml
208
- expect(subject.ng_xml).to be_kind_of Nokogiri::XML::Document
209
- expect(subject.ng_xml.to_xml).to be_equivalent_to(sample_raw_xml)
210
- end
211
-
212
- it "alwayses set a document when an Element is passed" do
213
- subject.ng_xml = Nokogiri::XML(sample_raw_xml).xpath('//xmlelement').first
214
- expect(subject.ng_xml).to be_kind_of Nokogiri::XML::Document
215
- expect(subject.ng_xml.to_xml).to be_equivalent_to("<xmlelement/>")
216
- end
217
-
218
- it "marks the datastream as changed" do
219
- expect {
220
- subject.ng_xml = sample_raw_xml
221
- }.to change { subject.changed? }.from(false).to(true)
222
- end
223
- end
224
-
225
- describe '.to_xml' do
226
- let(:doc) { Nokogiri::XML::Document.parse("<text_document/>") }
227
-
228
- it "ng_xml.to_xmls" do
229
- allow(subject).to receive(:ng_xml).and_return(doc)
230
- expect(subject.to_xml).to eq "<?xml version=\"1.0\"?>\n<text_document/>"
231
- end
232
-
233
- it 'accepts an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
234
- expect(doc.root).to receive(:add_child) # .with(test_ds.ng_xml.root)
235
- subject.to_xml(doc)
236
- end
237
-
238
- context "with some existing content" do
239
- before do
240
- subject.content = "<test_xml/>"
241
- end
242
- it 'accepts an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
243
- expected_result = "<test_document><foo/><test_xml/></test_document>"
244
- doc = Nokogiri::XML::Document.parse("<test_document><foo/></test_document>")
245
- result = subject.to_xml(doc)
246
- expect(doc).to be_equivalent_to expected_result
247
- expect(result).to be_equivalent_to expected_result
248
- end
249
-
250
- it 'adds to root of Nokogiri::XML::Documents, but add directly to the elements if a Nokogiri::XML::Node is passed in' do
251
- doc = Nokogiri::XML::Document.parse("<test_document/>")
252
- el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
253
- expect(subject.to_xml(doc)).to be_equivalent_to "<test_document><test_xml/></test_document>"
254
- expect(subject.to_xml(el)).to be_equivalent_to "<test_element/>"
255
- end
256
- end
257
- end
258
-
259
- describe '.update_values' do
260
- subject { described_class.new }
261
-
262
- before { subject.content = fixture(File.join("mods_articles", "mods_article1.xml")).read }
263
-
264
- it "updates a value internally call OM::XML::TermValueOperators::update_values if internal_solr_doc is not set" do
265
- expect(subject).to receive(:om_update_values)
266
- subject.update_values([{ ":person" => "0" }, "role", "text"] => { "0" => "role1", "1" => "role2", "2" => "role3" })
267
- end
268
-
269
- it "sets changed to true" do
270
- subject.update_values([{ ":person" => "0" }, "role", "text"] => { "0" => "role1", "1" => "role2", "2" => "role3" })
271
- expect(subject).to be_changed
272
- end
273
- end
274
-
275
- describe "an instance that exists in the datastore, but hasn't been loaded" do
276
- before do
277
- class MyObj < ActiveFedora::Base
278
- has_subresource 'descMetadata', class_name: 'Hydra::ModsArticleDatastream'
279
- end
280
- @obj = MyObj.new
281
- @obj.descMetadata.title = 'Foobar'
282
- @obj.save
283
- end
284
- after do
285
- @obj.destroy
286
- Object.send(:remove_const, :MyObj)
287
- end
288
- subject { @obj.reload.descMetadata }
289
- it "does not load the descMetadata datastream when calling content_changed?" do
290
- expect(@obj).to_not receive(:content)
291
- expect(subject).to_not be_content_changed
292
- end
293
- end
294
- end