active-fedora 8.7.0 → 9.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -15
- data/Gemfile +5 -5
- data/History.txt +0 -80
- data/README.md +1 -0
- data/Rakefile +0 -3
- data/active-fedora.gemspec +8 -7
- data/config/fedora.yml +5 -4
- data/config/predicate_mappings.yml +5 -5
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/lib/active_fedora.rb +151 -117
- data/lib/active_fedora/associations.rb +47 -15
- data/lib/active_fedora/associations/association.rb +29 -8
- data/lib/active_fedora/associations/association_scope.rb +5 -5
- data/lib/active_fedora/associations/belongs_to_association.rb +20 -63
- data/lib/active_fedora/associations/builder/association.rb +61 -25
- data/lib/active_fedora/associations/builder/belongs_to.rb +7 -94
- data/lib/active_fedora/associations/builder/collection_association.rb +11 -43
- data/lib/active_fedora/associations/builder/contains.rb +28 -0
- data/lib/active_fedora/associations/builder/has_and_belongs_to_many.rb +13 -3
- data/lib/active_fedora/associations/builder/has_many.rb +16 -10
- data/lib/active_fedora/associations/builder/property.rb +14 -0
- data/lib/active_fedora/associations/builder/singular_association.rb +14 -18
- data/lib/active_fedora/associations/builder/singular_property.rb +12 -0
- data/lib/active_fedora/associations/collection_association.rb +57 -80
- data/lib/active_fedora/associations/contains_association.rb +50 -0
- data/lib/active_fedora/associations/has_and_belongs_to_many_association.rb +44 -24
- data/lib/active_fedora/associations/has_many_association.rb +46 -14
- data/lib/active_fedora/associations/rdf.rb +86 -0
- data/lib/active_fedora/associations/singular_association.rb +4 -8
- data/lib/active_fedora/associations/singular_rdf.rb +15 -0
- data/lib/active_fedora/attached_files.rb +195 -0
- data/lib/active_fedora/attribute_methods.rb +122 -0
- data/lib/active_fedora/attribute_methods/dirty.rb +16 -0
- data/lib/active_fedora/attribute_methods/read.rb +61 -0
- data/lib/active_fedora/attribute_methods/write.rb +47 -0
- data/lib/active_fedora/attributes.rb +93 -44
- data/lib/active_fedora/attributes/primary_key.rb +12 -0
- data/lib/active_fedora/autosave_association.rb +2 -2
- data/lib/active_fedora/base.rb +16 -15
- data/lib/active_fedora/callbacks.rb +7 -7
- data/lib/active_fedora/change_set.rb +34 -0
- data/lib/active_fedora/cleaner.rb +62 -0
- data/lib/active_fedora/config.rb +4 -22
- data/lib/active_fedora/core.rb +173 -99
- data/lib/active_fedora/datastream.rb +4 -117
- data/lib/active_fedora/datastreams.rb +2 -263
- data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +28 -51
- data/lib/active_fedora/{datastream_attribute.rb → delegated_attribute.rb} +57 -26
- data/lib/active_fedora/errors.rb +61 -0
- data/lib/active_fedora/fedora.rb +19 -0
- data/lib/active_fedora/fedora_attributes.rb +58 -26
- data/lib/active_fedora/file.rb +318 -0
- data/lib/active_fedora/file_configurator.rb +32 -32
- data/lib/active_fedora/file_path_builder.rb +24 -0
- data/lib/active_fedora/files_hash.rb +82 -0
- data/lib/active_fedora/fixity_service.rb +40 -0
- data/lib/active_fedora/indexing.rb +55 -82
- data/lib/active_fedora/indexing_service.rb +70 -0
- data/lib/active_fedora/ldp_resource.rb +26 -0
- data/lib/active_fedora/loadable_from_json.rb +112 -0
- data/lib/active_fedora/model.rb +5 -19
- data/lib/active_fedora/nested_attributes.rb +5 -6
- data/lib/active_fedora/nom_datastream.rb +15 -25
- data/lib/active_fedora/om_datastream.rb +26 -197
- data/lib/active_fedora/persistence.rb +95 -71
- data/lib/active_fedora/predicates.rb +4 -4
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +17 -18
- data/lib/active_fedora/querying.rb +3 -4
- data/lib/active_fedora/railtie.rb +3 -6
- data/lib/active_fedora/rdf.rb +3 -1
- data/lib/active_fedora/rdf/datastream_indexing.rb +11 -0
- data/lib/active_fedora/rdf/fcrepo.rb +10 -324
- data/lib/active_fedora/rdf/indexing.rb +20 -16
- data/lib/active_fedora/rdf/ldp.rb +6 -0
- data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +1 -1
- data/lib/active_fedora/rdf/persistence.rb +5 -6
- data/lib/active_fedora/rdf/rdf_datastream.rb +44 -37
- data/lib/active_fedora/rdf/rdfxml_datastream.rb +13 -0
- data/lib/active_fedora/rdf/rels_ext.rb +26 -0
- data/lib/active_fedora/reflection.rb +256 -199
- data/lib/active_fedora/relation.rb +18 -6
- data/lib/active_fedora/relation/finder_methods.rb +69 -38
- data/lib/active_fedora/relation/query_methods.rb +7 -3
- data/lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb +7 -7
- data/lib/active_fedora/rspec_matchers/have_many_associated_active_fedora_objects_matcher.rb +8 -8
- data/lib/active_fedora/rspec_matchers/have_predicate_matcher.rb +9 -11
- data/lib/active_fedora/simple_datastream.rb +18 -13
- data/lib/active_fedora/solr_instance_loader.rb +18 -38
- data/lib/active_fedora/solr_service.rb +37 -20
- data/lib/active_fedora/sparql_insert.rb +45 -0
- data/lib/active_fedora/test_support.rb +1 -22
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/versionable.rb +90 -0
- data/lib/active_fedora/with_metadata.rb +37 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +70 -0
- data/lib/generators/active_fedora/config/config_generator.rb +0 -1
- data/lib/generators/active_fedora/config/solr/solr_generator.rb +1 -1
- data/lib/generators/active_fedora/model/model_generator.rb +5 -5
- data/lib/generators/active_fedora/model/templates/datastream_spec.rb.erb +1 -1
- data/lib/generators/active_fedora/model/templates/model_spec.rb.erb +2 -2
- data/lib/tasks/active_fedora_dev.rake +21 -27
- data/spec/config_helper.rb +1 -1
- data/spec/fixtures/mixed_rdf_descMetadata.nt +6 -6
- data/spec/fixtures/rails_root/config/predicate_mappings.yml +3 -19
- data/spec/fixtures/solr_rdf_descMetadata.nt +6 -6
- data/spec/integration/associations_spec.rb +133 -153
- data/spec/integration/attached_files_spec.rb +164 -0
- data/spec/integration/attributes_spec.rb +73 -12
- data/spec/integration/autosave_association_spec.rb +3 -3
- data/spec/integration/base_spec.rb +57 -351
- data/spec/integration/belongs_to_association_spec.rb +86 -76
- data/spec/integration/bug_spec.rb +3 -3
- data/spec/integration/collection_association_spec.rb +4 -4
- data/spec/integration/complex_rdf_datastream_spec.rb +54 -56
- data/spec/integration/delete_all_spec.rb +18 -15
- data/spec/integration/eradicate_spec.rb +54 -0
- data/spec/integration/fedora_solr_sync_spec.rb +7 -5
- data/spec/integration/field_to_solr_name_spec.rb +5 -5
- data/spec/integration/file_fixity_spec.rb +40 -0
- data/spec/integration/file_spec.rb +122 -0
- data/spec/integration/full_featured_model_spec.rb +53 -63
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +141 -114
- data/spec/integration/has_many_associations_spec.rb +142 -64
- data/spec/integration/json_serialization_spec.rb +50 -8
- data/spec/integration/model_spec.rb +12 -29
- data/spec/integration/nested_attribute_spec.rb +28 -20
- data/spec/integration/ntriples_datastream_spec.rb +60 -57
- data/spec/integration/om_datastream_spec.rb +51 -140
- data/spec/integration/rdf_nested_attributes_spec.rb +16 -14
- data/spec/integration/relation_delegation_spec.rb +7 -9
- data/spec/integration/relation_spec.rb +9 -7
- data/spec/integration/scoped_query_spec.rb +26 -26
- data/spec/integration/solr_instance_loader_spec.rb +69 -53
- data/spec/integration/solr_service_spec.rb +12 -73
- data/spec/integration/versionable_spec.rb +477 -0
- data/spec/integration/with_metadata_spec.rb +52 -0
- data/spec/samples/hydra-mods_article_datastream.rb +10 -6
- data/spec/samples/models/mods_article.rb +6 -2
- data/spec/samples/oral_history_sample.xml +1 -1
- data/spec/samples/oral_history_xml.xml +1 -1
- data/spec/samples/special_thing.rb +3 -3
- data/spec/spec_helper.rb +22 -12
- data/spec/support/an_active_model.rb +3 -7
- data/spec/unit/active_fedora_spec.rb +20 -17
- data/spec/unit/attached_files_spec.rb +203 -0
- data/spec/unit/attributes_spec.rb +286 -207
- data/spec/unit/base_active_model_spec.rb +8 -8
- data/spec/unit/base_datastream_management_spec.rb +11 -24
- data/spec/unit/base_extra_spec.rb +17 -67
- data/spec/unit/base_spec.rb +163 -428
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +2 -2
- data/spec/unit/callback_spec.rb +38 -23
- data/spec/unit/change_set_spec.rb +46 -0
- data/spec/unit/code_configurator_spec.rb +5 -5
- data/spec/unit/config_spec.rb +9 -14
- data/spec/unit/core_spec.rb +59 -8
- data/spec/unit/file_configurator_spec.rb +55 -53
- data/spec/unit/file_path_builder_spec.rb +18 -0
- data/spec/unit/file_spec.rb +221 -0
- data/spec/unit/files_hash_spec.rb +53 -0
- data/spec/unit/fixity_service_spec.rb +34 -0
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +134 -0
- data/spec/unit/has_many_association_spec.rb +51 -0
- data/spec/unit/indexing_service_spec.rb +23 -0
- data/spec/unit/indexing_spec.rb +26 -0
- data/spec/unit/inheritance_spec.rb +9 -10
- data/spec/unit/model_spec.rb +15 -33
- data/spec/unit/nom_datastream_spec.rb +13 -10
- data/spec/unit/ntriples_datastream_spec.rb +81 -96
- data/spec/unit/om_datastream_spec.rb +137 -227
- data/spec/unit/persistence_spec.rb +28 -34
- data/spec/unit/predicates_spec.rb +29 -29
- data/spec/unit/property_spec.rb +1 -3
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +27 -32
- data/spec/unit/query_spec.rb +116 -149
- data/spec/unit/rdf_datastream_spec.rb +25 -43
- data/spec/unit/rdf_resource_datastream_spec.rb +24 -123
- data/spec/unit/{rdfxml_rdf_datastream_spec.rb → rdfxml_datastream_spec.rb} +21 -25
- data/spec/unit/readonly_spec.rb +23 -0
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +6 -6
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +6 -6
- data/spec/unit/serializers_spec.rb +1 -1
- data/spec/unit/simple_datastream_spec.rb +12 -23
- data/spec/unit/solr_config_options_spec.rb +14 -17
- data/spec/unit/solr_service_spec.rb +38 -77
- data/spec/unit/sparql_insert_spec.rb +32 -0
- data/spec/unit/validations_spec.rb +8 -11
- metadata +96 -121
- data/lib/active_fedora/auditable.rb +0 -9
- data/lib/active_fedora/content_model.rb +0 -70
- data/lib/active_fedora/datastream_collections.rb +0 -302
- data/lib/active_fedora/datastream_hash.rb +0 -35
- data/lib/active_fedora/digital_object.rb +0 -55
- data/lib/active_fedora/fixture_exporter.rb +0 -33
- data/lib/active_fedora/fixture_loader.rb +0 -48
- data/lib/active_fedora/rdf/identifiable.rb +0 -66
- data/lib/active_fedora/rdf/project_hydra.rb +0 -12
- data/lib/active_fedora/rdf/rdfxml_rdf_datastream.rb +0 -13
- data/lib/active_fedora/rdf_xml_writer.rb +0 -49
- data/lib/active_fedora/relationship_graph.rb +0 -101
- data/lib/active_fedora/reload_on_save.rb +0 -16
- data/lib/active_fedora/rels_ext_datastream.rb +0 -100
- data/lib/active_fedora/rspec_matchers/match_fedora_datastream_matcher.rb +0 -41
- data/lib/active_fedora/rubydora_connection.rb +0 -35
- data/lib/active_fedora/semantic_node.rb +0 -164
- data/lib/active_fedora/service_definitions.rb +0 -88
- data/lib/active_fedora/sharding.rb +0 -58
- data/lib/active_fedora/solr_digital_object.rb +0 -68
- data/lib/active_fedora/unsaved_digital_object.rb +0 -58
- data/lib/generators/active_fedora/config/fedora/fedora_generator.rb +0 -12
- data/lib/generators/active_fedora/config/fedora/templates/fedora.yml +0 -38
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/development/fedora.fcfg +0 -953
- data/lib/generators/active_fedora/config/fedora/templates/fedora_conf/conf/test/fedora.fcfg +0 -953
- data/lib/tasks/active_fedora.rake +0 -83
- data/spec/fixtures/sharded_fedora.yml +0 -11
- data/spec/integration/auditable_spec.rb +0 -29
- data/spec/integration/datastream_collections_spec.rb +0 -127
- data/spec/integration/datastream_spec.rb +0 -90
- data/spec/integration/datastreams_spec.rb +0 -173
- data/spec/integration/load_from_solr_spec.rb +0 -66
- data/spec/integration/rels_ext_datastream_spec.rb +0 -82
- data/spec/support/mock_fedora.rb +0 -44
- data/spec/unit/content_model_spec.rb +0 -86
- data/spec/unit/datastream_collections_spec.rb +0 -420
- data/spec/unit/datastream_spec.rb +0 -83
- data/spec/unit/datastreams_spec.rb +0 -243
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +0 -96
- data/spec/unit/has_many_collection_spec.rb +0 -35
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/rdf_xml_writer_spec.rb +0 -63
- data/spec/unit/relationship_graph_spec.rb +0 -115
- data/spec/unit/reload_on_save_spec.rb +0 -24
- data/spec/unit/rels_ext_datastream_spec.rb +0 -170
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +0 -44
- data/spec/unit/rubydora_connection_spec.rb +0 -12
- data/spec/unit/semantic_node_spec.rb +0 -112
- data/spec/unit/service_definitions_spec.rb +0 -63
- data/spec/unit/solr_digital_object_spec.rb +0 -97
- data/spec/unit/unsaved_digital_object_spec.rb +0 -48
@@ -1,54 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
|
2
3
|
describe ActiveFedora::OmDatastream do
|
3
|
-
|
4
|
-
before(:all) do
|
5
|
-
@sample_fields = {:publisher => {:values => ["publisher1"], :type => :string},
|
6
|
-
:coverage => {:values => ["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 = {"id"=>"mods_article1",
|
13
|
-
ActiveFedora::SolrService.solr_name("test_ds__name_role_roleTerm", type: :string) =>["creator","submitter","teacher"],
|
14
|
-
ActiveFedora::SolrService.solr_name("test_ds__name_0_role", type: :string)=>"\r\ncreator\r\nsubmitter\r\n",
|
15
|
-
ActiveFedora::SolrService.solr_name("test_ds__name_1_role", type: :string)=>"\r\n teacher \r\n",
|
16
|
-
ActiveFedora::SolrService.solr_name("test_ds__name_0_role_0_roleTerm", type: :string)=>"creator",
|
17
|
-
ActiveFedora::SolrService.solr_name("test_ds__name_0_role_1_roleTerm", type: :string)=>"submitter",
|
18
|
-
ActiveFedora::SolrService.solr_name("test_ds__name_1_role_0_roleTerm", type: :string)=>["teacher"]}
|
19
|
-
end
|
20
|
-
|
21
|
-
before(:each) do
|
22
|
-
@mock_inner = double('inner object')
|
23
|
-
@mock_repo = double('repository')
|
24
|
-
allow(@mock_repo).to receive_messages(:datastream_dissemination=>'My Content', :config=>{}, :datastream_profile=>{})
|
25
|
-
allow(@mock_inner).to receive(:repository).and_return(@mock_repo)
|
26
|
-
allow(@mock_inner).to receive(:pid)
|
27
|
-
allow(@mock_inner).to receive_messages(:new_record? => false)
|
28
|
-
@test_ds = ActiveFedora::OmDatastream.new(@mock_inner, "descMetadata")
|
29
|
-
allow(@test_ds).to receive_messages(:new? => false, :profile => {}, :datastream_content => '<test_xml/>')
|
30
|
-
@test_ds.content="<test_xml/>"
|
31
|
-
allow(@test_ds).to receive_messages(:new? => false)
|
32
|
-
end
|
33
|
-
|
34
|
-
its(:metadata?) { should be true}
|
35
4
|
|
36
|
-
|
5
|
+
subject { ActiveFedora::OmDatastream.new }
|
6
|
+
it { should be_metadata }
|
37
7
|
|
38
8
|
it "should include the Solrizer::XML::TerminologyBasedSolrizer for .to_solr support" do
|
39
9
|
expect(ActiveFedora::OmDatastream.included_modules).to include(OM::XML::TerminologyBasedSolrizer)
|
40
10
|
end
|
41
|
-
|
11
|
+
|
42
12
|
describe '#new' do
|
43
|
-
it 'should provide #new' do
|
44
|
-
expect(ActiveFedora::OmDatastream).to respond_to(:new)
|
45
|
-
expect(@test_ds.ng_xml).to be_instance_of(Nokogiri::XML::Document)
|
46
|
-
end
|
47
13
|
it 'should load xml from blob if provided' do
|
48
|
-
test_ds1 = ActiveFedora::OmDatastream.new
|
14
|
+
test_ds1 = ActiveFedora::OmDatastream.new
|
49
15
|
test_ds1.content="<xml><foo/></xml>"
|
50
16
|
expect(test_ds1.ng_xml.to_xml).to be_equivalent_to("<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n")
|
51
17
|
end
|
18
|
+
|
52
19
|
it "should initialize from #xml_template if no xml is provided" do
|
53
20
|
expect(ActiveFedora::OmDatastream).to receive(:xml_template).and_return("<fake template/>")
|
54
21
|
n = ActiveFedora::OmDatastream.new
|
@@ -57,28 +24,23 @@ describe ActiveFedora::OmDatastream do
|
|
57
24
|
end
|
58
25
|
|
59
26
|
describe "#prefix" do
|
60
|
-
subject { ActiveFedora::OmDatastream.new
|
61
|
-
it "should
|
62
|
-
expect(subject.send(:prefix)).to eq
|
27
|
+
subject { ActiveFedora::OmDatastream.new }
|
28
|
+
it "should reflect the dsid" do
|
29
|
+
expect(subject.send(:prefix, 'descMetadata')).to eq "desc_metadata__"
|
63
30
|
end
|
64
31
|
end
|
65
|
-
|
32
|
+
|
66
33
|
describe '#xml_template' do
|
34
|
+
subject { ActiveFedora::OmDatastream.xml_template.to_xml }
|
67
35
|
it "should return an empty xml document" do
|
68
|
-
expect(
|
36
|
+
expect(subject).to be_equivalent_to("<?xml version=\"1.0\"?>\n<xml/>\n")
|
69
37
|
end
|
70
38
|
end
|
71
39
|
|
72
40
|
describe "to_solr" do
|
73
41
|
describe "with a dsid" do
|
74
|
-
subject { ActiveFedora::OmDatastream.new
|
75
|
-
|
76
|
-
end
|
77
|
-
describe "without a dsid" do
|
78
|
-
subject { ActiveFedora::OmDatastream.new }
|
79
|
-
it "should raise an error" do
|
80
|
-
expect{subject.to_solr}.to raise_error RuntimeError, "to_solr requires the dsid to be set"
|
81
|
-
end
|
42
|
+
subject { ActiveFedora::OmDatastream.new.to_solr }
|
43
|
+
it { should be_empty }
|
82
44
|
end
|
83
45
|
|
84
46
|
describe "when prefix is set" do
|
@@ -88,7 +50,8 @@ describe ActiveFedora::OmDatastream do
|
|
88
50
|
t.root(:path=>"mods")
|
89
51
|
t.title(:index_as=>[:stored_searchable])
|
90
52
|
end
|
91
|
-
|
53
|
+
|
54
|
+
def prefix(_)
|
92
55
|
"foo__"
|
93
56
|
end
|
94
57
|
end
|
@@ -110,31 +73,31 @@ describe ActiveFedora::OmDatastream do
|
|
110
73
|
describe ".update_indexed_attributes" do
|
111
74
|
|
112
75
|
before(:each) do
|
113
|
-
@mods_ds = Hydra::ModsArticleDatastream.new
|
76
|
+
@mods_ds = Hydra::ModsArticleDatastream.new
|
114
77
|
@mods_ds.content=fixture(File.join("mods_articles","mods_article1.xml")).read
|
115
78
|
end
|
116
79
|
|
117
80
|
it "should apply submitted hash to corresponding datastream field values" do
|
118
81
|
result = @mods_ds.update_indexed_attributes( {[{":person"=>"0"}, "role"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"} })
|
119
|
-
expect(result).to eq(
|
120
|
-
expect(@mods_ds.property_values('//oxns:name[@type="personal"][1]/oxns:role')).to eq
|
82
|
+
expect(result).to eq("person_0_role"=>["role1", "role2", "role3"])
|
83
|
+
expect(@mods_ds.property_values('//oxns:name[@type="personal"][1]/oxns:role')).to eq ["role1","role2","role3"]
|
121
84
|
end
|
122
85
|
it "should support single-value arguments (as opposed to a hash of values with array indexes as keys)" do
|
123
86
|
# In other words, { "fubar"=>"dork" } should have the same effect as { "fubar"=>{"0"=>"dork"} }
|
124
87
|
result = @mods_ds.update_indexed_attributes( { [{":person"=>"0"}, "role"]=>"the role" } )
|
125
|
-
expect(result).to eq(
|
126
|
-
expect(@mods_ds.term_values('//oxns:name[@type="personal"][1]/oxns:role').first).to eq
|
88
|
+
expect(result).to eq("person_0_role"=>["the role"])
|
89
|
+
expect(@mods_ds.term_values('//oxns:name[@type="personal"][1]/oxns:role').first).to eq "the role"
|
127
90
|
end
|
128
91
|
it "should do nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!" do
|
129
92
|
xml_before = @mods_ds.to_xml
|
130
|
-
expect(ActiveFedora::Base.logger).to receive(:warn).with "WARNING:
|
93
|
+
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."
|
131
94
|
expect(@mods_ds.update_indexed_attributes( { "fubar"=>"the role" } )).to eq({})
|
132
|
-
expect(@mods_ds.to_xml).to eq
|
95
|
+
expect(@mods_ds.to_xml).to eq xml_before
|
133
96
|
end
|
134
97
|
it "should do nothing if there is no accessor corresponding to the given field key" do
|
135
98
|
xml_before = @mods_ds.to_xml
|
136
99
|
expect(@mods_ds.update_indexed_attributes( { [{"fubar"=>"0"}]=>"the role" } )).to eq({})
|
137
|
-
expect(@mods_ds.to_xml).to eq
|
100
|
+
expect(@mods_ds.to_xml).to eq xml_before
|
138
101
|
end
|
139
102
|
|
140
103
|
### Examples copied over form metadata_datastream_spec
|
@@ -142,28 +105,28 @@ describe ActiveFedora::OmDatastream do
|
|
142
105
|
it "should work for text fields" do
|
143
106
|
att= {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
|
144
107
|
result = @mods_ds.update_indexed_attributes(att)
|
145
|
-
expect(result).to eq(
|
146
|
-
expect(@mods_ds.get_values([{:person=>0},:description])).to eq
|
108
|
+
expect(result).to eq("person_0_description"=>["mork","york"])
|
109
|
+
expect(@mods_ds.get_values([{:person=>0},:description])).to eq ['mork', 'york']
|
147
110
|
att= {[{"person"=>"0"},"description"]=>{"-1"=>"dork"}}
|
148
111
|
result2 = @mods_ds.update_indexed_attributes(att)
|
149
|
-
expect(result2).to eq(
|
150
|
-
expect(@mods_ds.get_values([{:person=>0},:description])).to eq
|
112
|
+
expect(result2).to eq("person_0_description"=>["dork"])
|
113
|
+
expect(@mods_ds.get_values([{:person=>0},:description])).to eq ['dork']
|
151
114
|
end
|
152
115
|
|
153
116
|
it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
|
154
117
|
att= {[{"person"=>"0"},"description"]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"}}
|
155
118
|
@mods_ds.update_indexed_attributes(att)
|
156
|
-
expect(@mods_ds.get_values([{"person"=>"0"},"description"])).to eq
|
119
|
+
expect(@mods_ds.get_values([{"person"=>"0"},"description"])).to eq ['york', 'mangle', 'mork']
|
157
120
|
|
158
121
|
@mods_ds.update_indexed_attributes({[{"person"=>"0"},{"description" => '1'} ]=> nil})
|
159
|
-
expect(@mods_ds.get_values([{"person"=>"0"},"description"])).to eq
|
122
|
+
expect(@mods_ds.get_values([{"person"=>"0"},"description"])).to eq ['york', 'mork']
|
160
123
|
|
161
124
|
@mods_ds.update_indexed_attributes({[{"person"=>"0"},{"description" => '0'}]=>:delete})
|
162
|
-
expect(@mods_ds.get_values([{"person"=>"0"},"description"])).to eq
|
125
|
+
expect(@mods_ds.get_values([{"person"=>"0"},"description"])).to eq ['mork']
|
163
126
|
end
|
164
127
|
|
165
128
|
it "should set changed to true" do
|
166
|
-
expect(@mods_ds.get_values([{:title_info=>0},:main_title])).to eq
|
129
|
+
expect(@mods_ds.get_values([{:title_info=>0},:main_title])).to eq ["ARTICLE TITLE", "TITLE OF HOST JOURNAL"]
|
167
130
|
@mods_ds.update_indexed_attributes [{"title_info"=>"0"},"main_title"]=>{"-1"=>"mork"}
|
168
131
|
expect(@mods_ds).to be_changed
|
169
132
|
end
|
@@ -172,230 +135,177 @@ describe ActiveFedora::OmDatastream do
|
|
172
135
|
describe ".get_values" do
|
173
136
|
|
174
137
|
before(:each) do
|
175
|
-
@mods_ds = Hydra::ModsArticleDatastream.new
|
138
|
+
@mods_ds = Hydra::ModsArticleDatastream.new
|
176
139
|
@mods_ds.content=fixture(File.join("mods_articles","mods_article1.xml")).read
|
177
140
|
end
|
178
141
|
|
179
142
|
it "should call lookup with field_name and return the text values from each resulting node" do
|
180
143
|
expect(@mods_ds).to receive(:term_values).with("--my xpath--").and_return(["value1", "value2"])
|
181
|
-
expect(@mods_ds.get_values("--my xpath--")).to eq
|
144
|
+
expect(@mods_ds.get_values("--my xpath--")).to eq ["value1", "value2"]
|
182
145
|
end
|
183
146
|
it "should assume that field_names that are strings are xpath queries" do
|
184
147
|
expect(ActiveFedora::OmDatastream).to receive(:accessor_xpath).never
|
185
148
|
expect(@mods_ds).to receive(:term_values).with("--my xpath--").and_return(["abstract1", "abstract2"])
|
186
|
-
expect(@mods_ds.get_values("--my xpath--")).to eq
|
149
|
+
expect(@mods_ds.get_values("--my xpath--")).to eq ["abstract1", "abstract2"]
|
187
150
|
end
|
188
151
|
end
|
189
152
|
|
190
153
|
describe '.save' do
|
191
|
-
|
192
|
-
|
154
|
+
let(:base_path) { '/foo' }
|
155
|
+
|
156
|
+
let(:ldp_source) { Ldp::Resource.new(mock_client, nil, nil, base_path) }
|
157
|
+
|
158
|
+
let(:conn_stubs) do
|
159
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
160
|
+
stub.post(base_path) { [200, {'Last-Modified' => 'Tue, 22 Jul 2014 02:23:32 GMT' }] }
|
161
|
+
end
|
193
162
|
end
|
194
|
-
it "should persist the product of .to_xml in fedora" do
|
195
|
-
allow(@mock_repo).to receive(:datastream).and_return('')
|
196
|
-
allow(@test_ds).to receive_messages(:new? => true)
|
197
|
-
allow(@test_ds).to receive_messages(:ng_xml_changed? => true)
|
198
|
-
allow(@test_ds).to receive_messages(:to_xml => "fake xml")
|
199
|
-
expect(@mock_repo).to receive(:add_datastream).with(:pid => nil, :dsid => 'descMetadata', :versionable => true, :content => 'fake xml', :controlGroup => 'M', :dsState => 'A', :mimeType=>'text/xml')
|
200
163
|
|
201
|
-
|
202
|
-
|
203
|
-
|
164
|
+
let(:mock_conn) do
|
165
|
+
test = Faraday.new do |builder|
|
166
|
+
builder.adapter :test, conn_stubs do |stub|
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
let :mock_client do
|
172
|
+
Ldp::Client.new mock_conn
|
173
|
+
end
|
174
|
+
|
175
|
+
before do
|
176
|
+
allow(subject).to receive(:ldp_source).and_return(ldp_source)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should persist the product of .to_xml in fedora" do
|
180
|
+
subject.serialize!
|
181
|
+
subject.save
|
182
|
+
expect(subject.mime_type).to eq 'text/xml'
|
204
183
|
end
|
205
184
|
end
|
206
|
-
|
185
|
+
|
207
186
|
describe 'setting content' do
|
208
|
-
subject { ActiveFedora::OmDatastream.new
|
187
|
+
subject { ActiveFedora::OmDatastream.new }
|
188
|
+
before { subject.content = "<a />" }
|
189
|
+
|
209
190
|
it "should update the content" do
|
210
|
-
|
211
|
-
subject.content = "<a />"
|
212
|
-
expect(subject.content).to eq('<a/>')
|
191
|
+
expect(subject.content).to eq "<?xml version=\"1.0\"?>\n<a/>"
|
213
192
|
end
|
214
193
|
|
215
194
|
it "should mark the object as changed" do
|
216
|
-
allow(subject).to receive_messages(:new? => false, :controlGroup => 'M')
|
217
|
-
subject.content = "<a />"
|
218
195
|
expect(subject).to be_changed
|
219
196
|
end
|
220
197
|
|
221
198
|
it "update ngxml and mark the xml as loaded" do
|
222
|
-
|
223
|
-
subject.content = "<a />"
|
224
|
-
expect(subject.ng_xml.to_xml).to match(/<a\/>/)
|
199
|
+
expect(subject.ng_xml.to_xml).to match /<a\/>/
|
225
200
|
expect(subject.xml_loaded).to be true
|
226
201
|
end
|
227
202
|
end
|
228
|
-
|
203
|
+
|
229
204
|
describe 'ng_xml=' do
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
205
|
+
let(:sample_raw_xml) { "<foo><xmlelement/></foo>" }
|
206
|
+
|
207
|
+
subject { ActiveFedora::OmDatastream.new }
|
208
|
+
|
234
209
|
it "should parse raw xml for you" do
|
235
|
-
|
236
|
-
expect(
|
237
|
-
expect(
|
210
|
+
subject.ng_xml = sample_raw_xml
|
211
|
+
expect(subject.ng_xml).to be_kind_of Nokogiri::XML::Document
|
212
|
+
expect(subject.ng_xml.to_xml).to be_equivalent_to(sample_raw_xml)
|
238
213
|
end
|
239
214
|
|
240
215
|
it "Should always set a document when an Element is passed" do
|
241
|
-
|
242
|
-
expect(
|
243
|
-
expect(
|
216
|
+
subject.ng_xml = Nokogiri::XML(sample_raw_xml).xpath('//xmlelement').first
|
217
|
+
expect(subject.ng_xml).to be_kind_of Nokogiri::XML::Document
|
218
|
+
expect(subject.ng_xml.to_xml).to be_equivalent_to("<xmlelement/>")
|
244
219
|
end
|
220
|
+
|
245
221
|
it "should mark the datastream as changed" do
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
expect(@test_ds2).to be_changed
|
222
|
+
expect {
|
223
|
+
subject.ng_xml = sample_raw_xml
|
224
|
+
}.to change { subject.changed? }.from(false).to(true)
|
250
225
|
end
|
251
226
|
end
|
252
|
-
|
227
|
+
|
253
228
|
describe '.to_xml' do
|
254
|
-
|
255
|
-
|
256
|
-
end
|
257
|
-
|
229
|
+
let(:doc) { Nokogiri::XML::Document.parse("<text_document/>") }
|
230
|
+
|
258
231
|
it "should ng_xml.to_xml" do
|
259
|
-
allow(
|
260
|
-
expect(
|
232
|
+
allow(subject).to receive(:ng_xml).and_return(doc)
|
233
|
+
expect(subject.to_xml).to eq "<?xml version=\"1.0\"?>\n<text_document/>"
|
261
234
|
end
|
262
235
|
|
263
236
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
|
264
|
-
doc
|
265
|
-
|
266
|
-
@test_ds.to_xml(doc)
|
267
|
-
end
|
268
|
-
|
269
|
-
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
|
270
|
-
expected_result = "<test_document><foo/><test_xml/></test_document>"
|
271
|
-
doc = Nokogiri::XML::Document.parse("<test_document><foo/></test_document>")
|
272
|
-
result = @test_ds.to_xml(doc)
|
273
|
-
expect(doc).to be_equivalent_to expected_result
|
274
|
-
expect(result).to be_equivalent_to expected_result
|
237
|
+
expect(doc.root).to receive(:add_child)#.with(test_ds.ng_xml.root)
|
238
|
+
subject.to_xml(doc)
|
275
239
|
end
|
276
240
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
241
|
+
context "with some existing content" do
|
242
|
+
before do
|
243
|
+
subject.content="<test_xml/>"
|
244
|
+
end
|
245
|
+
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
|
246
|
+
expected_result = "<test_document><foo/><test_xml/></test_document>"
|
247
|
+
doc = Nokogiri::XML::Document.parse("<test_document><foo/></test_document>")
|
248
|
+
result = subject.to_xml(doc)
|
249
|
+
expect(doc).to be_equivalent_to expected_result
|
250
|
+
expect(result).to be_equivalent_to expected_result
|
251
|
+
end
|
252
|
+
|
253
|
+
it 'should add to root of Nokogiri::XML::Documents, but add directly to the elements if a Nokogiri::XML::Node is passed in' do
|
254
|
+
doc = Nokogiri::XML::Document.parse("<test_document/>")
|
255
|
+
el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
|
256
|
+
expect(subject.to_xml(doc)).to be_equivalent_to "<test_document><test_xml/></test_document>"
|
257
|
+
expect(subject.to_xml(el)).to be_equivalent_to "<test_element/>"
|
258
|
+
end
|
282
259
|
end
|
283
260
|
|
284
261
|
end
|
285
262
|
|
286
|
-
describe '.from_solr' do
|
287
|
-
it "should set the internal_solr_doc attribute to the solr document passed in" do
|
288
|
-
@test_ds.from_solr(@solr_doc)
|
289
|
-
expect(@test_ds.internal_solr_doc).to eq(@solr_doc)
|
290
|
-
end
|
291
|
-
end
|
292
263
|
|
293
|
-
describe '.
|
294
|
-
|
295
|
-
|
296
|
-
|
264
|
+
describe '.has_solr_name?' do
|
265
|
+
let(:name0_role0) { ActiveFedora::SolrService.solr_name("desc_metadata__name_0_role_0_roleTerm", type: :string) }
|
266
|
+
let(:name1_role1) { ActiveFedora::SolrService.solr_name("desc_metadata__name_1_role_1_roleTerm", type: :string) }
|
267
|
+
let(:solr_doc) do
|
268
|
+
{"id"=>"mods_article1",
|
269
|
+
ActiveFedora::SolrService.solr_name("desc_metadata__name_role_roleTerm", type: :string) =>["creator","submitter","teacher"],
|
270
|
+
ActiveFedora::SolrService.solr_name("desc_metadata__name_0_role", type: :string)=>"\r\ncreator\r\nsubmitter\r\n",
|
271
|
+
ActiveFedora::SolrService.solr_name("desc_metadata__name_1_role", type: :string)=>"\r\n teacher \r\n",
|
272
|
+
name0_role0 =>"creator",
|
273
|
+
ActiveFedora::SolrService.solr_name("desc_metadata__name_0_role_1_roleTerm", type: :string)=>"submitter",
|
274
|
+
ActiveFedora::SolrService.solr_name("desc_metadata__name_1_role_0_roleTerm", type: :string)=>["teacher"]}
|
297
275
|
end
|
298
276
|
|
299
|
-
it "should return empty array if internal_solr_doc not set" do
|
300
|
-
@mods_ds.get_values_from_solr(:name,:role,:roleTerm)
|
301
|
-
end
|
302
|
-
|
303
|
-
it "should return correct values from solr_doc given different term pointers" do
|
304
|
-
mock_term = double("OM::XML::Term")
|
305
|
-
allow(mock_term).to receive(:type).and_return(:text)
|
306
|
-
mock_terminology = double("OM::XML::Terminology")
|
307
|
-
allow(mock_terminology).to receive(:retrieve_term).and_return(mock_term)
|
308
|
-
allow(ActiveFedora::OmDatastream).to receive(:terminology).and_return(mock_terminology)
|
309
|
-
@mods_ds.from_solr(@solr_doc)
|
310
|
-
term_pointer = [:name,:role,:roleTerm]
|
311
|
-
expect(@mods_ds.get_values_from_solr(:name,:role,:roleTerm)).to eq(["creator","submitter","teacher"])
|
312
|
-
ar = @mods_ds.get_values_from_solr({:name=>0},:role,:roleTerm)
|
313
|
-
expect(ar.length).to eq(2)
|
314
|
-
expect(ar.include?("creator")).to eq(true)
|
315
|
-
expect(ar.include?("submitter")).to eq(true)
|
316
|
-
expect(@mods_ds.get_values_from_solr({:name=>1},:role,:roleTerm)).to eq(["teacher"])
|
317
|
-
expect(@mods_ds.get_values_from_solr({:name=>0},{:role=>0},:roleTerm)).to eq(["creator"])
|
318
|
-
expect(@mods_ds.get_values_from_solr({:name=>0},{:role=>1},:roleTerm)).to eq(["submitter"])
|
319
|
-
expect(@mods_ds.get_values_from_solr({:name=>0},{:role=>2},:roleTerm)).to eq([])
|
320
|
-
expect(@mods_ds.get_values_from_solr({:name=>1},{:role=>0},:roleTerm)).to eq(["teacher"])
|
321
|
-
expect(@mods_ds.get_values_from_solr({:name=>1},{:role=>1},:roleTerm)).to eq([])
|
322
|
-
ar = @mods_ds.get_values_from_solr(:name,{:role=>0},:roleTerm)
|
323
|
-
expect(ar.length).to eq(2)
|
324
|
-
expect(ar.include?("creator")).to eq(true)
|
325
|
-
expect(ar.include?("teacher")).to eq(true)
|
326
|
-
expect(@mods_ds.get_values_from_solr(:name,{:role=>1},:roleTerm)).to eq(["submitter"])
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
describe '.has_solr_name?' do
|
331
277
|
it "should return true if the given key exists in the solr document passed in" do
|
332
|
-
expect(
|
333
|
-
expect(
|
334
|
-
expect(
|
278
|
+
expect(subject).to have_solr_name(name0_role0, solr_doc)
|
279
|
+
expect(subject).to have_solr_name(name0_role0.to_sym, solr_doc)
|
280
|
+
expect(subject).to_not have_solr_name(name1_role1, solr_doc)
|
335
281
|
#if not doc passed in should be new empty solr doc and always return false
|
336
|
-
expect(
|
282
|
+
expect(subject).to_not have_solr_name(name0_role0)
|
337
283
|
end
|
338
284
|
end
|
339
285
|
|
340
286
|
describe '.is_hierarchical_term_pointer?' do
|
341
287
|
it "should return true only if the pointer passed in is an array that contains a hash" do
|
342
|
-
expect(
|
343
|
-
expect(
|
344
|
-
expect(
|
345
|
-
expect(
|
288
|
+
expect(subject.is_hierarchical_term_pointer?(*[:image,{:tag1=>1},:tag2])).to be true
|
289
|
+
expect(subject.is_hierarchical_term_pointer?(*[:image,:tag1,{:tag2=>1}])).to be true
|
290
|
+
expect(subject.is_hierarchical_term_pointer?(*[:image,:tag1,:tag2])).to be false
|
291
|
+
expect(subject.is_hierarchical_term_pointer?(nil)).to be false
|
346
292
|
end
|
347
293
|
end
|
348
294
|
|
349
295
|
describe '.update_values' do
|
350
|
-
before(:each) do
|
351
|
-
@mods_ds = ActiveFedora::OmDatastream.new
|
352
|
-
@mods_ds.content= fixture(File.join("mods_articles","mods_article1.xml")).read
|
353
|
-
end
|
354
296
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
begin
|
359
|
-
@mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
360
|
-
rescue
|
361
|
-
found_exception = true
|
362
|
-
end
|
363
|
-
expect(found_exception).to eq(true)
|
364
|
-
end
|
297
|
+
subject { ActiveFedora::OmDatastream.new }
|
298
|
+
|
299
|
+
before { subject.content= fixture(File.join("mods_articles","mods_article1.xml")).read }
|
365
300
|
|
366
301
|
it "should update a value internally call OM::XML::TermValueOperators::update_values if internal_solr_doc is not set" do
|
367
|
-
|
368
|
-
|
369
|
-
@mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
302
|
+
expect(subject).to receive(:om_update_values)
|
303
|
+
subject.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
370
304
|
end
|
371
305
|
|
372
306
|
it "should set changed to true" do
|
373
|
-
|
374
|
-
|
375
|
-
mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
376
|
-
expect(mods_ds).to be_changed
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
describe '.term_values' do
|
381
|
-
|
382
|
-
before(:each) do
|
383
|
-
@mods_ds = ActiveFedora::OmDatastream.new
|
384
|
-
@mods_ds.content=fixture(File.join("mods_articles","mods_article1.xml")).read
|
385
|
-
end
|
386
|
-
|
387
|
-
it "should call OM::XML::term_values if internal_solr_doc is not set and return values from xml" do
|
388
|
-
allow(@mods_ds).to receive(:om_term_values).once()
|
389
|
-
term_pointer = [:name,:role,:roleTerm]
|
390
|
-
@mods_ds.term_values(*term_pointer)
|
391
|
-
end
|
392
|
-
|
393
|
-
# we will know this is working because solr_doc and xml are not synced so that wrong return mechanism can be detected
|
394
|
-
it "should call get_values_from_solr if internal_solr_doc is set" do
|
395
|
-
@mods_ds.from_solr(@solr_doc)
|
396
|
-
term_pointer = [:name,:role,:roleTerm]
|
397
|
-
allow(@mods_ds).to receive(:get_values_from_solr).once()
|
398
|
-
@mods_ds.term_values(*term_pointer)
|
307
|
+
subject.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
|
308
|
+
expect(subject).to be_changed
|
399
309
|
end
|
400
310
|
end
|
401
311
|
|
@@ -407,15 +317,15 @@ describe ActiveFedora::OmDatastream do
|
|
407
317
|
@obj = MyObj.new
|
408
318
|
@obj.descMetadata.title = 'Foobar'
|
409
319
|
@obj.save
|
410
|
-
@obj.reload
|
411
320
|
end
|
412
321
|
after do
|
413
322
|
@obj.destroy
|
414
323
|
Object.send(:remove_const, :MyObj)
|
415
324
|
end
|
325
|
+
subject { @obj.reload.descMetadata }
|
416
326
|
it "should not load the descMetadata datastream when calling content_changed?" do
|
417
|
-
expect(@obj
|
418
|
-
expect(
|
327
|
+
expect(@obj).to_not receive(:content)
|
328
|
+
expect(subject).to_not be_content_changed
|
419
329
|
end
|
420
330
|
end
|
421
331
|
end
|