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,168 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require "solrizer"
|
3
2
|
|
4
3
|
describe ActiveFedora::OmDatastream do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
|
10
|
-
has_metadata "descMetadata", type: Hydra::ModsArticleDatastream, control_group: 'X', autocreate: true
|
11
|
-
end
|
4
|
+
before(:all) do
|
5
|
+
class ModsArticle2 < ActiveFedora::Base
|
6
|
+
# Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
|
7
|
+
has_metadata "descMetadata", type: Hydra::ModsArticleDatastream, autocreate: true
|
12
8
|
end
|
9
|
+
end
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
after(:all) do
|
12
|
+
Object.send(:remove_const, :ModsArticle2)
|
13
|
+
end
|
17
14
|
|
18
|
-
|
19
|
-
@obj = ModsArticle3.new
|
20
|
-
@obj.save
|
21
|
-
@obj.reload
|
22
|
-
end
|
15
|
+
let(:obj) { ModsArticle2.create.reload }
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
after(:each) do
|
18
|
+
obj.destroy
|
19
|
+
end
|
27
20
|
|
28
|
-
|
29
|
-
expect(@obj.descMetadata).to be_inline
|
30
|
-
end
|
21
|
+
subject { obj.descMetadata }
|
31
22
|
|
23
|
+
describe "#changed?" do
|
32
24
|
it "should not be changed when no fields have been set" do
|
33
|
-
expect(
|
25
|
+
expect(subject).to_not be_content_changed
|
34
26
|
end
|
35
27
|
it "should be changed when a field has been set" do
|
36
|
-
|
37
|
-
expect(
|
38
|
-
end
|
39
|
-
describe "#changed?" do
|
40
|
-
it "should not be changed if the new xml matches the old xml" do
|
41
|
-
@obj.descMetadata.content = @obj.descMetadata.content
|
42
|
-
expect(@obj.descMetadata).not_to be_changed
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should not be changed if there are minor differences in whitespace" do
|
46
|
-
@obj.descMetadata.content = "<a><b>1</b></a>"
|
47
|
-
@obj.save
|
48
|
-
expect(@obj.descMetadata).not_to be_changed
|
49
|
-
@obj.descMetadata.content = "<a>\n<b>1</b>\n</a>"
|
50
|
-
expect(@obj.descMetadata).not_to be_changed
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "an instance that is a managed datastream" do
|
56
|
-
before(:all) do
|
57
|
-
class ModsArticle2 < ActiveFedora::Base
|
58
|
-
# Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
|
59
|
-
has_metadata "descMetadata", type: Hydra::ModsArticleDatastream, autocreate: true
|
60
|
-
end
|
28
|
+
subject.title = 'Foobar'
|
29
|
+
expect(subject).to be_content_changed
|
61
30
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
before(:each) do
|
68
|
-
@obj = ModsArticle2.new
|
69
|
-
@obj.save
|
70
|
-
@obj.reload
|
31
|
+
it "should not be changed if the new xml matches the old xml" do
|
32
|
+
subject.content = subject.content
|
33
|
+
expect(subject).to_not be_changed
|
71
34
|
end
|
72
35
|
|
73
|
-
|
74
|
-
|
36
|
+
it "should be changed if there are minor differences in whitespace" do
|
37
|
+
subject.content = "<a><b>1</b></a>"
|
38
|
+
obj.save
|
39
|
+
expect(subject).to_not be_changed
|
40
|
+
subject.content = "<a>\n<b>1</b>\n</a>"
|
41
|
+
expect(subject).to be_changed
|
75
42
|
end
|
43
|
+
end
|
76
44
|
|
77
|
-
|
78
|
-
|
45
|
+
describe "empty datastream content" do
|
46
|
+
it "should not break when there is empty datastream content" do
|
47
|
+
subject.content = ""
|
48
|
+
obj.save
|
79
49
|
end
|
50
|
+
end
|
80
51
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
it "should be changed if there are minor differences in whitespace" do
|
88
|
-
@obj.descMetadata.content = "<a><b>1</b></a>"
|
89
|
-
@obj.save
|
90
|
-
expect(@obj.descMetadata).not_to be_changed
|
91
|
-
@obj.descMetadata.content = "<a>\n<b>1</b>\n</a>"
|
92
|
-
expect(@obj.descMetadata).to be_changed
|
93
|
-
end
|
52
|
+
describe '.update_values' do
|
53
|
+
before do
|
54
|
+
subject.content = File.read(fixture('mods_articles/mods_article1.xml'))
|
55
|
+
obj.save
|
56
|
+
obj.reload
|
94
57
|
end
|
95
58
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
59
|
+
it "should not be dirty after .update_values is saved" do
|
60
|
+
obj.descMetadata.update_values([{:name=>0},{:role=>0},:text] =>"Funder")
|
61
|
+
expect(obj.descMetadata).to be_changed
|
62
|
+
obj.save
|
63
|
+
expect(obj.descMetadata).to_not be_changed
|
64
|
+
expect(obj.descMetadata.term_values({:name=>0},{:role=>0},:text)).to eq ["Funder"]
|
101
65
|
end
|
66
|
+
end
|
102
67
|
|
103
|
-
describe '.term_values' do
|
104
|
-
before do
|
105
|
-
@obj.descMetadata.content = File.read(fixture('mods_articles/mods_article1.xml'))
|
106
|
-
@obj.save
|
107
|
-
@obj.reload
|
108
|
-
@solr_obj = ActiveFedora::Base.load_instance_from_solr(@obj.pid)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should return the same values whether getting from solr or Fedora" do
|
112
|
-
expect(@solr_obj.datastreams["descMetadata"].term_values(:name,:role,:text)).to eq(["Creator","Contributor","Funder","Host"])
|
113
|
-
expect(@solr_obj.datastreams["descMetadata"].term_values({:name=>0},:role,:text)).to eq(["Creator"])
|
114
|
-
expect(@solr_obj.datastreams["descMetadata"].term_values({:name=>1},:role,:text)).to eq(["Contributor"])
|
115
|
-
expect(@solr_obj.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text)).to eq(["Creator"])
|
116
|
-
expect(@solr_obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>0},:text)).to eq(["Contributor"])
|
117
|
-
expect(@solr_obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>1},:text)).to eq([])
|
118
|
-
ar = @solr_obj.datastreams["descMetadata"].term_values(:name,{:role=>0},:text)
|
119
|
-
expect(ar.length).to eq(4)
|
120
|
-
expect(ar.include?("Creator")).to eq(true)
|
121
|
-
expect(ar.include?("Contributor")).to eq(true)
|
122
|
-
expect(ar.include?("Funder")).to eq(true)
|
123
|
-
expect(ar.include?("Host")).to eq(true)
|
124
|
-
|
125
|
-
expect(@obj.datastreams["descMetadata"].term_values(:name,:role,:text)).to eq(["Creator","Contributor","Funder","Host"])
|
126
|
-
expect(@obj.datastreams["descMetadata"].term_values({:name=>0},:role,:text)).to eq(["Creator"])
|
127
|
-
expect(@obj.datastreams["descMetadata"].term_values({:name=>1},:role,:text)).to eq(["Contributor"])
|
128
|
-
expect(@obj.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text)).to eq(["Creator"])
|
129
|
-
expect(@obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>0},:text)).to eq(["Contributor"])
|
130
|
-
expect(@obj.datastreams["descMetadata"].term_values({:name=>1},{:role=>1},:text)).to eq([])
|
131
|
-
ar = @obj.datastreams["descMetadata"].term_values(:name,{:role=>0},:text)
|
132
|
-
expect(ar.length).to eq(4)
|
133
|
-
expect(ar.include?("Creator")).to eq(true)
|
134
|
-
expect(ar.include?("Contributor")).to eq(true)
|
135
|
-
expect(ar.include?("Funder")).to eq(true)
|
136
|
-
expect(ar.include?("Host")).to eq(true)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
describe '.update_values' do
|
141
|
-
before do
|
142
|
-
@obj.descMetadata.content = File.read(fixture('mods_articles/mods_article1.xml'))
|
143
|
-
@obj.save
|
144
|
-
@obj.reload
|
145
|
-
end
|
146
68
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
expect(@obj.datastreams["descMetadata"].term_values({:name=>0},{:role=>0},:text)).to eq(["Funder"])
|
153
|
-
end
|
69
|
+
describe ".to_solr" do
|
70
|
+
before do
|
71
|
+
subject.journal.issue.publication_date = Date.parse('2012-11-02')
|
72
|
+
obj.save!
|
73
|
+
obj.reload
|
154
74
|
end
|
155
|
-
|
156
|
-
|
157
|
-
describe ".to_solr" do
|
158
|
-
before do
|
159
|
-
@obj.descMetadata.journal.issue.publication_date = Date.parse('2012-11-02')
|
160
|
-
@obj.save!
|
161
|
-
@obj.reload
|
162
|
-
end
|
163
|
-
it "should solrize terms with :type=>'date' to *_dt solr terms" do
|
164
|
-
expect(@obj.to_solr[ActiveFedora::SolrService.solr_name('desc_metadata__journal_issue_publication_date', type: :date)]).to eq(['2012-11-02T00:00:00Z'])
|
165
|
-
end
|
75
|
+
it "should solrize terms with :type=>'date' to *_dt solr terms" do
|
76
|
+
expect(obj.to_solr[ActiveFedora::SolrService.solr_name('desc_metadata__journal_issue_publication_date', type: :date)]).to eq ['2012-11-02T00:00:00Z']
|
166
77
|
end
|
167
78
|
end
|
168
79
|
end
|
@@ -2,9 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "Nesting attribute behavior of RDFDatastream" do
|
4
4
|
describe ".attributes=" do
|
5
|
+
|
5
6
|
describe "complex properties" do
|
6
7
|
before do
|
7
8
|
class DummyMADS < RDF::Vocabulary("http://www.loc.gov/mads/rdf/v1#")
|
9
|
+
# TODO this test is order dependent. It expects to use the object created in the previous test
|
8
10
|
# componentList and Types of components
|
9
11
|
property :componentList
|
10
12
|
property :Topic
|
@@ -27,7 +29,7 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
27
29
|
class ComplexRDFDatastream < ActiveFedora::NtriplesRDFDatastream
|
28
30
|
property :topic, predicate: DummyMADS.Topic, class_name: "Topic"
|
29
31
|
property :personalName, predicate: DummyMADS.PersonalName, class_name: "PersonalName"
|
30
|
-
property :title, predicate: RDF::DC.title
|
32
|
+
property :title, predicate: ::RDF::DC.title
|
31
33
|
|
32
34
|
|
33
35
|
accepts_nested_attributes_for :topic, :personalName
|
@@ -61,7 +63,7 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
61
63
|
Object.send(:remove_const, :ComplexRDFDatastream)
|
62
64
|
Object.send(:remove_const, :DummyMADS)
|
63
65
|
end
|
64
|
-
subject { ComplexRDFDatastream.new
|
66
|
+
subject { ComplexRDFDatastream.new }
|
65
67
|
let(:params) do
|
66
68
|
{ myResource:
|
67
69
|
{
|
@@ -100,14 +102,14 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
100
102
|
subject { ComplexRDFDatastream::PersonalName.new(RDF::Graph.new) }
|
101
103
|
it "should accept a hash" do
|
102
104
|
subject.elementList_attributes = [{ topicElement_attributes: {'0' => { elementValue:"Quantum Behavior" }, '1' => { elementValue:"Wave Function" }}}]
|
103
|
-
expect(subject.elementList.first[0].elementValue).to eq
|
104
|
-
expect(subject.elementList.first[1].elementValue).to eq
|
105
|
+
expect(subject.elementList.first[0].elementValue).to eq ["Quantum Behavior"]
|
106
|
+
expect(subject.elementList.first[1].elementValue).to eq ["Wave Function"]
|
105
107
|
|
106
108
|
end
|
107
109
|
it "should accept an array" do
|
108
110
|
subject.elementList_attributes = [{ topicElement_attributes: [{ elementValue:"Quantum Behavior" }, { elementValue:"Wave Function" }]}]
|
109
|
-
expect(subject.elementList.first[0].elementValue).to eq
|
110
|
-
expect(subject.elementList.first[1].elementValue).to eq
|
111
|
+
expect(subject.elementList.first[0].elementValue).to eq ["Quantum Behavior"]
|
112
|
+
expect(subject.elementList.first[1].elementValue).to eq ["Wave Function"]
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
@@ -118,10 +120,10 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
118
120
|
end
|
119
121
|
|
120
122
|
it 'should have attributes' do
|
121
|
-
expect(subject.topic[0].elementList.first[0].elementValue).to eq
|
122
|
-
expect(subject.topic[1].elementList.first[0].elementValue).to eq
|
123
|
-
expect(subject.personalName.first.elementList.first.fullNameElement).to eq
|
124
|
-
expect(subject.personalName.first.elementList.first.dateNameElement).to eq
|
123
|
+
expect(subject.topic[0].elementList.first[0].elementValue).to eq ["Cosmology"]
|
124
|
+
expect(subject.topic[1].elementList.first[0].elementValue).to eq ["Quantum Behavior"]
|
125
|
+
expect(subject.personalName.first.elementList.first.fullNameElement).to eq ["Jefferson, Thomas"]
|
126
|
+
expect(subject.personalName.first.elementList.first.dateNameElement).to eq ["1743-1826"]
|
125
127
|
end
|
126
128
|
|
127
129
|
it 'should build nodes with ids' do
|
@@ -144,11 +146,11 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
144
146
|
describe "with an existing object" do
|
145
147
|
before(:each) do
|
146
148
|
class SpecDatastream < ActiveFedora::NtriplesRDFDatastream
|
147
|
-
property :parts, predicate: RDF::DC.hasPart, :class_name=>'Component'
|
149
|
+
property :parts, predicate: ::RDF::DC.hasPart, :class_name=>'Component'
|
148
150
|
accepts_nested_attributes_for :parts, allow_destroy: true
|
149
151
|
|
150
152
|
class Component < ActiveTriples::Resource
|
151
|
-
property :label, predicate: RDF::DC.title
|
153
|
+
property :label, predicate: ::RDF::DC.title
|
152
154
|
end
|
153
155
|
end
|
154
156
|
|
@@ -157,7 +159,7 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
157
159
|
after(:each) do
|
158
160
|
Object.send(:remove_const, :SpecDatastream)
|
159
161
|
end
|
160
|
-
subject { SpecDatastream.new
|
162
|
+
subject { SpecDatastream.new }
|
161
163
|
before do
|
162
164
|
subject.attributes = { parts_attributes: [
|
163
165
|
{label: 'Alternator'},
|
@@ -171,7 +173,7 @@ describe "Nesting attribute behavior of RDFDatastream" do
|
|
171
173
|
it "should update nested objects" do
|
172
174
|
subject.parts_attributes= [{id: replace_object_id, label: "Universal Joint"}, {label:"Oil Pump"}, {id: remove_object_id, _destroy: '1', label: "bar1 uno"}]
|
173
175
|
|
174
|
-
expect(subject.parts.map{|p| p.label.first}).to eq
|
176
|
+
expect(subject.parts.map{|p| p.label.first}).to eq ['Alternator', 'Universal Joint', 'Transmission', 'Oil Pump']
|
175
177
|
|
176
178
|
end
|
177
179
|
it "create a new object when the id is provided" do
|
@@ -22,7 +22,7 @@ describe ActiveFedora::Model do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
after(:all) do
|
27
27
|
Object.send(:remove_const, :ModelIntegrationSpec)
|
28
28
|
end
|
@@ -33,16 +33,14 @@ describe ActiveFedora::Model do
|
|
33
33
|
let!(:instance2){ ModelIntegrationSpec::Basic.create!(foo: ['Alpha'], bar: ['Peanuts'])}
|
34
34
|
let!(:instance3){ ModelIntegrationSpec::Basic.create!(foo: ['Sigma'], bar: ['Peanuts'])}
|
35
35
|
|
36
|
-
after { ModelIntegrationSpec::Basic.delete_all }
|
37
|
-
|
38
36
|
subject { ModelIntegrationSpec::Basic.where(bar: 'Peanuts') }
|
39
37
|
|
40
38
|
it "should map" do
|
41
|
-
expect(subject.map(&:id)).to eq
|
39
|
+
expect(subject.map(&:id)).to eq [instance2.id, instance3.id]
|
42
40
|
end
|
43
41
|
|
44
42
|
it "should collect" do
|
45
|
-
expect(subject.collect(&:id)).to eq
|
43
|
+
expect(subject.collect(&:id)).to eq [instance2.id, instance3.id]
|
46
44
|
end
|
47
45
|
|
48
46
|
it "should have each" do
|
@@ -52,13 +50,13 @@ describe ActiveFedora::Model do
|
|
52
50
|
end
|
53
51
|
|
54
52
|
it "should have all?" do
|
55
|
-
expect(subject.all? { |t| t.foo == ['Alpha']}).to
|
56
|
-
expect(subject.all? { |t| t.bar == ['Peanuts']}).to
|
53
|
+
expect(subject.all? { |t| t.foo == ['Alpha']}).to be false
|
54
|
+
expect(subject.all? { |t| t.bar == ['Peanuts']}).to be true
|
57
55
|
end
|
58
56
|
|
59
57
|
it "should have include?" do
|
60
|
-
expect(subject.include?(instance1)).to
|
61
|
-
expect(subject.include?(instance2)).to
|
58
|
+
expect(subject.include?(instance1)).to be false
|
59
|
+
expect(subject.include?(instance2)).to be true
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
@@ -2,21 +2,23 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
before :all do
|
5
|
-
class Library < ActiveFedora::Base
|
6
|
-
has_many :books,
|
5
|
+
class Library < ActiveFedora::Base
|
6
|
+
has_many :books, predicate: ActiveFedora::RDF::RelsExt.isPartOf
|
7
7
|
end
|
8
8
|
class Book < ActiveFedora::Base; end
|
9
9
|
end
|
10
10
|
after :all do
|
11
|
-
Library.delete_all
|
12
11
|
Object.send(:remove_const, :Library)
|
13
12
|
Object.send(:remove_const, :Book)
|
14
13
|
end
|
15
14
|
|
16
|
-
subject { Library.all }
|
17
|
-
its(:class) {is_expected.to eq ActiveFedora::Relation }
|
15
|
+
subject { Library.all }
|
18
16
|
|
19
|
-
|
17
|
+
it "should be a relation" do
|
18
|
+
expect(subject.class).to be ActiveFedora::Relation
|
19
|
+
end
|
20
|
+
|
21
|
+
before :each do
|
20
22
|
Library.create
|
21
23
|
@library = Library.create
|
22
24
|
end
|
@@ -32,7 +34,7 @@ describe ActiveFedora::Base do
|
|
32
34
|
expect(subject).to be_loaded
|
33
35
|
end
|
34
36
|
it "shouldn't reload" do
|
35
|
-
expect_any_instance_of(ActiveFedora::Relation).
|
37
|
+
expect_any_instance_of(ActiveFedora::Relation).to_not receive :find_each
|
36
38
|
subject[0]
|
37
39
|
end
|
38
40
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe "scoped queries" do
|
4
4
|
|
5
|
-
before do
|
5
|
+
before do
|
6
6
|
module ModelIntegrationSpec
|
7
7
|
class Basic < ActiveFedora::Base
|
8
8
|
has_metadata "properties", type: ActiveFedora::SimpleDatastream do |m|
|
@@ -18,12 +18,12 @@ describe "scoped queries" do
|
|
18
18
|
doc[ActiveFedora::SolrService.solr_name('foo', :sortable)] = doc[ActiveFedora::SolrService.solr_name('foo', type: :string)]
|
19
19
|
doc
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
after do
|
28
28
|
Object.send(:remove_const, :ModelIntegrationSpec)
|
29
29
|
end
|
@@ -35,30 +35,28 @@ describe "scoped queries" do
|
|
35
35
|
after do
|
36
36
|
test_instance.delete
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
describe ".all" do
|
40
40
|
it "should return an array of instances of the calling Class" do
|
41
41
|
result = ModelIntegrationSpec::Basic.all.to_a
|
42
42
|
expect(result).to be_instance_of(Array)
|
43
43
|
# this test is meaningless if the array length is zero
|
44
|
-
expect(result.length).to be
|
45
|
-
result.
|
46
|
-
expect(obj.class).to eq(ModelIntegrationSpec::Basic)
|
47
|
-
end
|
44
|
+
expect(result.length > 0).to be true
|
45
|
+
expect(result).to all( be_an ModelIntegrationSpec::Basic )
|
48
46
|
end
|
49
47
|
end
|
50
48
|
|
51
49
|
describe ".first" do
|
52
50
|
it "should return one instance of the calling class" do
|
53
|
-
expect(ModelIntegrationSpec::Basic.first).to eq
|
51
|
+
expect(ModelIntegrationSpec::Basic.first).to eq test_instance
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
58
56
|
describe "with multiple objects" do
|
59
|
-
let!(:test_instance1) { ModelIntegrationSpec::Basic.create!(foo: ['Beta'], bar: ['Chips'])
|
60
|
-
let!(:test_instance2) { ModelIntegrationSpec::Basic.create!(foo: ['Alpha'], bar: ['Peanuts'])
|
61
|
-
let!(:test_instance3) { ModelIntegrationSpec::Basic.create!(foo: ['Sigma'], bar: ['Peanuts'])
|
57
|
+
let!(:test_instance1) { ModelIntegrationSpec::Basic.create!(foo: ['Beta'], bar: ['Chips'])}
|
58
|
+
let!(:test_instance2) { ModelIntegrationSpec::Basic.create!(foo: ['Alpha'], bar: ['Peanuts'])}
|
59
|
+
let!(:test_instance3) { ModelIntegrationSpec::Basic.create!(foo: ['Sigma'], bar: ['Peanuts'])}
|
62
60
|
|
63
61
|
describe "when the objects are in fedora" do
|
64
62
|
after do
|
@@ -66,34 +64,36 @@ describe "scoped queries" do
|
|
66
64
|
test_instance2.delete
|
67
65
|
test_instance3.delete
|
68
66
|
end
|
67
|
+
|
69
68
|
it "should query" do
|
70
|
-
|
71
|
-
expect(ModelIntegrationSpec::Basic.where(
|
69
|
+
field = ActiveFedora::SolrService.solr_name('foo', type: :string)
|
70
|
+
expect(ModelIntegrationSpec::Basic.where(field => 'Beta')).to eq [test_instance1]
|
71
|
+
expect(ModelIntegrationSpec::Basic.where('foo' => 'Beta')).to eq [test_instance1]
|
72
72
|
end
|
73
73
|
it "should order" do
|
74
|
-
expect(ModelIntegrationSpec::Basic.order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc')).to eq
|
74
|
+
expect(ModelIntegrationSpec::Basic.order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc')).to eq [test_instance2, test_instance1, test_instance3]
|
75
75
|
end
|
76
76
|
it "should limit" do
|
77
|
-
expect(ModelIntegrationSpec::Basic.limit(1)).to eq
|
77
|
+
expect(ModelIntegrationSpec::Basic.limit(1)).to eq [test_instance1]
|
78
78
|
end
|
79
79
|
it "should offset" do
|
80
|
-
expect(ModelIntegrationSpec::Basic.offset(1)).to eq
|
80
|
+
expect(ModelIntegrationSpec::Basic.offset(1)).to eq [test_instance2, test_instance3]
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should chain queries" do
|
84
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc').limit(1)).to eq
|
84
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').order(ActiveFedora::SolrService.solr_name('foo', :sortable) + ' asc').limit(1)).to eq [test_instance2]
|
85
85
|
end
|
86
86
|
|
87
87
|
it "should wrap string conditions with parentheses" do
|
88
|
-
expect(ModelIntegrationSpec::Basic.where("foo:bar OR bar:baz").where_values).to eq
|
88
|
+
expect(ModelIntegrationSpec::Basic.where("foo:bar OR bar:baz").where_values).to eq ["(foo:bar OR bar:baz)"]
|
89
89
|
end
|
90
90
|
|
91
91
|
it "should chain where queries" do
|
92
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').where("#{ActiveFedora::SolrService.solr_name('foo', type: :string)}:bar").where_values).to eq
|
92
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').where("#{ActiveFedora::SolrService.solr_name('foo', type: :string)}:bar").where_values).to eq ["#{ActiveFedora::SolrService.solr_name('bar', type: :string)}:Peanuts", "(#{ActiveFedora::SolrService.solr_name('foo', type: :string)}:bar)"]
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should chain count" do
|
96
|
-
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').count).to eq
|
96
|
+
expect(ModelIntegrationSpec::Basic.where(ActiveFedora::SolrService.solr_name('bar', type: :string) => 'Peanuts').count).to eq 2
|
97
97
|
end
|
98
98
|
|
99
99
|
it "calling first should not affect the relation's ability to get all results later" do
|
@@ -113,19 +113,19 @@ describe "scoped queries" do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
describe "when one of the objects in solr isn't in fedora" do
|
116
|
-
let!(:
|
117
|
-
before { test_instance2.
|
116
|
+
let!(:id) { test_instance2.id }
|
117
|
+
before { Ldp::Resource::RdfSource.new(ActiveFedora.fedora.connection, test_instance2.uri).delete }
|
118
118
|
after do
|
119
119
|
ActiveFedora::SolrService.instance.conn.tap do |conn|
|
120
|
-
conn.delete_by_query "id:\"#{
|
120
|
+
conn.delete_by_query "id:\"#{id}\""
|
121
121
|
conn.commit
|
122
122
|
end
|
123
123
|
test_instance1.delete
|
124
124
|
test_instance3.delete
|
125
125
|
end
|
126
126
|
it "should log an error" do
|
127
|
-
expect(ActiveFedora::Base.logger).to receive(:error).with("Although #{
|
128
|
-
expect(ModelIntegrationSpec::Basic.all).to eq
|
127
|
+
expect(ActiveFedora::Base.logger).to receive(:error).with("Although #{id} was found in Solr, it doesn't seem to exist in Fedora. The index is out of synch.")
|
128
|
+
expect(ModelIntegrationSpec::Basic.all).to eq [test_instance1, test_instance3]
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|