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
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::WithMetadata do
|
4
|
+
before do
|
5
|
+
class Sample < ActiveFedora::Base
|
6
|
+
contains :file, class_name: 'SampleFile'
|
7
|
+
end
|
8
|
+
|
9
|
+
class SampleFile < ActiveFedora::File
|
10
|
+
include ActiveFedora::WithMetadata
|
11
|
+
|
12
|
+
metadata do
|
13
|
+
property :title, predicate: ::RDF::DC.title
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Object.send(:remove_const, :SampleFile)
|
20
|
+
Object.send(:remove_const, :Sample)
|
21
|
+
end
|
22
|
+
|
23
|
+
let(:base) { Sample.new }
|
24
|
+
let(:file) { base.file }
|
25
|
+
|
26
|
+
describe "properties" do
|
27
|
+
before do
|
28
|
+
file.title = ['one', 'two']
|
29
|
+
end
|
30
|
+
it "should set and retrieve properties" do
|
31
|
+
expect(file.title).to eq ['one', 'two']
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should track changes" do
|
35
|
+
expect(file.title_changed?).to be true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#save" do
|
40
|
+
before do
|
41
|
+
file.content = "Hey"
|
42
|
+
file.title = ["foo"]
|
43
|
+
base.save
|
44
|
+
base.reload
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should save the metadata too" do
|
48
|
+
expect(base.file.title).to eq ['foo']
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require "active-fedora"
|
2
2
|
module Hydra
|
3
|
-
|
3
|
+
|
4
4
|
# This is an example of a OmDatastream that defines an OM terminology for MODS xml
|
5
5
|
# It focuses on the aspects of MODS that deal with descriptive metadata for published articles
|
6
6
|
# This is not the hydra-head plugin version of this OM Terminology; See https://github.com/projecthydra/hydra-head/blob/master/lib/hydra/mods_article.rb
|
@@ -11,14 +11,14 @@ module Hydra
|
|
11
11
|
# * Defines a term lang_code that maps to "languageTerm[@type=code]"
|
12
12
|
# * Defines a variety of terms, date, last_name, first_name & terms_of_address, that all map to mods:namePart but use varying attributes to distinguish themselves
|
13
13
|
# * Uses proxy terms to define familar terms like start_page and end_page that map to non-intuitive xml structures "extent[@unit=pages]/start" and "extent[@unit=pages]/end"
|
14
|
-
# * Uses proxy terms, publication_url, peer_reviewed, and title, to allow convenient access to frequently used terms
|
14
|
+
# * Uses proxy terms, publication_url, peer_reviewed, and title, to allow convenient access to frequently used terms
|
15
15
|
#
|
16
16
|
# Things to note about the additional methods it defines:
|
17
|
-
#
|
17
|
+
#
|
18
18
|
# * Defines a series of templates, person_template, organization_template, etc. for generating a whole set of xml nodes to insert into the document (note: the new OM::TemplateRegistry provides an even better way to do this)
|
19
19
|
# * Defines a custom method, insert_contributor, that uses the Terminology to manipulate xml documents in specialized ways
|
20
20
|
# * Defines a series of relator_term Hashes that can then be used when generating views, etc. In this case, the Hashes are hard-coded into the Class. Ideally, they might be read from a configuration file or mixed into the class using a module
|
21
|
-
class ModsArticleDatastream < ActiveFedora::OmDatastream
|
21
|
+
class ModsArticleDatastream < ActiveFedora::OmDatastream
|
22
22
|
|
23
23
|
set_terminology do |t|
|
24
24
|
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
|
@@ -153,6 +153,10 @@ module Hydra
|
|
153
153
|
end
|
154
154
|
return builder.doc
|
155
155
|
end
|
156
|
+
|
157
|
+
def prefix(name)
|
158
|
+
"#{name.underscore}__"
|
159
|
+
end
|
156
160
|
|
157
161
|
# Generates a new Person node
|
158
162
|
def self.person_template
|
@@ -505,8 +509,8 @@ module Hydra
|
|
505
509
|
["data", "supporting file", "profile", "lorem ipsum", "dolor"]
|
506
510
|
end
|
507
511
|
|
508
|
-
def to_solr(solr_doc=Hash.new)
|
509
|
-
solr_doc = super
|
512
|
+
def to_solr(solr_doc=Hash.new, opts={})
|
513
|
+
solr_doc = super
|
510
514
|
|
511
515
|
::Solrizer::Extractor.insert_solr_field_value(solr_doc, Solrizer.default_field_mapper.solr_name('object_type', :facetable), "Article")
|
512
516
|
::Solrizer::Extractor.insert_solr_field_value(solr_doc, Solrizer.default_field_mapper.solr_name('mods_journal_title_info', :facetable), "Unknown") if solr_doc["mods_journal_title_info_facet"].nil?
|
@@ -6,9 +6,13 @@ require_relative '../hydra-rights_metadata_datastream.rb'
|
|
6
6
|
#
|
7
7
|
# See lib/samples/sample_thing.rb for a fuller, annotated example of an ActiveFedora Model
|
8
8
|
class ModsArticle < ActiveFedora::Base
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
# Mute deprecation of has_metadata
|
11
|
+
@original_behavior = Deprecation.default_deprecation_behavior
|
12
|
+
Deprecation.default_deprecation_behavior = :silence
|
13
|
+
has_metadata :name => "descMetadata", :type=> Hydra::ModsArticleDatastream
|
11
14
|
has_metadata :name => "rightsMetadata", :type => Hydra::RightsMetadataDatastream
|
12
15
|
has_metadata :name => "properties", :type => ActiveFedora::SimpleDatastream
|
16
|
+
Deprecation.default_deprecation_behavior = @original_behavior
|
13
17
|
|
14
18
|
end
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<rights>rights</rights>
|
10
10
|
<publisher>publisher</publisher>
|
11
11
|
<creation_date>creation date</creation_date>
|
12
|
-
<identifier>jwa:
|
12
|
+
<identifier>jwa:sample_id</identifier>
|
13
13
|
<format>format</format>
|
14
14
|
<extent>extent</extent>
|
15
15
|
<language>language</language>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<field name="rights_text">rights</field>
|
9
9
|
<field name="publisher_field">publisher</field>
|
10
10
|
<field name="creation_date">creation date</field>
|
11
|
-
<field name="identifier_field">jwa:
|
11
|
+
<field name="identifier_field">jwa:sample_id</field>
|
12
12
|
<field name="format_field">format</field>
|
13
13
|
<field name="extent_field">extent</field>
|
14
14
|
<field name="language_field">language</field>
|
@@ -34,11 +34,11 @@ class SpecialThing < ActiveFedora::Base
|
|
34
34
|
#
|
35
35
|
# RELATIONSHIPS
|
36
36
|
#
|
37
|
-
|
37
|
+
|
38
38
|
# This is an example of how you can add a custom relationship to a model
|
39
39
|
# This will allow you to call .derivation on instances of the model to get the _outbound_ "hasDerivation" relationship in the RELS-EXT datastream
|
40
|
-
belongs_to :derivation,
|
40
|
+
belongs_to :derivation, predicate: ActiveFedora::RDF::RelsExt.hasDerivation, class_name: 'SpecialThing'
|
41
41
|
|
42
42
|
# This will allow you to call .inspirations on instances of the model to get a list of all of the objects that assert "hasDerivation" relationships pointing at this object
|
43
|
-
has_many :inspirations,
|
43
|
+
has_many :inspirations, predicate: ActiveFedora::RDF::RelsExt.hasDerivation, class_name: 'SpecialThing'
|
44
44
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
ENV["environment"] ||= 'test'
|
2
2
|
require "bundler/setup"
|
3
3
|
|
4
|
-
|
5
|
-
begin
|
4
|
+
if ENV["COVERAGE"]
|
6
5
|
require 'simplecov'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
require 'coveralls'
|
7
|
+
|
8
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter "/spec/"
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
14
|
require 'active-fedora'
|
14
15
|
require 'rspec'
|
15
|
-
require 'rspec/its'
|
16
16
|
require 'equivalent-xml/rspec_matchers'
|
17
17
|
require 'logger'
|
18
|
+
require 'byebug' unless ENV['TRAVIS']
|
18
19
|
|
19
|
-
ActiveFedora::Base.logger = Logger.new(STDERR)
|
20
|
+
ActiveFedora::Base.logger = Logger.new(STDERR)
|
20
21
|
ActiveFedora::Base.logger.level = Logger::WARN
|
22
|
+
# HttpLogger.logger = Logger.new(STDOUT)
|
23
|
+
# HttpLogger.ignore = [/localhost:8983\/solr/]
|
24
|
+
# HttpLogger.colorize = false
|
25
|
+
# HttpLogger.log_headers = true
|
21
26
|
|
22
27
|
Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f }
|
23
28
|
require 'samples/samples'
|
@@ -34,13 +39,18 @@ restore_spec_configuration
|
|
34
39
|
# Shut those Rails deprecation warnings up
|
35
40
|
ActiveSupport::Deprecation.behavior= Proc.new { |message, callstack| }
|
36
41
|
|
42
|
+
require 'active_fedora/cleaner'
|
37
43
|
RSpec.configure do |config|
|
44
|
+
# Stub out test stuff.
|
45
|
+
config.before(:each) do
|
46
|
+
ActiveFedora::Cleaner.clean!
|
47
|
+
end
|
48
|
+
config.after(:each) do
|
49
|
+
# cleanout_fedora
|
50
|
+
end
|
51
|
+
config.order = :random if ENV['CI']
|
38
52
|
end
|
39
53
|
|
40
54
|
def fixture(file)
|
41
55
|
File.open(File.join(File.dirname(__FILE__), 'fixtures', file), 'rb')
|
42
56
|
end
|
43
|
-
|
44
|
-
def solr_uri(uri)
|
45
|
-
uri.gsub(/(:)/, "\\:").gsub(/(\/)/,"\\/")
|
46
|
-
end
|
@@ -1,18 +1,14 @@
|
|
1
1
|
shared_examples_for "An ActiveModel" do
|
2
2
|
def assert(test, *args)
|
3
|
-
expect(test).to
|
4
|
-
end
|
5
|
-
|
6
|
-
def assert_equal(test, obj)
|
7
|
-
expect(test).to eq(obj)
|
3
|
+
expect(test).to be true
|
8
4
|
end
|
9
5
|
|
10
6
|
def assert_kind_of(klass, inspected_object)
|
11
7
|
expect(inspected_object).to be_kind_of(klass)
|
12
8
|
end
|
13
9
|
|
14
|
-
def
|
15
|
-
expect(
|
10
|
+
def assert_equal(the_other, one)
|
11
|
+
expect(one).to eq the_other
|
16
12
|
end
|
17
13
|
|
18
14
|
include ActiveModel::Lint::Tests
|
@@ -5,6 +5,9 @@ require 'config_helper'
|
|
5
5
|
|
6
6
|
describe ActiveFedora do
|
7
7
|
|
8
|
+
before(:each) do
|
9
|
+
restore_spec_configuration
|
10
|
+
end
|
8
11
|
after :all do
|
9
12
|
unstub_rails
|
10
13
|
# Restore to default fedora configs
|
@@ -14,20 +17,20 @@ describe ActiveFedora do
|
|
14
17
|
describe "initialization methods" do
|
15
18
|
describe "environment" do
|
16
19
|
it "should use config_options[:environment] if set" do
|
17
|
-
allow(ActiveFedora).to
|
20
|
+
allow(ActiveFedora).to receive(:config_options).and_return(:environment=>"ballyhoo")
|
18
21
|
expect(ActiveFedora.environment).to eql("ballyhoo")
|
19
22
|
end
|
20
23
|
|
21
24
|
it "should use Rails.env if no config_options and Rails.env is set" do
|
22
25
|
stub_rails(:env => "bedbugs")
|
23
|
-
allow(ActiveFedora).to
|
26
|
+
allow(ActiveFedora).to receive(:config_options).and_return({})
|
24
27
|
expect(ActiveFedora.environment).to eql("bedbugs")
|
25
28
|
unstub_rails
|
26
29
|
end
|
27
30
|
|
28
31
|
it "should use ENV['environment'] if neither config_options nor Rails.env are set" do
|
29
32
|
ENV['environment'] = "wichita"
|
30
|
-
allow(ActiveFedora).to
|
33
|
+
allow(ActiveFedora).to receive(:config_options).and_return({})
|
31
34
|
expect(ActiveFedora.environment).to eql("wichita")
|
32
35
|
ENV['environment']='test'
|
33
36
|
end
|
@@ -35,15 +38,15 @@ describe ActiveFedora do
|
|
35
38
|
it "should use ENV['RAILS_ENV'] and log a warning if none of the above are set" do
|
36
39
|
ENV['environment']=nil
|
37
40
|
ENV['RAILS_ENV'] = "rails_env"
|
38
|
-
expect
|
41
|
+
expect{ ActiveFedora.environment }.to raise_error(RuntimeError, "You're depending on RAILS_ENV for setting your environment. Please use ENV['environment'] for non-rails environment setting: 'rake foo:bar environment=test'")
|
39
42
|
ENV['environment']='test'
|
40
43
|
end
|
41
44
|
|
42
45
|
it "should be development if none of the above are present" do
|
43
46
|
ENV['environment']=nil
|
44
47
|
ENV['RAILS_ENV'] = nil
|
45
|
-
allow(ActiveFedora).to
|
46
|
-
expect(ActiveFedora.environment).to eq
|
48
|
+
allow(ActiveFedora).to receive(:config_options).and_return({})
|
49
|
+
expect(ActiveFedora.environment).to eq 'development'
|
47
50
|
ENV['environment']="test"
|
48
51
|
end
|
49
52
|
end
|
@@ -51,7 +54,7 @@ describe ActiveFedora do
|
|
51
54
|
|
52
55
|
describe ".init" do
|
53
56
|
|
54
|
-
after(:
|
57
|
+
after(:each) do
|
55
58
|
# Restore to default fedora configs
|
56
59
|
ActiveFedora.init(:environment => "test", :fedora_config_path => File.join(File.dirname(__FILE__), "..", "..", "config", "fedora.yml"))
|
57
60
|
end
|
@@ -59,13 +62,13 @@ describe ActiveFedora do
|
|
59
62
|
describe "outside of rails" do
|
60
63
|
it "should load the passed config if explicit config passed in as a string" do
|
61
64
|
ActiveFedora.init(:fedora_config_path=>'./spec/fixtures/rails_root/config/fedora.yml', :environment => 'test')
|
62
|
-
expect(ActiveFedora.config.credentials).to eq(
|
65
|
+
expect(ActiveFedora.config.credentials).to eq(url: "http://testhost.com:8983/fedora", :user=>'fedoraAdmin', :password=>'fedoraAdmin')
|
63
66
|
end
|
64
67
|
end
|
65
68
|
|
66
69
|
describe "within rails" do
|
67
70
|
|
68
|
-
after(:
|
71
|
+
after(:each) do
|
69
72
|
unstub_rails
|
70
73
|
end
|
71
74
|
|
@@ -78,13 +81,13 @@ describe ActiveFedora do
|
|
78
81
|
fedora_config_path = File.expand_path(File.join(File.dirname(__FILE__),"../fixtures/rails_root/config/fedora.yml"))
|
79
82
|
solr_config_path = File.expand_path(File.join(File.dirname(__FILE__),"../fixtures/rails_root/config/solr.yml"))
|
80
83
|
pred_config_path = File.expand_path(File.join(File.dirname(__FILE__),"../fixtures/rails_root/config/predicate_mappings.yml"))
|
81
|
-
|
84
|
+
|
82
85
|
allow(File).to receive(:open).with(fedora_config_path).and_return(fedora_config)
|
83
86
|
allow(File).to receive(:open).with(solr_config_path).and_return(solr_config)
|
84
87
|
allow(ActiveFedora::SolrService).to receive(:load_mappings) #For the solrizer solr_mappings.yml
|
85
88
|
|
86
89
|
ActiveFedora.init(:fedora_config_path=>fedora_config_path,:solr_config_path=>solr_config_path)
|
87
|
-
expect(ActiveFedora.solr.class).to eq
|
90
|
+
expect(ActiveFedora.solr.class).to eq ActiveFedora::SolrService
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
@@ -94,7 +97,7 @@ describe ActiveFedora do
|
|
94
97
|
|
95
98
|
stub_rails(:root=>File.join(File.dirname(__FILE__),"../fixtures/rails_root"))
|
96
99
|
ActiveFedora.init()
|
97
|
-
expect(ActiveFedora.config.credentials[:url]).to eq
|
100
|
+
expect(ActiveFedora.config.credentials[:url]).to eq "http://testhost.com:8983/fedora"
|
98
101
|
end
|
99
102
|
end
|
100
103
|
end
|
@@ -111,19 +114,19 @@ describe ActiveFedora do
|
|
111
114
|
end
|
112
115
|
end
|
113
116
|
it "should return class constants based on strings" do
|
114
|
-
expect(ActiveFedora.class_from_string("Om")).to eq
|
115
|
-
expect(ActiveFedora.class_from_string("ActiveFedora::RDF::Indexing")).to eq
|
116
|
-
expect(ActiveFedora.class_from_string("Indexing", ActiveFedora::RDF)).to eq
|
117
|
+
expect(ActiveFedora.class_from_string("Om")).to eq Om
|
118
|
+
expect(ActiveFedora.class_from_string("ActiveFedora::RDF::Indexing")).to eq ActiveFedora::RDF::Indexing
|
119
|
+
expect(ActiveFedora.class_from_string("Indexing", ActiveFedora::RDF)).to eq ActiveFedora::RDF::Indexing
|
117
120
|
end
|
118
121
|
|
119
122
|
it "should find sibling classes" do
|
120
|
-
expect(ActiveFedora.class_from_string("SiblingClass", ParentClass::OtherSiblingClass)).to eq
|
123
|
+
expect(ActiveFedora.class_from_string("SiblingClass", ParentClass::OtherSiblingClass)).to eq ParentClass::SiblingClass
|
121
124
|
end
|
122
125
|
|
123
126
|
it "should raise a NameError if the class isn't found" do
|
124
127
|
expect {
|
125
128
|
ActiveFedora.class_from_string("FooClass", ParentClass::OtherSiblingClass)
|
126
|
-
}.to raise_error NameError,
|
129
|
+
}.to raise_error NameError, "uninitialized constant FooClass"
|
127
130
|
end
|
128
131
|
end
|
129
132
|
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::AttachedFiles do
|
4
|
+
subject { ActiveFedora::Base.new }
|
5
|
+
describe "contains" do
|
6
|
+
before do
|
7
|
+
class FooHistory < ActiveFedora::Base
|
8
|
+
contains 'dsid', class_name: 'ActiveFedora::SimpleDatastream'
|
9
|
+
contains 'complex_ds', autocreate: true, class_name: 'Z'
|
10
|
+
contains 'thumbnail'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
after do
|
14
|
+
Object.send(:remove_const, :FooHistory)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a child_resource_reflection" do
|
18
|
+
expect(FooHistory.child_resource_reflections).to have_key(:dsid)
|
19
|
+
expect(FooHistory.child_resource_reflections).to have_key(:thumbnail)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should let you override defaults" do
|
23
|
+
expect(FooHistory.child_resource_reflections[:complex_ds].options).to include(autocreate: true)
|
24
|
+
expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq 'Z'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should raise an error if you don't give a dsid" do
|
28
|
+
expect{ FooHistory.contains nil, type: ActiveFedora::SimpleDatastream }.to raise_error ArgumentError,
|
29
|
+
"You must provide a name (dsid) for the datastream"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.has_metadata' do
|
34
|
+
before do
|
35
|
+
@original_behavior = Deprecation.default_deprecation_behavior
|
36
|
+
Deprecation.default_deprecation_behavior = :silence
|
37
|
+
class FooHistory < ActiveFedora::Base
|
38
|
+
has_metadata :name => 'dsid', type: ActiveFedora::SimpleDatastream
|
39
|
+
has_metadata 'complex_ds', autocreate: true, type: 'Z'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
after do
|
43
|
+
Deprecation.default_deprecation_behavior = @original_behavior
|
44
|
+
Object.send(:remove_const, :FooHistory)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should have a child_resource_reflection" do
|
48
|
+
expect(FooHistory.child_resource_reflections).to have_key(:dsid)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should have reasonable defaults" do
|
52
|
+
expect(FooHistory.child_resource_reflections[:dsid].options).to include(class_name: 'ActiveFedora::SimpleDatastream')
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should let you override defaults" do
|
56
|
+
expect(FooHistory.child_resource_reflections[:complex_ds].options).to include(autocreate: true)
|
57
|
+
expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq 'Z'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise an error if you don't give a type" do
|
61
|
+
expect{ FooHistory.has_metadata "bob" }.to raise_error ArgumentError,
|
62
|
+
"You must provide a :type property for the datastream 'bob'"
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should raise an error if you don't give a dsid" do
|
66
|
+
expect{ FooHistory.has_metadata type: ActiveFedora::SimpleDatastream }.to raise_error ArgumentError,
|
67
|
+
"You must provide a name (dsid) for the datastream"
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "creates accessors" do
|
71
|
+
subject { FooHistory.new }
|
72
|
+
it "should exist on the instance" do
|
73
|
+
expect(subject.dsid).to eq subject.attached_files['dsid']
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '.has_file_datastream' do
|
79
|
+
before do
|
80
|
+
class FooHistory < ActiveFedora::Base
|
81
|
+
has_file_datastream :name => 'dsid'
|
82
|
+
has_file_datastream 'another'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
after do
|
86
|
+
Object.send(:remove_const, :FooHistory)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have reasonable defaults" do
|
90
|
+
expect(FooHistory.child_resource_reflections[:dsid].klass).to eq ActiveFedora::File
|
91
|
+
expect(FooHistory.child_resource_reflections[:another].klass).to eq ActiveFedora::File
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#add_file_datastream" do
|
96
|
+
before do
|
97
|
+
class Bar < ActiveFedora::File; end
|
98
|
+
|
99
|
+
class FooHistory < ActiveFedora::Base
|
100
|
+
contains :content, class_name: 'Bar'
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
after do
|
105
|
+
Object.send(:remove_const, :Bar)
|
106
|
+
Object.send(:remove_const, :FooHistory)
|
107
|
+
end
|
108
|
+
let(:container) { FooHistory.new }
|
109
|
+
|
110
|
+
context "a reflection matches the :dsid property" do
|
111
|
+
it "should build the reflection" do
|
112
|
+
container.add_file_datastream('blah', dsid: 'content')
|
113
|
+
expect(container.content).to be_instance_of Bar
|
114
|
+
expect(container.content.content).to eq 'blah'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "no reflection matches the :dsid property" do
|
119
|
+
it "should create a singleton reflection and build it" do
|
120
|
+
container.add_file_datastream('blah', dsid: 'fizz')
|
121
|
+
expect(container.fizz).to be_instance_of ActiveFedora::File
|
122
|
+
expect(container.fizz.content).to eq 'blah'
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#serialize_attached_files" do
|
128
|
+
it "should touch each file" do
|
129
|
+
m1 = double()
|
130
|
+
m2 = double()
|
131
|
+
|
132
|
+
expect(m1).to receive(:serialize!)
|
133
|
+
expect(m2).to receive(:serialize!)
|
134
|
+
allow(subject).to receive(:attached_files).and_return(:m1 => m1, :m2 => m2)
|
135
|
+
subject.serialize_attached_files
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#accessor_name" do
|
140
|
+
it "should use the name" do
|
141
|
+
expect(subject.send(:accessor_name, 'abc')).to eq 'abc'
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should use the name" do
|
145
|
+
expect(subject.send(:accessor_name, 'ARCHIVAL_XML')).to eq 'ARCHIVAL_XML'
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should use the name" do
|
149
|
+
expect(subject.send(:accessor_name, 'descMetadata')).to eq 'descMetadata'
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should hash-erize underscores" do
|
153
|
+
expect(subject.send(:accessor_name, 'a-b')).to eq 'a_b'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "#attached_files" do
|
158
|
+
it "should return the datastream hash proxy" do
|
159
|
+
allow(subject).to receive(:load_datastreams)
|
160
|
+
expect(subject.attached_files).to be_a_kind_of(ActiveFedora::FilesHash)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#attach_file" do
|
165
|
+
let(:dsid) { 'Abc' }
|
166
|
+
let(:file) { ActiveFedora::File.new }
|
167
|
+
before do
|
168
|
+
subject.attach_file(file, dsid)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should add the datastream to the object" do
|
172
|
+
expect(subject.attached_files['Abc']).to eq file
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "dynamic accessors" do
|
176
|
+
context "when the file is named with dash" do
|
177
|
+
let(:dsid) { 'eac-cpf' }
|
178
|
+
it "should convert dashes to underscores" do
|
179
|
+
expect(subject.eac_cpf).to eq file
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "when the file is named with underscore" do
|
184
|
+
let(:dsid) { 'foo_bar' }
|
185
|
+
it "should preserve the underscore" do
|
186
|
+
expect(subject.foo_bar).to eq file
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "#metadata_streams" do
|
193
|
+
it "should only be metadata datastreams" do
|
194
|
+
ds1 = double(:metadata? => true)
|
195
|
+
ds2 = double(:metadata? => true)
|
196
|
+
ds3 = double(:metadata? => true)
|
197
|
+
file_ds = double(:metadata? => false)
|
198
|
+
allow(subject).to receive(:attached_files).and_return(:a => ds1, :b => ds2, :c => ds3, :e => file_ds)
|
199
|
+
expect(subject.metadata_streams).to include(ds1, ds2, ds3)
|
200
|
+
expect(subject.metadata_streams).to_not include(file_ds)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|