active-fedora 11.0.0.rc1 → 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 (159) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +2 -7
  4. data/.rubocop_todo.yml +40 -9
  5. data/.solr_wrapper +6 -0
  6. data/README.md +1 -3
  7. data/active-fedora.gemspec +5 -9
  8. data/lib/active_fedora/associations/collection_association.rb +1 -1
  9. data/lib/active_fedora/associations/contained_finder.rb +2 -2
  10. data/lib/active_fedora/associations/has_many_association.rb +1 -1
  11. data/lib/active_fedora/associations/has_subresource_association.rb +2 -2
  12. data/lib/active_fedora/attribute_assignment.rb +0 -1
  13. data/lib/active_fedora/attributes.rb +1 -1
  14. data/lib/active_fedora/base.rb +3 -7
  15. data/lib/active_fedora/change_set.rb +6 -2
  16. data/lib/active_fedora/containers/container.rb +1 -1
  17. data/lib/active_fedora/core.rb +22 -25
  18. data/lib/active_fedora/fedora_attributes.rb +1 -1
  19. data/lib/active_fedora/file.rb +1 -1
  20. data/lib/active_fedora/indexing_service.rb +0 -4
  21. data/lib/active_fedora/orders/ordered_list.rb +2 -2
  22. data/lib/active_fedora/querying.rb +1 -1
  23. data/lib/active_fedora/railtie.rb +2 -2
  24. data/lib/active_fedora/rake_support.rb +1 -1
  25. data/lib/active_fedora/rdf.rb +0 -1
  26. data/lib/active_fedora/relation/delegation.rb +4 -0
  27. data/lib/active_fedora/solr_hit.rb +0 -4
  28. data/lib/active_fedora/solr_query_builder.rb +16 -12
  29. data/lib/active_fedora/version.rb +1 -1
  30. data/lib/active_fedora.rb +0 -10
  31. data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +11 -0
  32. data/lib/generators/active_fedora/config/solr/templates/solr_wrapper_test.yml +1 -1
  33. data/spec/config_helper.rb +1 -1
  34. data/spec/integration/associations_spec.rb +17 -18
  35. data/spec/integration/attached_files_spec.rb +18 -8
  36. data/spec/integration/attributes_spec.rb +12 -16
  37. data/spec/integration/autosave_association_spec.rb +6 -6
  38. data/spec/integration/base_spec.rb +3 -3
  39. data/spec/integration/collection_association_spec.rb +2 -5
  40. data/spec/integration/date_time_properties_spec.rb +1 -2
  41. data/spec/integration/direct_container_spec.rb +8 -8
  42. data/spec/integration/directly_contains_one_association_spec.rb +11 -13
  43. data/spec/integration/eradicate_spec.rb +1 -1
  44. data/spec/integration/fedora_solr_sync_spec.rb +2 -2
  45. data/spec/integration/file_fixity_spec.rb +6 -8
  46. data/spec/integration/file_spec.rb +32 -34
  47. data/spec/integration/generators/solr_generator_spec.rb +7 -10
  48. data/spec/integration/has_many_associations_spec.rb +6 -8
  49. data/spec/integration/indexing_spec.rb +1 -1
  50. data/spec/integration/indirect_container_spec.rb +8 -9
  51. data/spec/integration/json_serialization_spec.rb +4 -4
  52. data/spec/integration/query_result_builder_spec.rb +9 -21
  53. data/spec/integration/rdf_nested_attributes_spec.rb +6 -6
  54. data/spec/integration/relation_delegation_spec.rb +8 -10
  55. data/spec/integration/relation_spec.rb +13 -16
  56. data/spec/integration/solr_hit_spec.rb +4 -4
  57. data/spec/integration/versionable_spec.rb +73 -327
  58. data/spec/spec_helper.rb +52 -10
  59. data/spec/unit/active_fedora_spec.rb +1 -1
  60. data/spec/unit/aggregation/list_source_spec.rb +37 -37
  61. data/spec/unit/aggregation/ordered_reader_spec.rb +4 -4
  62. data/spec/unit/association_hash_spec.rb +17 -31
  63. data/spec/unit/attached_files_spec.rb +35 -32
  64. data/spec/unit/attributes_spec.rb +25 -25
  65. data/spec/unit/base_active_model_spec.rb +8 -8
  66. data/spec/unit/base_cma_spec.rb +1 -1
  67. data/spec/unit/base_extra_spec.rb +7 -22
  68. data/spec/unit/base_spec.rb +14 -20
  69. data/spec/unit/callback_spec.rb +2 -2
  70. data/spec/unit/change_set_spec.rb +5 -5
  71. data/spec/unit/checksum_spec.rb +2 -2
  72. data/spec/unit/code_configurator_spec.rb +1 -1
  73. data/spec/unit/core_spec.rb +62 -26
  74. data/spec/unit/default_model_mapper_spec.rb +6 -6
  75. data/spec/unit/fedora_spec.rb +2 -2
  76. data/spec/unit/file_configurator_spec.rb +96 -96
  77. data/spec/unit/file_path_builder_spec.rb +1 -1
  78. data/spec/unit/file_spec.rb +61 -61
  79. data/spec/unit/files_hash_spec.rb +9 -9
  80. data/spec/unit/finder_methods_spec.rb +3 -3
  81. data/spec/unit/has_and_belongs_to_many_association_spec.rb +13 -14
  82. data/spec/unit/has_many_association_spec.rb +28 -13
  83. data/spec/unit/indexers/global_indexer_spec.rb +6 -6
  84. data/spec/unit/indexing_service_spec.rb +5 -5
  85. data/spec/unit/indexing_spec.rb +6 -6
  86. data/spec/unit/inheritance_spec.rb +11 -7
  87. data/spec/unit/loadable_from_json_spec.rb +4 -4
  88. data/spec/unit/logger_spec.rb +1 -1
  89. data/spec/unit/model_classifier_spec.rb +5 -5
  90. data/spec/unit/ordered_spec.rb +142 -142
  91. data/spec/unit/orders/list_node_spec.rb +21 -21
  92. data/spec/unit/orders/ordered_list_spec.rb +96 -96
  93. data/spec/unit/orders/reflection_spec.rb +4 -4
  94. data/spec/unit/pathing_spec.rb +4 -4
  95. data/spec/unit/persistence_spec.rb +28 -28
  96. data/spec/unit/property_spec.rb +2 -2
  97. data/spec/unit/query_spec.rb +10 -10
  98. data/spec/unit/rdf/indexing_service_spec.rb +26 -26
  99. data/spec/unit/readonly_spec.rb +5 -4
  100. data/spec/unit/reflection_spec.rb +3 -3
  101. data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +9 -9
  102. data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +9 -9
  103. data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +9 -9
  104. data/spec/unit/schema_indexing_strategy_spec.rb +5 -5
  105. data/spec/unit/serializers_spec.rb +3 -4
  106. data/spec/unit/solr_config_options_spec.rb +13 -16
  107. data/spec/unit/solr_hit_spec.rb +9 -9
  108. data/spec/unit/solr_service_spec.rb +4 -10
  109. data/spec/unit/sparql_insert_spec.rb +2 -2
  110. data/spec/unit/validations_spec.rb +9 -9
  111. data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +3 -2
  112. data/spec/unit/with_metadata/metadata_node_spec.rb +3 -2
  113. metadata +17 -118
  114. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  115. data/lib/active_fedora/datastreams.rb +0 -6
  116. data/lib/active_fedora/nom_datastream.rb +0 -73
  117. data/lib/active_fedora/om_datastream.rb +0 -118
  118. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  119. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  120. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  121. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -173
  122. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  123. data/solr/config/_rest_managed.json +0 -3
  124. data/solr/config/admin-extra.html +0 -31
  125. data/solr/config/elevate.xml +0 -36
  126. data/solr/config/mapping-ISOLatin1Accent.txt +0 -246
  127. data/solr/config/protwords.txt +0 -21
  128. data/solr/config/schema.xml +0 -372
  129. data/solr/config/scripts.conf +0 -24
  130. data/solr/config/solrconfig.xml +0 -311
  131. data/solr/config/spellings.txt +0 -2
  132. data/solr/config/stopwords.txt +0 -58
  133. data/solr/config/stopwords_en.txt +0 -58
  134. data/solr/config/synonyms.txt +0 -31
  135. data/solr/config/xslt/example.xsl +0 -132
  136. data/solr/config/xslt/example_atom.xsl +0 -67
  137. data/solr/config/xslt/example_rss.xsl +0 -66
  138. data/solr/config/xslt/luke.xsl +0 -337
  139. data/spec/fixtures/damsObjectModel.xml +0 -38
  140. data/spec/fixtures/dublin_core_rdf_descMetadata.nt +0 -13
  141. data/spec/fixtures/mixed_rdf_descMetadata.nt +0 -7
  142. data/spec/fixtures/mods_articles/mods_article1.xml +0 -98
  143. data/spec/fixtures/solr_rdf_descMetadata.nt +0 -7
  144. data/spec/integration/complex_rdf_datastream_spec.rb +0 -227
  145. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -180
  146. data/spec/integration/ntriples_datastream_spec.rb +0 -215
  147. data/spec/integration/om_datastream_spec.rb +0 -78
  148. data/spec/samples/hydra-mods_article_datastream.rb +0 -515
  149. data/spec/samples/models/mods_article.rb +0 -9
  150. data/spec/samples/oral_history_sample.xml +0 -38
  151. data/spec/samples/oral_history_xml.xml +0 -35
  152. data/spec/samples/samples.rb +0 -2
  153. data/spec/unit/nom_datastream_spec.rb +0 -60
  154. data/spec/unit/ntriples_datastream_spec.rb +0 -167
  155. data/spec/unit/om_datastream_spec.rb +0 -294
  156. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  157. data/spec/unit/rdf_datastream_spec.rb +0 -84
  158. data/spec/unit/rdf_resource_datastream_spec.rb +0 -208
  159. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -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,167 +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::Vocab::FOAF.based_near
24
- property :related_url, predicate: ::RDF::Vocab::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 "has method missing" do
59
- expect(lambda { @subject.frank }).to raise_exception NoMethodError
60
- end
61
-
62
- it "sets fields" do
63
- @subject.publisher = "St. Martin's Press"
64
- expect(@subject.publisher).to eq ["St. Martin's Press"]
65
- end
66
- it "sets rdf literal fields" do
67
- @subject.creator = RDF.Literal("Geoff Ryman")
68
- expect(@subject.creator).to eq ["Geoff Ryman"]
69
- end
70
- it "appends fields" do
71
- @subject.publisher << "St. Martin's Press"
72
- expect(@subject.publisher).to contain_exactly "Penn State", "St. Martin's Press"
73
- end
74
- it "deletes fields" do
75
- @subject.related_url.delete(RDF::URI("http://google.com/"))
76
- expect(@subject.related_url).to eq []
77
- end
78
- end
79
-
80
- describe "some dummy instances" do
81
- before do
82
- @one = ActiveFedora::RDFDatastream.new
83
- @two = ActiveFedora::RDFDatastream.new
84
- end
85
- it "generates predictable prexies" do
86
- expect(@one.send(:apply_prefix, "baz", 'myFoobar')).to eq 'my_foobar__baz'
87
- expect(@two.send(:apply_prefix, "baz", 'myQuix')).to eq 'my_quix__baz'
88
- end
89
- end
90
-
91
- describe "an instance with a custom subject" do
92
- before do
93
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
94
- rdf_subject { |ds| "#{ActiveFedora.fedora.host}/test/#{ds.id}/content" }
95
- property :created, predicate: ::RDF::Vocab::DC.created
96
- property :title, predicate: ::RDF::Vocab::DC.title
97
- property :publisher, predicate: ::RDF::Vocab::DC.publisher
98
- property :based_near, predicate: ::RDF::Vocab::FOAF.based_near
99
- property :related_url, predicate: ::RDF::Vocab::RDFS.seeAlso
100
- end
101
- @subject = MyDatastream.new
102
- allow(@subject).to receive(:id).and_return 'test:1'
103
- allow(@subject).to receive(:new_record?).and_return false
104
- allow(@subject).to receive(:remote_content).and_return remote_content
105
- end
106
-
107
- after do
108
- Object.send(:remove_const, :MyDatastream)
109
- end
110
-
111
- it "has fields" do
112
- expect(@subject.title).to eq ["Title of datastream"]
113
- end
114
-
115
- it "has a custom subject" do
116
- expect(@subject.rdf_subject).to eq "#{ActiveFedora.fedora.host}/test/test:1/content"
117
- end
118
- end
119
-
120
- describe "a new instance" do
121
- before do
122
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
123
- property :publisher, predicate: ::RDF::Vocab::DC.publisher
124
- end
125
- @subject = MyDatastream.new
126
- end
127
-
128
- after do
129
- Object.send(:remove_const, :MyDatastream)
130
- end
131
-
132
- xit "supports to_s method" do
133
- expect(@subject.publisher.to_s).to eq [].to_s
134
- @subject.publisher = "Bob"
135
- expect(@subject.publisher.to_s).to eq ["Bob"].to_s
136
- @subject.publisher << "Jim"
137
- expect(@subject.publisher.to_s).to eq ["Bob", "Jim"].to_s
138
- end
139
- end
140
-
141
- describe "solr integration" do
142
- before(:all) do
143
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
144
- end
145
- end
146
-
147
- after(:all) do
148
- Object.send(:remove_const, :MyDatastream)
149
- end
150
-
151
- before(:each) do
152
- @subject = MyDatastream.new
153
- @subject.content = File.new('spec/fixtures/solr_rdf_descMetadata.nt').read
154
- @subject.serialize
155
- end
156
-
157
- it "provides .to_solr and return a SolrDocument" do
158
- expect(@subject).to respond_to(:to_solr)
159
- expect(@subject.to_solr).to be_kind_of(Hash)
160
- end
161
-
162
- it "optionally allows you to provide the Solr::Document to add fields to and return that document when done" do
163
- doc = {}
164
- expect(@subject.to_solr(doc)).to eq doc
165
- end
166
- end
167
- 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
@@ -1,119 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ActiveFedora::QualifiedDublinCoreDatastream do
4
- DC_ELEMENTS = [:contributor, :coverage, :creator, :date, :description, :identifier, :language, :publisher, :relation, :rights, :source].freeze
5
-
6
- let(:sample_xml) do "<dc xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:dcterms='http://purl.org/dc/terms/'>
7
- <dcterms:type xsi:type='DCMITYPE'>sound</dcterms:type>
8
- <dcterms:medium>medium</dcterms:medium>
9
- <dcterms:rights>rights</dcterms:rights>
10
- <dcterms:language>English</dcterms:language>
11
- <dcterms:temporal>tmp</dcterms:temporal>
12
- <dcterms:subject>kw1</dcterms:subject>
13
- <dcterms:subject>kw2</dcterms:subject>
14
- <dcterms:creator>creator</dcterms:creator>
15
- <dcterms:creator>creator</dcterms:creator>
16
- <dcterms:contributor>contributor</dcterms:contributor>
17
- <dcterms:coverage>coverage</dcterms:coverage>
18
- <dcterms:identifier>identifier</dcterms:identifier>
19
- <dcterms:relation>relation</dcterms:relation>
20
- <dcterms:source>source</dcterms:source>
21
- <dcterms:title>title</dcterms:title>
22
- <dcterms:extent>extent</dcterms:extent>
23
- <dcterms:format>audio/x-wav</dcterms:format>
24
- <dcterms:subject xsi:type='LCSH'>sh1</dcterms:subject>
25
- <dcterms:subject xsi:type='LCSH'>sh2</dcterms:subject>
26
- <dcterms:spatial>sp1</dcterms:spatial>
27
- <dcterms:spatial>sp2</dcterms:spatial>
28
- <dcterms:publisher>jwa</dcterms:publisher>
29
- <dcterms:alternative>alt</dcterms:alternative>
30
- <dcterms:description>desc</dcterms:description>
31
- <dcterms:date>datestr</dcterms:date>
32
- </dc>"
33
- end
34
- before do
35
- @test_ds = described_class.new
36
- @test_ds.content = sample_xml
37
- end
38
-
39
- it "creates the right number of fields" do
40
- expect(ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS.size).to eq 54
41
- end
42
-
43
- it "has unmodifiable constants" do
44
- expect { ActiveFedora::QualifiedDublinCoreDatastream::DCTERMS << :foo }.to raise_error(RuntimeError, /can't modify frozen array/i)
45
- end
46
-
47
- it "defaults dc elements to :multiple=>true" do
48
- @test_ds.fields.values.each do |s|
49
- expect(s.key?(:multiple)).to be true
50
- end
51
- end
52
-
53
- describe '#new' do
54
- it 'provides #new' do
55
- expect(described_class).to respond_to(:new)
56
- end
57
-
58
- describe "model methods" do
59
- DC_ELEMENTS.each do |el|
60
- it "should respond to getters and setters for #{el} element" do
61
- pending if el == :type
62
- value = "Hey #{el}"
63
- @test_ds.send("#{el}=", value)
64
- expect(@test_ds.send(el).first).to eq value # Looking at first because creator has 2 nodes
65
- end
66
- end
67
- end
68
- end
69
-
70
- describe '.to_xml' do
71
- it 'outputs the fields hash as Qualified Dublin Core XML' do
72
- @test_ds = described_class.new
73
-
74
- @test_ds.field :publisher
75
- @test_ds.field :creator
76
- @test_ds.field :title
77
-
78
- @test_ds.publisher = ["publisher1"]
79
- @test_ds.creator = ["creator1", "creator2"]
80
- @test_ds.title = ["title1"]
81
-
82
- expect(@test_ds.to_xml).to be_equivalent_to('
83
- <dc xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
84
- <dcterms:publisher>publisher1</dcterms:publisher>
85
- <dcterms:creator>creator1</dcterms:creator>
86
- <dcterms:creator>creator2</dcterms:creator>
87
- <dcterms:title>title1</dcterms:title>
88
- </dc>')
89
- end
90
- end
91
-
92
- describe "#to_solr" do
93
- it "has title" do
94
- @test_ds = described_class.new
95
- @test_ds.title = "War and Peace"
96
- solr = @test_ds.to_solr
97
- expect(solr[ActiveFedora.index_field_mapper.solr_name('title', type: :string)]).to eq "War and Peace"
98
- end
99
- end
100
-
101
- describe 'custom fields' do
102
- subject { described_class.new }
103
- it 'grabs the term' do
104
- sample_xml = "<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><dcterms:cust>custom</dcterms:cust></dc>"
105
- subject.content = sample_xml
106
- subject.field :cust
107
- expect(subject.cust).to eq ['custom']
108
- end
109
- end
110
-
111
- describe "#field should accept :path option" do
112
- subject { described_class.new }
113
- it "is able to map :dc_type to the path 'type'" do
114
- subject.content = sample_xml
115
- subject.field :dc_type, :string, path: "type", multiple: true
116
- expect(subject.dc_type).to eq ['sound']
117
- end
118
- end
119
- end