active-fedora 11.0.0.rc6 → 11.0.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/active-fedora.gemspec +0 -3
  3. data/lib/active_fedora.rb +0 -10
  4. data/lib/active_fedora/associations/has_many_association.rb +1 -1
  5. data/lib/active_fedora/attributes.rb +1 -1
  6. data/lib/active_fedora/base.rb +3 -7
  7. data/lib/active_fedora/querying.rb +1 -1
  8. data/lib/active_fedora/rdf.rb +0 -1
  9. data/lib/active_fedora/version.rb +1 -1
  10. data/spec/integration/attached_files_spec.rb +14 -4
  11. data/spec/integration/file_spec.rb +22 -23
  12. data/spec/integration/versionable_spec.rb +0 -254
  13. data/spec/spec_helper.rb +0 -7
  14. data/spec/unit/attached_files_spec.rb +10 -7
  15. data/spec/unit/base_spec.rb +3 -1
  16. data/spec/unit/has_many_association_spec.rb +23 -8
  17. data/spec/unit/inheritance_spec.rb +11 -7
  18. data/spec/unit/model_classifier_spec.rb +1 -1
  19. data/spec/unit/rdf/indexing_service_spec.rb +9 -9
  20. data/spec/unit/solr_config_options_spec.rb +12 -15
  21. metadata +2 -67
  22. data/lib/active_fedora/datastreams.rb +0 -6
  23. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  24. data/lib/active_fedora/nom_datastream.rb +0 -73
  25. data/lib/active_fedora/om_datastream.rb +0 -118
  26. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  27. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  28. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  29. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -173
  30. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  31. data/spec/integration/complex_rdf_datastream_spec.rb +0 -227
  32. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -180
  33. data/spec/integration/ntriples_datastream_spec.rb +0 -215
  34. data/spec/integration/om_datastream_spec.rb +0 -78
  35. data/spec/samples/hydra-mods_article_datastream.rb +0 -515
  36. data/spec/samples/models/mods_article.rb +0 -9
  37. data/spec/samples/samples.rb +0 -2
  38. data/spec/unit/nom_datastream_spec.rb +0 -60
  39. data/spec/unit/ntriples_datastream_spec.rb +0 -167
  40. data/spec/unit/om_datastream_spec.rb +0 -294
  41. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  42. data/spec/unit/rdf_datastream_spec.rb +0 -84
  43. data/spec/unit/rdf_resource_datastream_spec.rb +0 -208
  44. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -1,9 +0,0 @@
1
- require "active-fedora"
2
- require_relative '../hydra-mods_article_datastream.rb'
3
-
4
- # This Model is used to load & index the test:fixture_mods_article1 fixture for use in tests.
5
- #
6
- # See lib/samples/sample_thing.rb for a fuller, annotated example of an ActiveFedora Model
7
- class ModsArticle < ActiveFedora::Base
8
- has_subresource "descMetadata", class_name: 'Hydra::ModsArticleDatastream'
9
- end
@@ -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(:datastream) {
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
- datastream.content = '<root><a>123</a><b><c>asdf</c></b></root>'
17
- end
18
-
19
- it "works" do
20
- expect(datastream.a).to include("123")
21
- end
22
-
23
- it "to_solrs" do
24
- expect(datastream.to_solr['a_s']).to include('123')
25
- expect(datastream.to_solr['b_s']).to include('asdf')
26
- end
27
- end
28
-
29
- describe "with options for .set_terminology" do
30
- subject(:datastream) {
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
- datastream.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(datastream.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(:datastream) { 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(:datastream) { described_class.new }
27
- it "reflects the dsid" do
28
- expect(datastream.send(:prefix, 'descMetadata')).to eq "desc_metadata__"
29
- end
30
- end
31
-
32
- describe '#xml_template' do
33
- subject(:datastream) { described_class.xml_template.to_xml }
34
- it "returns an empty xml document" do
35
- expect(datastream).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
- datastream.title = 'Science'
58
- end
59
- after do
60
- Object.send(:remove_const, :MyDatastream)
61
- end
62
- subject(:datastream) { MyDatastream.new }
63
- it "uses the prefix" do
64
- expect(datastream.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(datastream.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(datastream).to receive(:ldp_source).and_return(ldp_source)
174
- end
175
-
176
- it "persists the product of .to_xml in fedora" do
177
- datastream.serialize!
178
- datastream.save
179
- expect(datastream.mime_type).to eq 'text/xml'
180
- end
181
- end
182
-
183
- describe 'setting content' do
184
- subject(:datastream) { described_class.new }
185
- before { datastream.content = "<a />" }
186
-
187
- it "updates the content" do
188
- expect(datastream.content).to eq "<?xml version=\"1.0\"?>\n<a/>"
189
- end
190
-
191
- it "marks the object as changed" do
192
- expect(datastream).to be_changed
193
- end
194
-
195
- it "update ngxml and mark the xml as loaded" do
196
- expect(datastream.ng_xml.to_xml).to match(/<a\/>/)
197
- expect(datastream.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(:datastream) { described_class.new }
205
-
206
- it "parses raw xml for you" do
207
- datastream.ng_xml = sample_raw_xml
208
- expect(datastream.ng_xml).to be_kind_of Nokogiri::XML::Document
209
- expect(datastream.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
- datastream.ng_xml = Nokogiri::XML(sample_raw_xml).xpath('//xmlelement').first
214
- expect(datastream.ng_xml).to be_kind_of Nokogiri::XML::Document
215
- expect(datastream.ng_xml.to_xml).to be_equivalent_to("<xmlelement/>")
216
- end
217
-
218
- it "marks the datastream as changed" do
219
- expect {
220
- datastream.ng_xml = sample_raw_xml
221
- }.to change { datastream.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(datastream).to receive(:ng_xml).and_return(doc)
230
- expect(datastream.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
- datastream.to_xml(doc)
236
- end
237
-
238
- context "with some existing content" do
239
- before do
240
- datastream.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 = datastream.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(datastream.to_xml(doc)).to be_equivalent_to "<test_document><test_xml/></test_document>"
254
- expect(datastream.to_xml(el)).to be_equivalent_to "<test_element/>"
255
- end
256
- end
257
- end
258
-
259
- describe '.update_values' do
260
- subject(:datastream) { described_class.new }
261
-
262
- before { datastream.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(datastream).to receive(:om_update_values)
266
- datastream.update_values([{ ":person" => "0" }, "role", "text"] => { "0" => "role1", "1" => "role2", "2" => "role3" })
267
- end
268
-
269
- it "sets changed to true" do
270
- datastream.update_values([{ ":person" => "0" }, "role", "text"] => { "0" => "role1", "1" => "role2", "2" => "role3" })
271
- expect(datastream).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(:datastream) { @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(datastream).to_not be_content_changed
292
- end
293
- end
294
- end