active-fedora 6.7.8 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +938 -0
- data/.travis.yml +5 -6
- data/Gemfile +3 -1
- data/Rakefile +7 -5
- data/active-fedora.gemspec +7 -8
- data/lib/active_fedora/om_datastream.rb +1 -0
- data/lib/active_fedora/rdf_xml_writer.rb +31 -62
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +232 -232
- data/spec/integration/attributes_spec.rb +11 -12
- data/spec/integration/auditable_spec.rb +10 -10
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delegating_spec.rb +14 -14
- data/spec/integration/delete_all_spec.rb +38 -42
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/full_featured_model_spec.rb +101 -101
- data/spec/integration/has_many_associations_spec.rb +24 -24
- data/spec/integration/model_spec.rb +30 -30
- data/spec/integration/nested_attribute_spec.rb +41 -41
- data/spec/integration/ntriples_datastream_spec.rb +107 -107
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +6 -6
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +24 -26
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +40 -41
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/rails3_test_app/config/application.rb +1 -1
- data/spec/rails3_test_app/config/environments/development.rb +0 -1
- data/spec/rails3_test_app/config/environments/production.rb +1 -1
- data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +7 -11
- data/spec/support/an_active_model.rb +2 -2
- data/spec/support/mock_fedora.rb +16 -17
- data/spec/unit/active_fedora_spec.rb +58 -58
- data/spec/unit/association_proxy_spec.rb +5 -7
- data/spec/unit/base_active_model_spec.rb +25 -26
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_delegate_spec.rb +80 -82
- data/spec/unit/base_delegate_to_spec.rb +37 -39
- data/spec/unit/base_extra_spec.rb +48 -48
- data/spec/unit/base_spec.rb +300 -300
- data/spec/unit/callback_spec.rb +19 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +16 -8
- data/spec/unit/content_model_spec.rb +60 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +57 -54
- data/spec/unit/datastreams_spec.rb +77 -77
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
- data/spec/unit/has_many_collection_spec.rb +9 -9
- data/spec/unit/inheritance_spec.rb +12 -13
- data/spec/unit/model_spec.rb +41 -51
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +112 -112
- data/spec/unit/om_datastream_spec.rb +233 -227
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +9 -17
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +188 -217
- data/spec/unit/rdf_datastream_spec.rb +28 -21
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +80 -104
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +75 -69
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +59 -59
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +27 -28
- data/spec/unit/solr_digital_object_spec.rb +21 -21
- data/spec/unit/solr_service_spec.rb +81 -81
- data/spec/unit/unsaved_digital_object_spec.rb +20 -20
- data/spec/unit/validations_spec.rb +21 -21
- metadata +70 -58
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -1,367 +1,373 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe ActiveFedora::OmDatastream do
|
3
|
-
|
4
3
|
before(:all) do
|
5
|
-
@sample_fields = {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
ActiveFedora::SolrService.solr_name(
|
16
|
-
ActiveFedora::SolrService.solr_name(
|
17
|
-
ActiveFedora::SolrService.solr_name(
|
18
|
-
ActiveFedora::SolrService.solr_name(
|
4
|
+
@sample_fields = {
|
5
|
+
publisher: { values: ['publisher1'], type: :string },
|
6
|
+
coverage: { values: %w(coverage1 coverage2), type: :text },
|
7
|
+
creation_date: { values: 'fake-date', type: :date },
|
8
|
+
mydate: { values: 'fake-date', type: :date },
|
9
|
+
empty_field: { values: {} }
|
10
|
+
}
|
11
|
+
@sample_raw_xml = '<foo><xmlelement/></foo>'
|
12
|
+
@solr_doc = {
|
13
|
+
'id' => 'mods_article1',
|
14
|
+
ActiveFedora::SolrService.solr_name('name_role_roleTerm', type: :string) => %w(creator submitter teacher),
|
15
|
+
ActiveFedora::SolrService.solr_name('name_0_role', type: :string) => "\r\ncreator\r\nsubmitter\r\n",
|
16
|
+
ActiveFedora::SolrService.solr_name('name_1_role', type: :string) => "\r\n teacher \r\n",
|
17
|
+
ActiveFedora::SolrService.solr_name('name_0_role_0_roleTerm', type: :string) => 'creator',
|
18
|
+
ActiveFedora::SolrService.solr_name('name_0_role_1_roleTerm', type: :string) => 'submitter',
|
19
|
+
ActiveFedora::SolrService.solr_name('name_1_role_0_roleTerm', type: :string) => ['teacher']
|
20
|
+
}
|
19
21
|
end
|
20
|
-
|
22
|
+
|
21
23
|
before(:each) do
|
22
24
|
@mock_inner = double('inner object')
|
23
|
-
@mock_repo
|
24
|
-
@mock_repo.stub(:
|
25
|
-
@mock_inner.
|
26
|
-
@mock_inner.
|
27
|
-
@mock_inner.stub(
|
28
|
-
@test_ds = ActiveFedora::OmDatastream.new(@mock_inner,
|
29
|
-
@test_ds.stub(
|
30
|
-
@test_ds.content=
|
31
|
-
@test_ds.stub(
|
25
|
+
@mock_repo = double('repository')
|
26
|
+
@mock_repo.stub(datastream_dissemination: 'My Content', config: {}, datastream_profile: {}, datastream: '')
|
27
|
+
allow(@mock_inner).to receive(:repository).and_return(@mock_repo)
|
28
|
+
allow(@mock_inner).to receive(:pid)
|
29
|
+
@mock_inner.stub(new?: false)
|
30
|
+
@test_ds = ActiveFedora::OmDatastream.new(@mock_inner, 'descMetadata')
|
31
|
+
@test_ds.stub(new?: false, profile: {}, datastream_content: '<test_xml/>')
|
32
|
+
@test_ds.content = '<test_xml/>'
|
33
|
+
@test_ds.stub(new?: false)
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#metadata?' do
|
37
|
+
subject { super().metadata? }
|
38
|
+
it { is_expected.to be_truthy }
|
32
39
|
end
|
33
|
-
|
34
|
-
its(:metadata?) { should be_true}
|
35
40
|
|
36
|
-
|
41
|
+
describe '#controlGroup' do
|
42
|
+
subject { super().controlGroup }
|
43
|
+
it { is_expected.to eq('M') }
|
44
|
+
end
|
37
45
|
|
38
|
-
it
|
39
|
-
ActiveFedora::OmDatastream.included_modules.
|
46
|
+
it 'should include the Solrizer::XML::TerminologyBasedSolrizer for .to_solr support' do
|
47
|
+
expect(ActiveFedora::OmDatastream.included_modules).to include(OM::XML::TerminologyBasedSolrizer)
|
40
48
|
end
|
41
|
-
|
49
|
+
|
42
50
|
describe '#new' do
|
43
51
|
it 'should provide #new' do
|
44
|
-
ActiveFedora::OmDatastream.
|
45
|
-
@test_ds.ng_xml.
|
52
|
+
expect(ActiveFedora::OmDatastream).to respond_to(:new)
|
53
|
+
expect(@test_ds.ng_xml).to be_instance_of(Nokogiri::XML::Document)
|
46
54
|
end
|
47
55
|
it 'should load xml from blob if provided' do
|
48
56
|
test_ds1 = ActiveFedora::OmDatastream.new(nil, 'ds1')
|
49
|
-
test_ds1.content=
|
50
|
-
test_ds1.ng_xml.to_xml.
|
57
|
+
test_ds1.content = '<xml><foo/></xml>'
|
58
|
+
expect(test_ds1.ng_xml.to_xml).to eq("<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n")
|
51
59
|
end
|
52
|
-
it
|
53
|
-
ActiveFedora::OmDatastream.
|
60
|
+
it 'should initialize from #xml_template if no xml is provided' do
|
61
|
+
expect(ActiveFedora::OmDatastream).to receive(:xml_template).and_return('<fake template/>')
|
54
62
|
n = ActiveFedora::OmDatastream.new
|
55
|
-
n.ng_xml.
|
63
|
+
expect(n.ng_xml).to be_equivalent_to('<fake template/>')
|
56
64
|
end
|
57
65
|
end
|
58
|
-
|
66
|
+
|
59
67
|
describe '#xml_template' do
|
60
|
-
it
|
61
|
-
ActiveFedora::OmDatastream.xml_template.to_xml.
|
68
|
+
it 'should return an empty xml document' do
|
69
|
+
expect(ActiveFedora::OmDatastream.xml_template.to_xml).to eq("<?xml version=\"1.0\"?>\n<xml/>\n")
|
62
70
|
end
|
63
71
|
end
|
64
72
|
|
65
|
-
describe
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
describe 'an instance' do
|
74
|
+
it '#to_solr' do
|
75
|
+
obj = ActiveFedora::OmDatastream.new
|
76
|
+
expect(obj).to respond_to(:to_solr)
|
77
|
+
expect(obj.to_solr).to eq({})
|
78
|
+
end
|
69
79
|
end
|
70
|
-
|
71
|
-
describe
|
72
|
-
|
80
|
+
|
81
|
+
describe '.update_indexed_attributes' do
|
73
82
|
before(:each) do
|
74
83
|
@mods_ds = Hydra::ModsArticleDatastream.new(nil, 'descMetadata')
|
75
|
-
@mods_ds.content=fixture(File.join(
|
84
|
+
@mods_ds.content = fixture(File.join('mods_articles', 'mods_article1.xml')).read
|
76
85
|
end
|
77
|
-
|
78
|
-
it
|
79
|
-
result = @mods_ds.update_indexed_attributes(
|
80
|
-
result.
|
81
|
-
@mods_ds.property_values('//oxns:name[@type="personal"][1]/oxns:role').
|
86
|
+
|
87
|
+
it 'should apply submitted hash to corresponding datastream field values' do
|
88
|
+
result = @mods_ds.update_indexed_attributes([{ ':person' => '0' }, 'role'] => { '0' => 'role1', '1' => 'role2', '2' => 'role3' })
|
89
|
+
expect(result).to eq('person_0_role' => %w(role1 role2 role3))
|
90
|
+
expect(@mods_ds.property_values('//oxns:name[@type="personal"][1]/oxns:role')).to eq(%w(role1 role2 role3))
|
82
91
|
end
|
83
|
-
it
|
92
|
+
it 'should support single-value arguments (as opposed to a hash of values with array indexes as keys)' do
|
84
93
|
# In other words, { "fubar"=>"dork" } should have the same effect as { "fubar"=>{"0"=>"dork"} }
|
85
|
-
result = @mods_ds.update_indexed_attributes(
|
86
|
-
result.
|
87
|
-
@mods_ds.term_values('//oxns:name[@type="personal"][1]/oxns:role').first.
|
94
|
+
result = @mods_ds.update_indexed_attributes([{ ':person' => '0' }, 'role'] => 'the role')
|
95
|
+
expect(result).to eq('person_0_role' => ['the role'])
|
96
|
+
expect(@mods_ds.term_values('//oxns:name[@type="personal"][1]/oxns:role').first).to eq('the role')
|
88
97
|
end
|
89
|
-
it
|
98
|
+
it 'should do nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!' do
|
90
99
|
xml_before = @mods_ds.to_xml
|
91
|
-
logger.
|
92
|
-
@mods_ds.update_indexed_attributes(
|
93
|
-
@mods_ds.to_xml.
|
100
|
+
expect(logger).to receive(:warn).with "WARNING: descMetadata 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."
|
101
|
+
expect(@mods_ds.update_indexed_attributes('fubar' => 'the role')).to eq({})
|
102
|
+
expect(@mods_ds.to_xml).to eq(xml_before)
|
94
103
|
end
|
95
|
-
it
|
104
|
+
it 'should do nothing if there is no accessor corresponding to the given field key' do
|
96
105
|
xml_before = @mods_ds.to_xml
|
97
|
-
@mods_ds.update_indexed_attributes(
|
98
|
-
@mods_ds.to_xml.
|
106
|
+
expect(@mods_ds.update_indexed_attributes([{ 'fubar' => '0' }] => 'the role')).to eq({})
|
107
|
+
expect(@mods_ds.to_xml).to eq(xml_before)
|
99
108
|
end
|
100
|
-
|
109
|
+
|
101
110
|
### Examples copied over form metadata_datastream_spec
|
102
|
-
|
103
|
-
it
|
104
|
-
att= {[{
|
111
|
+
|
112
|
+
it 'should work for text fields' do
|
113
|
+
att = { [{ 'person' => '0' }, 'description'] => { '-1' => 'mork', '1' => 'york' } }
|
105
114
|
result = @mods_ds.update_indexed_attributes(att)
|
106
|
-
result.
|
107
|
-
@mods_ds.get_values([{:
|
108
|
-
att= {[{
|
115
|
+
expect(result).to eq('person_0_description' => %w(mork york))
|
116
|
+
expect(@mods_ds.get_values([{ person: 0 }, :description])).to eq(%w(mork york))
|
117
|
+
att = { [{ 'person' => '0' }, 'description'] => { '-1' => 'dork' } }
|
109
118
|
result2 = @mods_ds.update_indexed_attributes(att)
|
110
|
-
result2.
|
111
|
-
@mods_ds.get_values([{:
|
119
|
+
expect(result2).to eq('person_0_description' => ['dork'])
|
120
|
+
expect(@mods_ds.get_values([{ person: 0 }, :description])).to eq(['dork'])
|
112
121
|
end
|
113
|
-
|
114
|
-
it
|
115
|
-
att= {[{
|
122
|
+
|
123
|
+
it 'should allow deleting of values and should delete values so that to_xml does not return emtpy nodes' do
|
124
|
+
att = { [{ 'person' => '0' }, 'description'] => { '0' => 'york', '1' => 'mangle', '2' => 'mork' } }
|
116
125
|
@mods_ds.update_indexed_attributes(att)
|
117
|
-
@mods_ds.get_values([{
|
118
|
-
|
119
|
-
@mods_ds.update_indexed_attributes(
|
120
|
-
@mods_ds.get_values([{
|
121
|
-
|
122
|
-
@mods_ds.update_indexed_attributes(
|
123
|
-
@mods_ds.get_values([{
|
124
|
-
end
|
125
|
-
|
126
|
-
it
|
127
|
-
@mods_ds.get_values([{:
|
128
|
-
@mods_ds.update_indexed_attributes [{
|
129
|
-
@mods_ds.
|
126
|
+
expect(@mods_ds.get_values([{ 'person' => '0' }, 'description'])).to eq(%w(york mangle mork))
|
127
|
+
|
128
|
+
@mods_ds.update_indexed_attributes([{ 'person' => '0' }, { 'description' => '1' }] => nil)
|
129
|
+
expect(@mods_ds.get_values([{ 'person' => '0' }, 'description'])).to eq(%w(york mork))
|
130
|
+
|
131
|
+
@mods_ds.update_indexed_attributes([{ 'person' => '0' }, { 'description' => '0' }] => :delete)
|
132
|
+
expect(@mods_ds.get_values([{ 'person' => '0' }, 'description'])).to eq(['mork'])
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'should set changed to true' do
|
136
|
+
expect(@mods_ds.get_values([{ title_info: 0 }, :main_title])).to eq(['ARTICLE TITLE', 'TITLE OF HOST JOURNAL'])
|
137
|
+
@mods_ds.update_indexed_attributes [{ 'title_info' => '0' }, 'main_title'] => { '-1' => 'mork' }
|
138
|
+
expect(@mods_ds).to be_changed
|
130
139
|
end
|
131
140
|
end
|
132
|
-
|
133
|
-
describe
|
134
|
-
|
141
|
+
|
142
|
+
describe '.get_values' do
|
135
143
|
before(:each) do
|
136
144
|
@mods_ds = Hydra::ModsArticleDatastream.new(nil, 'modsDs')
|
137
|
-
@mods_ds.content=fixture(File.join(
|
145
|
+
@mods_ds.content = fixture(File.join('mods_articles', 'mods_article1.xml')).read
|
138
146
|
end
|
139
|
-
|
140
|
-
it
|
141
|
-
@mods_ds.
|
142
|
-
@mods_ds.get_values(
|
147
|
+
|
148
|
+
it 'should call lookup with field_name and return the text values from each resulting node' do
|
149
|
+
expect(@mods_ds).to receive(:term_values).with('--my xpath--').and_return(%w(value1 value2))
|
150
|
+
expect(@mods_ds.get_values('--my xpath--')).to eq(%w(value1 value2))
|
143
151
|
end
|
144
|
-
it
|
145
|
-
ActiveFedora::OmDatastream.
|
146
|
-
@mods_ds.
|
147
|
-
@mods_ds.get_values(
|
152
|
+
it 'should assume that field_names that are strings are xpath queries' do
|
153
|
+
expect(ActiveFedora::OmDatastream).to receive(:accessor_xpath).never
|
154
|
+
expect(@mods_ds).to receive(:term_values).with('--my xpath--').and_return(%w(abstract1 abstract2))
|
155
|
+
expect(@mods_ds.get_values('--my xpath--')).to eq(%w(abstract1 abstract2))
|
148
156
|
end
|
149
157
|
end
|
150
158
|
|
151
159
|
describe '.save' do
|
152
|
-
it
|
153
|
-
@test_ds.
|
154
|
-
end
|
155
|
-
it
|
156
|
-
@mock_repo.
|
157
|
-
@test_ds.stub(
|
158
|
-
@test_ds.stub(
|
159
|
-
@test_ds.stub(:
|
160
|
-
@mock_repo.
|
160
|
+
it 'should provide .save' do
|
161
|
+
expect(@test_ds).to respond_to(:save)
|
162
|
+
end
|
163
|
+
it 'should persist the product of .to_xml in fedora' do
|
164
|
+
allow(@mock_repo).to receive(:datastream).and_return('')
|
165
|
+
@test_ds.stub(new?: true)
|
166
|
+
@test_ds.stub(ng_xml_changed?: true)
|
167
|
+
@test_ds.stub(to_xml: 'fake xml')
|
168
|
+
expect(@mock_repo).to receive(:add_datastream).with(pid: nil, dsid: 'descMetadata', versionable: true, content: 'fake xml', controlGroup: 'M', dsState: 'A', mimeType: 'text/xml')
|
161
169
|
|
162
170
|
@test_ds.serialize!
|
163
171
|
@test_ds.save
|
164
|
-
@test_ds.mimeType.
|
172
|
+
expect(@test_ds.mimeType).to eq('text/xml')
|
165
173
|
end
|
166
174
|
end
|
167
|
-
|
175
|
+
|
168
176
|
describe 'setting content' do
|
169
|
-
subject { ActiveFedora::OmDatastream.new(@mock_inner,
|
170
|
-
it
|
171
|
-
subject.stub(
|
172
|
-
subject.content =
|
173
|
-
subject.content.
|
177
|
+
subject { ActiveFedora::OmDatastream.new(@mock_inner, 'descMetadata') }
|
178
|
+
it 'should update the content' do
|
179
|
+
subject.stub(new?: false)
|
180
|
+
subject.content = '<a />'
|
181
|
+
expect(subject.content).to eq('<a/>')
|
174
182
|
end
|
175
183
|
|
176
|
-
it
|
177
|
-
subject.stub(
|
178
|
-
subject.content =
|
179
|
-
subject.
|
184
|
+
it 'should mark the object as changed' do
|
185
|
+
subject.stub(new?: false, controlGroup: 'M')
|
186
|
+
subject.content = '<a />'
|
187
|
+
expect(subject).to be_changed
|
180
188
|
end
|
181
189
|
|
182
|
-
it
|
183
|
-
subject.stub(
|
184
|
-
subject.content =
|
185
|
-
subject.ng_xml.to_xml.
|
186
|
-
subject.xml_loaded.
|
190
|
+
it 'update ngxml and mark the xml as loaded' do
|
191
|
+
subject.stub(new?: false)
|
192
|
+
subject.content = '<a />'
|
193
|
+
expect(subject.ng_xml.to_xml).to match(/<a\/>/)
|
194
|
+
expect(subject.xml_loaded).to be_truthy
|
187
195
|
end
|
188
196
|
end
|
189
|
-
|
197
|
+
|
190
198
|
describe 'ng_xml=' do
|
191
199
|
before do
|
192
|
-
@mock_inner.stub(
|
193
|
-
@test_ds2 = ActiveFedora::OmDatastream.new(@mock_inner,
|
200
|
+
@mock_inner.stub(new_record?: true)
|
201
|
+
@test_ds2 = ActiveFedora::OmDatastream.new(@mock_inner, 'descMetadata')
|
194
202
|
end
|
195
|
-
it
|
203
|
+
it 'should parse raw xml for you' do
|
196
204
|
@test_ds2.ng_xml = @sample_raw_xml
|
197
|
-
@test_ds2.ng_xml.class.
|
198
|
-
@test_ds2.ng_xml.to_xml.
|
205
|
+
expect(@test_ds2.ng_xml.class).to eq(Nokogiri::XML::Document)
|
206
|
+
expect(@test_ds2.ng_xml.to_xml).to be_equivalent_to(@sample_raw_xml)
|
199
207
|
end
|
200
208
|
|
201
|
-
it
|
209
|
+
it 'Should always set a document when an Element is passed' do
|
202
210
|
@test_ds2.ng_xml = Nokogiri::XML(@sample_raw_xml).xpath('//xmlelement').first
|
203
|
-
@test_ds2.ng_xml.
|
204
|
-
@test_ds2.ng_xml.to_xml.
|
211
|
+
expect(@test_ds2.ng_xml).to be_kind_of Nokogiri::XML::Document
|
212
|
+
expect(@test_ds2.ng_xml.to_xml).to be_equivalent_to('<xmlelement/>')
|
205
213
|
end
|
206
|
-
it
|
207
|
-
@test_ds2.stub(
|
208
|
-
@test_ds2.
|
214
|
+
it 'should mark the datastream as changed' do
|
215
|
+
@test_ds2.stub(new?: false, controlGroup: 'M')
|
216
|
+
expect(@test_ds2).not_to be_changed
|
209
217
|
@test_ds2.ng_xml = @sample_raw_xml
|
210
|
-
@test_ds2.
|
218
|
+
expect(@test_ds2).to be_changed
|
211
219
|
end
|
212
220
|
end
|
213
|
-
|
221
|
+
|
214
222
|
describe '.to_xml' do
|
215
|
-
it
|
216
|
-
@test_ds.
|
223
|
+
it 'should provide .to_xml' do
|
224
|
+
expect(@test_ds).to respond_to(:to_xml)
|
217
225
|
end
|
218
|
-
|
219
|
-
it
|
220
|
-
@test_ds.stub(:
|
221
|
-
@test_ds.to_xml.
|
226
|
+
|
227
|
+
it 'should ng_xml.to_xml' do
|
228
|
+
@test_ds.stub(ng_xml: Nokogiri::XML::Document.parse('<text_document/>'))
|
229
|
+
expect(@test_ds.to_xml).to eq('<text_document/>')
|
222
230
|
end
|
223
|
-
|
231
|
+
|
224
232
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
|
225
|
-
doc = Nokogiri::XML::Document.parse(
|
226
|
-
doc.root.
|
233
|
+
doc = Nokogiri::XML::Document.parse('<test_document/>')
|
234
|
+
expect(doc.root).to receive(:add_child) # .with(@test_ds.ng_xml.root)
|
227
235
|
@test_ds.to_xml(doc)
|
228
236
|
end
|
229
|
-
|
237
|
+
|
230
238
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
|
231
|
-
expected_result =
|
232
|
-
doc = Nokogiri::XML::Document.parse(
|
239
|
+
expected_result = '<test_document><foo/><test_xml/></test_document>'
|
240
|
+
doc = Nokogiri::XML::Document.parse('<test_document><foo/></test_document>')
|
233
241
|
result = @test_ds.to_xml(doc)
|
234
|
-
doc.
|
235
|
-
result.
|
242
|
+
expect(doc).to be_equivalent_to expected_result
|
243
|
+
expect(result).to be_equivalent_to expected_result
|
236
244
|
end
|
237
|
-
|
245
|
+
|
238
246
|
it 'should add to root of Nokogiri::XML::Documents, but add directly to the elements if a Nokogiri::XML::Node is passed in' do
|
239
|
-
doc = Nokogiri::XML::Document.parse(
|
240
|
-
el = Nokogiri::XML::Node.new(
|
241
|
-
@test_ds.to_xml(doc).
|
242
|
-
@test_ds.to_xml(el).
|
247
|
+
doc = Nokogiri::XML::Document.parse('<test_document/>')
|
248
|
+
el = Nokogiri::XML::Node.new('test_element', Nokogiri::XML::Document.new)
|
249
|
+
expect(@test_ds.to_xml(doc)).to be_equivalent_to '<test_document><test_xml/></test_document>'
|
250
|
+
expect(@test_ds.to_xml(el)).to be_equivalent_to '<test_element/>'
|
243
251
|
end
|
244
|
-
|
245
252
|
end
|
246
|
-
|
253
|
+
|
247
254
|
describe '.from_solr' do
|
248
|
-
it
|
255
|
+
it 'should set the internal_solr_doc attribute to the solr document passed in' do
|
249
256
|
@test_ds.from_solr(@solr_doc)
|
250
|
-
@test_ds.internal_solr_doc.
|
257
|
+
expect(@test_ds.internal_solr_doc).to eq(@solr_doc)
|
251
258
|
end
|
252
259
|
end
|
253
260
|
|
254
261
|
describe '.get_values_from_solr' do
|
255
262
|
before(:each) do
|
256
263
|
@mods_ds = ActiveFedora::OmDatastream.new
|
257
|
-
@mods_ds.content=fixture(File.join(
|
264
|
+
@mods_ds.content = fixture(File.join('mods_articles', 'mods_article1.xml')).read
|
258
265
|
end
|
259
266
|
|
260
|
-
it
|
261
|
-
@mods_ds.get_values_from_solr(:name
|
267
|
+
it 'should return empty array if internal_solr_doc not set' do
|
268
|
+
@mods_ds.get_values_from_solr(:name, :role, :roleTerm)
|
262
269
|
end
|
263
|
-
|
264
|
-
it
|
265
|
-
mock_term = double(
|
266
|
-
mock_term.
|
267
|
-
mock_terminology = double(
|
268
|
-
mock_terminology.
|
269
|
-
ActiveFedora::OmDatastream.
|
270
|
+
|
271
|
+
it 'should return correct values from solr_doc given different term pointers' do
|
272
|
+
mock_term = double('OM::XML::Term')
|
273
|
+
allow(mock_term).to receive(:type).and_return(:text)
|
274
|
+
mock_terminology = double('OM::XML::Terminology')
|
275
|
+
allow(mock_terminology).to receive(:retrieve_term).and_return(mock_term)
|
276
|
+
allow(ActiveFedora::OmDatastream).to receive(:terminology).and_return(mock_terminology)
|
270
277
|
@mods_ds.from_solr(@solr_doc)
|
271
|
-
term_pointer = [:name
|
272
|
-
@mods_ds.get_values_from_solr(:name
|
273
|
-
ar = @mods_ds.get_values_from_solr({:
|
274
|
-
ar.length.
|
275
|
-
ar.include?(
|
276
|
-
ar.include?(
|
277
|
-
@mods_ds.get_values_from_solr({:
|
278
|
-
@mods_ds.get_values_from_solr({:
|
279
|
-
@mods_ds.get_values_from_solr({:
|
280
|
-
@mods_ds.get_values_from_solr({:
|
281
|
-
@mods_ds.get_values_from_solr({:
|
282
|
-
@mods_ds.get_values_from_solr({:
|
283
|
-
ar = @mods_ds.get_values_from_solr(:name,{:
|
284
|
-
ar.length.
|
285
|
-
ar.include?(
|
286
|
-
ar.include?(
|
287
|
-
@mods_ds.get_values_from_solr(:name,{:
|
278
|
+
term_pointer = [:name, :role, :roleTerm]
|
279
|
+
expect(@mods_ds.get_values_from_solr(:name, :role, :roleTerm)).to eq(%w(creator submitter teacher))
|
280
|
+
ar = @mods_ds.get_values_from_solr({ name: 0 }, :role, :roleTerm)
|
281
|
+
expect(ar.length).to eq(2)
|
282
|
+
expect(ar.include?('creator')).to eq(true)
|
283
|
+
expect(ar.include?('submitter')).to eq(true)
|
284
|
+
expect(@mods_ds.get_values_from_solr({ name: 1 }, :role, :roleTerm)).to eq(['teacher'])
|
285
|
+
expect(@mods_ds.get_values_from_solr({ name: 0 }, { role: 0 }, :roleTerm)).to eq(['creator'])
|
286
|
+
expect(@mods_ds.get_values_from_solr({ name: 0 }, { role: 1 }, :roleTerm)).to eq(['submitter'])
|
287
|
+
expect(@mods_ds.get_values_from_solr({ name: 0 }, { role: 2 }, :roleTerm)).to eq([])
|
288
|
+
expect(@mods_ds.get_values_from_solr({ name: 1 }, { role: 0 }, :roleTerm)).to eq(['teacher'])
|
289
|
+
expect(@mods_ds.get_values_from_solr({ name: 1 }, { role: 1 }, :roleTerm)).to eq([])
|
290
|
+
ar = @mods_ds.get_values_from_solr(:name, { role: 0 }, :roleTerm)
|
291
|
+
expect(ar.length).to eq(2)
|
292
|
+
expect(ar.include?('creator')).to eq(true)
|
293
|
+
expect(ar.include?('teacher')).to eq(true)
|
294
|
+
expect(@mods_ds.get_values_from_solr(:name, { role: 1 }, :roleTerm)).to eq(['submitter'])
|
288
295
|
end
|
289
296
|
end
|
290
297
|
|
291
298
|
describe '.has_solr_name?' do
|
292
|
-
it
|
293
|
-
@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name(
|
294
|
-
@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name(
|
295
|
-
@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name(
|
296
|
-
#if not doc passed in should be new empty solr doc and always return false
|
297
|
-
@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name(
|
299
|
+
it 'should return true if the given key exists in the solr document passed in' do
|
300
|
+
expect(@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name('name_0_role_0_roleTerm', type: :string), @solr_doc)).to eq(true)
|
301
|
+
expect(@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name('name_0_role_0_roleTerm', type: :string).to_sym, @solr_doc)).to eq(true)
|
302
|
+
expect(@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name('name_1_role_1_roleTerm', type: :string), @solr_doc)).to eq(false)
|
303
|
+
# if not doc passed in should be new empty solr doc and always return false
|
304
|
+
expect(@test_ds.has_solr_name?(ActiveFedora::SolrService.solr_name('name_0_role_0_roleTerm', type: :string))).to eq(false)
|
298
305
|
end
|
299
306
|
end
|
300
307
|
|
301
308
|
describe '.is_hierarchical_term_pointer?' do
|
302
|
-
it
|
303
|
-
@test_ds.is_hierarchical_term_pointer?(*[:image,{:
|
304
|
-
@test_ds.is_hierarchical_term_pointer?(*[:image
|
305
|
-
@test_ds.is_hierarchical_term_pointer?(*[:image
|
306
|
-
@test_ds.is_hierarchical_term_pointer?(nil).
|
309
|
+
it 'should return true only if the pointer passed in is an array that contains a hash' do
|
310
|
+
expect(@test_ds.is_hierarchical_term_pointer?(*[:image, { tag1: 1 }, :tag2])).to eq(true)
|
311
|
+
expect(@test_ds.is_hierarchical_term_pointer?(*[:image, :tag1, { tag2: 1 }])).to eq(true)
|
312
|
+
expect(@test_ds.is_hierarchical_term_pointer?(*[:image, :tag1, :tag2])).to eq(false)
|
313
|
+
expect(@test_ds.is_hierarchical_term_pointer?(nil)).to eq(false)
|
307
314
|
end
|
308
315
|
end
|
309
316
|
|
310
317
|
describe '.update_values' do
|
311
318
|
before(:each) do
|
312
319
|
@mods_ds = ActiveFedora::OmDatastream.new
|
313
|
-
@mods_ds.content= fixture(File.join(
|
320
|
+
@mods_ds.content = fixture(File.join('mods_articles', 'mods_article1.xml')).read
|
314
321
|
end
|
315
322
|
|
316
|
-
it
|
323
|
+
it 'should throw an exception if we have initialized the internal_solr_doc.' do
|
317
324
|
@mods_ds.from_solr(@solr_doc)
|
318
325
|
found_exception = false
|
319
326
|
begin
|
320
|
-
@mods_ds.update_values([{
|
327
|
+
@mods_ds.update_values([{ ':person' => '0' }, 'role', 'text'] => { '0' => 'role1', '1' => 'role2', '2' => 'role3' })
|
321
328
|
rescue
|
322
329
|
found_exception = true
|
323
330
|
end
|
324
|
-
found_exception.
|
331
|
+
expect(found_exception).to eq(true)
|
325
332
|
end
|
326
333
|
|
327
|
-
it
|
328
|
-
@mods_ds.
|
329
|
-
term_pointer = [:name
|
330
|
-
@mods_ds.update_values([{
|
334
|
+
it 'should update a value internally call OM::XML::TermValueOperators::update_values if internal_solr_doc is not set' do
|
335
|
+
allow(@mods_ds).to receive(:om_update_values).once
|
336
|
+
term_pointer = [:name, :role, :roleTerm]
|
337
|
+
@mods_ds.update_values([{ ':person' => '0' }, 'role', 'text'] => { '0' => 'role1', '1' => 'role2', '2' => 'role3' })
|
331
338
|
end
|
332
339
|
|
333
|
-
it
|
340
|
+
it 'should set changed to true' do
|
334
341
|
mods_ds = Hydra::ModsArticleDatastream.new
|
335
|
-
mods_ds.content=fixture(File.join(
|
336
|
-
mods_ds.update_values([{
|
337
|
-
mods_ds.
|
342
|
+
mods_ds.content = fixture(File.join('mods_articles', 'mods_article1.xml')).read
|
343
|
+
mods_ds.update_values([{ ':person' => '0' }, 'role', 'text'] => { '0' => 'role1', '1' => 'role2', '2' => 'role3' })
|
344
|
+
expect(mods_ds).to be_changed
|
338
345
|
end
|
339
346
|
end
|
340
347
|
|
341
348
|
describe '.term_values' do
|
342
|
-
|
343
349
|
before(:each) do
|
344
350
|
@mods_ds = ActiveFedora::OmDatastream.new
|
345
|
-
@mods_ds.content=fixture(File.join(
|
351
|
+
@mods_ds.content = fixture(File.join('mods_articles', 'mods_article1.xml')).read
|
346
352
|
end
|
347
353
|
|
348
|
-
it
|
349
|
-
@mods_ds.
|
350
|
-
term_pointer = [:name
|
354
|
+
it 'should call OM::XML::term_values if internal_solr_doc is not set and return values from xml' do
|
355
|
+
allow(@mods_ds).to receive(:om_term_values).once
|
356
|
+
term_pointer = [:name, :role, :roleTerm]
|
351
357
|
@mods_ds.term_values(*term_pointer)
|
352
358
|
end
|
353
359
|
|
354
360
|
# we will know this is working because solr_doc and xml are not synced so that wrong return mechanism can be detected
|
355
|
-
it
|
361
|
+
it 'should call get_values_from_solr if internal_solr_doc is set' do
|
356
362
|
@mods_ds.from_solr(@solr_doc)
|
357
|
-
term_pointer = [:name
|
358
|
-
@mods_ds.
|
363
|
+
term_pointer = [:name, :role, :roleTerm]
|
364
|
+
allow(@mods_ds).to receive(:get_values_from_solr).once
|
359
365
|
@mods_ds.term_values(*term_pointer)
|
360
366
|
end
|
361
367
|
end
|
362
368
|
|
363
369
|
describe "an instance that exists in the datastore, but hasn't been loaded" do
|
364
|
-
before do
|
370
|
+
before do
|
365
371
|
class MyObj < ActiveFedora::Base
|
366
372
|
has_metadata 'descMetadata', type: Hydra::ModsArticleDatastream
|
367
373
|
end
|
@@ -373,10 +379,10 @@ describe ActiveFedora::OmDatastream do
|
|
373
379
|
@obj.destroy
|
374
380
|
Object.send(:remove_const, :MyObj)
|
375
381
|
end
|
376
|
-
subject { @obj.reload.descMetadata }
|
377
|
-
it
|
378
|
-
@obj.inner_object.repository.
|
379
|
-
subject.
|
382
|
+
subject { @obj.reload.descMetadata }
|
383
|
+
it 'should not load the descMetadata datastream when calling content_changed?' do
|
384
|
+
expect(@obj.inner_object.repository).not_to receive(:datastream_dissemination).with(hash_including(dsid: 'descMetadata'))
|
385
|
+
expect(subject).not_to be_content_changed
|
380
386
|
end
|
381
387
|
end
|
382
388
|
end
|