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