active-fedora 10.0.0.beta1 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/active_fedora/associations/collection_association.rb +2 -1
- data/lib/active_fedora/change_set.rb +2 -1
- data/lib/active_fedora/file/attributes.rb +5 -5
- data/lib/active_fedora/file.rb +15 -19
- data/lib/active_fedora/indexing_service.rb +0 -1
- data/lib/active_fedora/railtie.rb +4 -1
- data/lib/active_fedora/rake_support.rb +17 -8
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/default_metadata_class_factory.rb +31 -0
- data/lib/active_fedora/with_metadata/default_schema.rb +15 -0
- data/lib/active_fedora/with_metadata/default_strategy.rb +12 -0
- data/lib/active_fedora/with_metadata/metadata_node.rb +12 -1
- data/lib/active_fedora/with_metadata/sweet_jpl_terms.rb +10 -0
- data/lib/active_fedora/with_metadata.rb +11 -10
- data/lib/generators/active_fedora/config/solr/templates/solr/config/solrconfig.xml +0 -1
- data/solr/config/solrconfig.xml +0 -1
- data/spec/integration/file_spec.rb +1 -1
- data/spec/integration/indexing_spec.rb +31 -0
- data/spec/integration/om_datastream_spec.rb +8 -8
- data/spec/integration/with_metadata_spec.rb +25 -0
- data/spec/unit/file_spec.rb +34 -0
- data/spec/unit/has_many_association_spec.rb +20 -0
- data/spec/unit/indexing_spec.rb +0 -4
- data/spec/unit/query_spec.rb +3 -3
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +28 -0
- metadata +9 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1467d74478a1ea4aa80bcb17add4c7f34b798af7
|
|
4
|
+
data.tar.gz: 5e15c3f279e391f4acf2fd0c87a5554e0df65c7d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c65e10a31bc1b766e4837eabfa198a3fe873b3ba93963d46edaaf0efb16c509f7091752336bf4608ea7e2fbccab5f899644777bb187585f1f197560b963b52b3
|
|
7
|
+
data.tar.gz: 03dcfbf9f6c33829ac0235a5108985b29a62cbbe8b9782a24cee195f7962749010c4d75559f2f7e9ffade94f5acaeb58474465a021c43c25e2b370e1ba7d80cd
|
data/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Description
|
|
|
9
9
|
ActiveFedora is a Ruby gem for creating and
|
|
10
10
|
managing objects in the Fedora Repository Architecture
|
|
11
11
|
([http://fedora-commons.org](http://fedora-commons.org)). ActiveFedora
|
|
12
|
-
is loosely based on “ActiveRecord” in Rails. Version 9.0+ works with Fedora 4 and prior versions work on Fedora 3. Version 9.2+ works with Solr 4.10.
|
|
12
|
+
is loosely based on “ActiveRecord” in Rails. Version 9.0+ works with Fedora 4 and prior versions work on Fedora 3. Version 9.2+ works with Solr 4.10. Version 10.0+ works with Fedora >= 4.5.1.
|
|
13
13
|
|
|
14
14
|
Getting Help
|
|
15
15
|
------------
|
|
@@ -101,4 +101,3 @@ Creator: Matt Zumwalt ([MediaShelf](http://yourmediashelf.com))
|
|
|
101
101
|
Developers:
|
|
102
102
|
Justin Coyne, McClain Looney & Eddie Shin
|
|
103
103
|
([MediaShelf](http://yourmediashelf.com)), Rick Johnson (Notre Dame)
|
|
104
|
-
|
|
@@ -29,9 +29,10 @@ module ActiveFedora
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
# Implements the ids reader method, e.g. foo.item_ids for Foo.has_many :items
|
|
32
|
+
# it discards any ids where the record it belongs to was marked for destruction.
|
|
32
33
|
def ids_reader
|
|
33
34
|
if loaded?
|
|
34
|
-
load_target.map(&:id)
|
|
35
|
+
load_target.reject(&:marked_for_destruction?).map(&:id)
|
|
35
36
|
else
|
|
36
37
|
load_from_solr.map(&:id)
|
|
37
38
|
end
|
|
@@ -17,7 +17,8 @@ module ActiveFedora
|
|
|
17
17
|
# @return [Hash<RDF::URI, RDF::Queryable::Enumerator>] hash of predicate uris to statements
|
|
18
18
|
def changes
|
|
19
19
|
@changes ||= changed_attributes.each_with_object({}) do |key, result|
|
|
20
|
-
if object.
|
|
20
|
+
if object.association(key.to_sym).present?
|
|
21
|
+
# This is always an ActiveFedora::Reflection::RDFPropertyReflection
|
|
21
22
|
predicate = object.association(key.to_sym).reflection.predicate
|
|
22
23
|
result[predicate] = graph.query(subject: object.rdf_subject, predicate: predicate)
|
|
23
24
|
elsif object.class.properties.keys.include?(key)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
module ActiveFedora::File::Attributes
|
|
2
|
-
|
|
2
|
+
delegate :mime_type=, to: :metadata
|
|
3
3
|
|
|
4
4
|
def assign_attributes(_)
|
|
5
5
|
# nop
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def mime_type
|
|
9
|
-
|
|
9
|
+
fetch_mime_type
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def original_name
|
|
@@ -29,7 +29,7 @@ module ActiveFedora::File::Attributes
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def dirty_size
|
|
32
|
-
content.size if
|
|
32
|
+
content.size if content_changed? && content.respond_to?(:size)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
def size
|
|
@@ -72,8 +72,8 @@ module ActiveFedora::File::Attributes
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def fetch_mime_type
|
|
75
|
-
return default_mime_type if new_record?
|
|
76
|
-
|
|
75
|
+
return default_mime_type if new_record? && metadata.mime_type.blank?
|
|
76
|
+
metadata.mime_type.first
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
def fetch_original_name
|
data/lib/active_fedora/file.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'deprecation'
|
|
2
|
-
|
|
3
1
|
module ActiveFedora
|
|
4
2
|
# An LDP NonRDFSource. The base class for a bytestream stored in the repository.
|
|
5
3
|
class File
|
|
@@ -99,11 +97,8 @@ module ActiveFedora
|
|
|
99
97
|
end
|
|
100
98
|
|
|
101
99
|
def attribute_will_change!(attr)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
else
|
|
105
|
-
super
|
|
106
|
-
end
|
|
100
|
+
return super unless attr == 'content'
|
|
101
|
+
changed_attributes['content'] = true
|
|
107
102
|
end
|
|
108
103
|
|
|
109
104
|
def remote_content
|
|
@@ -124,8 +119,13 @@ module ActiveFedora
|
|
|
124
119
|
local_or_remote_content(false) != @ds_content
|
|
125
120
|
end
|
|
126
121
|
|
|
122
|
+
def metadata_changed?
|
|
123
|
+
return false if new_record? || links['describedby'].blank?
|
|
124
|
+
metadata.changed?
|
|
125
|
+
end
|
|
126
|
+
|
|
127
127
|
def changed?
|
|
128
|
-
super || content_changed?
|
|
128
|
+
super || content_changed? || metadata_changed?
|
|
129
129
|
end
|
|
130
130
|
|
|
131
131
|
def inspect
|
|
@@ -170,6 +170,12 @@ module ActiveFedora
|
|
|
170
170
|
|
|
171
171
|
private
|
|
172
172
|
|
|
173
|
+
def create_or_update(*options)
|
|
174
|
+
super.tap do
|
|
175
|
+
metadata.save if metadata.changed?
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
173
179
|
# Rack::Test::UploadedFile is often set via content=, however it's not an IO, though it wraps an io object.
|
|
174
180
|
def behaves_like_io?(obj)
|
|
175
181
|
[IO, Tempfile, StringIO].any? { |klass| obj.is_a? klass } || (defined?(Rack) && obj.is_a?(Rack::Test::UploadedFile))
|
|
@@ -201,17 +207,7 @@ module ActiveFedora
|
|
|
201
207
|
return @content if new_record?
|
|
202
208
|
|
|
203
209
|
@content ||= ensure_fetch ? remote_content : @ds_content
|
|
204
|
-
|
|
205
|
-
if behaves_like_io?(@content)
|
|
206
|
-
begin
|
|
207
|
-
@content.rewind
|
|
208
|
-
@content.read
|
|
209
|
-
ensure
|
|
210
|
-
@content.rewind
|
|
211
|
-
end
|
|
212
|
-
else
|
|
213
|
-
@content
|
|
214
|
-
end
|
|
210
|
+
@content.rewind if behaves_like_io?(@content)
|
|
215
211
|
@content
|
|
216
212
|
end
|
|
217
213
|
end
|
|
@@ -38,7 +38,6 @@ module ActiveFedora
|
|
|
38
38
|
solr_doc = {}
|
|
39
39
|
Solrizer.set_field(solr_doc, 'system_create', c_time, :stored_sortable)
|
|
40
40
|
Solrizer.set_field(solr_doc, 'system_modified', m_time, :stored_sortable)
|
|
41
|
-
Solrizer.set_field(solr_doc, 'active_fedora_model', object.class.inspect, :stored_sortable)
|
|
42
41
|
solr_doc[QueryResultBuilder::HAS_MODEL_SOLR_FIELD] = object.has_model
|
|
43
42
|
solr_doc[ActiveFedora.id_field.to_sym] = object.id
|
|
44
43
|
solr_doc[self.class.profile_solr_name] = profile_service.new(object).export
|
|
@@ -8,7 +8,10 @@ module ActiveFedora
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
initializer "active_fedora.logger" do
|
|
11
|
-
ActiveSupport.on_load(:active_fedora)
|
|
11
|
+
ActiveSupport.on_load(:active_fedora) do
|
|
12
|
+
self.logger ||= ::Rails.logger
|
|
13
|
+
Solrizer.logger ||= logger
|
|
14
|
+
end
|
|
12
15
|
end
|
|
13
16
|
|
|
14
17
|
generators do
|
|
@@ -4,17 +4,18 @@ def with_test_server(&block)
|
|
|
4
4
|
with_server('test', &block)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
def with_server(environment
|
|
7
|
+
def with_server(environment)
|
|
8
8
|
return yield if ENV["#{environment}_SERVER_STARTED"]
|
|
9
9
|
|
|
10
10
|
ENV["#{environment}_SERVER_STARTED"] = 'true'
|
|
11
11
|
|
|
12
12
|
# setting port: nil assigns a random port.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
solr_defaults = { port: nil, verbose: true, managed: true }
|
|
14
|
+
fcrepo_defaults = { port: nil, verbose: true, managed: true,
|
|
15
|
+
enable_jms: false, fcrepo_home_dir: "fcrepo4-#{environment}-data" }
|
|
16
|
+
|
|
17
|
+
SolrWrapper.wrap(load_config(:solr, environment, solr_defaults)) do |solr|
|
|
18
|
+
ENV["SOLR_#{environment.upcase}_PORT"] = solr.port.to_s
|
|
18
19
|
solr_config_path = File.join('solr', 'config')
|
|
19
20
|
# Check to see if configs exist in a path relative to the working directory
|
|
20
21
|
unless Dir.exist?(solr_config_path)
|
|
@@ -23,11 +24,19 @@ def with_server(environment, fcrepo_port: nil, solr_port: nil)
|
|
|
23
24
|
solr_config_path = File.join(File.expand_path("../..", File.dirname(__FILE__)), "solr", "config")
|
|
24
25
|
end
|
|
25
26
|
solr.with_collection(name: "hydra-#{environment}", dir: solr_config_path) do
|
|
26
|
-
FcrepoWrapper.wrap(
|
|
27
|
-
ENV["FCREPO_#{environment.upcase}_PORT"] = fcrepo.port
|
|
27
|
+
FcrepoWrapper.wrap(load_config(:fcrepo, environment, fcrepo_defaults)) do |fcrepo|
|
|
28
|
+
ENV["FCREPO_#{environment.upcase}_PORT"] = fcrepo.port.to_s
|
|
28
29
|
yield
|
|
29
30
|
end
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
ENV["#{environment}_SERVER_STARTED"] = 'false'
|
|
33
34
|
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def load_config(service, environment, defaults)
|
|
39
|
+
config_file = environment == 'test' ? "config/#{service}_wrapper_test.yml" : ".#{service}_wrapper"
|
|
40
|
+
return { config: config_file } if File.exist?(config_file)
|
|
41
|
+
defaults
|
|
42
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This builds classes for metadata nodes (nodes that describe a binary)
|
|
2
|
+
module ActiveFedora::WithMetadata
|
|
3
|
+
class DefaultMetadataClassFactory
|
|
4
|
+
class_attribute :metadata_base_class, :file_metadata_schemas, :file_metadata_strategy
|
|
5
|
+
self.metadata_base_class = MetadataNode
|
|
6
|
+
self.file_metadata_schemas = [DefaultSchema]
|
|
7
|
+
self.file_metadata_strategy = DefaultStrategy
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
def build(parent, &block)
|
|
11
|
+
create_class(parent).tap do |resource_class|
|
|
12
|
+
file_metadata_schemas.each do |schema|
|
|
13
|
+
resource_class.apply_schema(schema, file_metadata_strategy)
|
|
14
|
+
end
|
|
15
|
+
resource_class.exec_block(&block) if block_given?
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
# Make a subclass of MetadataNode named GeneratedMetadataSchema and set its
|
|
22
|
+
# parent_class attribute to have the value of the current class.
|
|
23
|
+
def create_class(parent_klass)
|
|
24
|
+
Class.new(metadata_base_class).tap do |klass|
|
|
25
|
+
parent_klass.const_set(:GeneratedMetadataSchema, klass)
|
|
26
|
+
klass.parent_class = parent_klass
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# These are the default properties defined on a resource that has WithMetadata
|
|
2
|
+
# added to it. This is most commonly used with ActiveFedora::File, when we want
|
|
3
|
+
# to add rdf triples to a non-rdf resource and have them persisted.
|
|
4
|
+
module ActiveFedora::WithMetadata
|
|
5
|
+
class DefaultSchema < ActiveTriples::Schema
|
|
6
|
+
property :label, predicate: ::RDF::RDFS.label
|
|
7
|
+
property :file_name, predicate: ::RDF::Vocab::EBUCore.filename
|
|
8
|
+
property :file_size, predicate: ::RDF::Vocab::EBUCore.fileSize
|
|
9
|
+
property :date_created, predicate: ::RDF::Vocab::EBUCore.dateCreated
|
|
10
|
+
property :date_modified, predicate: ::RDF::Vocab::EBUCore.dateModified
|
|
11
|
+
property :byte_order, predicate: SweetJPLTerms.byteOrder
|
|
12
|
+
# This is a server-managed predicate which means Fedora does not let us change it.
|
|
13
|
+
property :file_hash, predicate: ::RDF::Vocab::PREMIS.hasMessageDigest
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module ActiveFedora::WithMetadata
|
|
2
|
+
class DefaultStrategy < ActiveTriples::ExtensionStrategy
|
|
3
|
+
# override apply method to check if property already exists or reciever already has predicate defined.
|
|
4
|
+
# Do not add property if the rdf_resource already responds to the property name
|
|
5
|
+
# Do not add property if the rdf_resource already has a property with the same predicate.
|
|
6
|
+
def self.apply(resource, property)
|
|
7
|
+
return if resource.respond_to?(property.name)
|
|
8
|
+
return if resource.properties.any? { |p| p[1].predicate == property.predicate }
|
|
9
|
+
resource.property property.name, property.to_h
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -4,6 +4,12 @@ module ActiveFedora
|
|
|
4
4
|
include ActiveModel::Dirty
|
|
5
5
|
attr_reader :file
|
|
6
6
|
|
|
7
|
+
# mime_type is treated differently than all the other metadata properties,
|
|
8
|
+
# in that it can be set at file-create time (as a HTTP post header) and be
|
|
9
|
+
# updated (using SPARQL update) on the metadata-node. Therefore, it is in
|
|
10
|
+
# this class rather than being in the DefaultSchema.
|
|
11
|
+
property :mime_type, predicate: ::RDF::Vocab::EBUCore.hasMimeType
|
|
12
|
+
|
|
7
13
|
def initialize(file)
|
|
8
14
|
@file = file
|
|
9
15
|
super(file.uri, ldp_source.graph)
|
|
@@ -45,10 +51,15 @@ module ActiveFedora
|
|
|
45
51
|
|
|
46
52
|
def changed_attributes
|
|
47
53
|
super.tap do |changed|
|
|
48
|
-
changed['type'] = true if type.present?
|
|
54
|
+
changed['type'] = true if type.present? && new_record?
|
|
49
55
|
end
|
|
50
56
|
end
|
|
51
57
|
|
|
58
|
+
# Conform to the ActiveFedora::Base API
|
|
59
|
+
def association(_)
|
|
60
|
+
[]
|
|
61
|
+
end
|
|
62
|
+
|
|
52
63
|
private
|
|
53
64
|
|
|
54
65
|
def changes_for_update
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require 'rdf'
|
|
2
|
+
module ActiveFedora::WithMetadata
|
|
3
|
+
class SweetJPLTerms < RDF::StrictVocabulary('http://sweet.jpl.nasa.gov/2.2/reprDataFormat.owl#')
|
|
4
|
+
# Property definitions
|
|
5
|
+
property :byteOrder,
|
|
6
|
+
comment: ['Byte Order.'.freeze],
|
|
7
|
+
range: 'xsd:string'.freeze,
|
|
8
|
+
label: 'Byte Order'.freeze
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -4,6 +4,15 @@ module ActiveFedora
|
|
|
4
4
|
extend ActiveSupport::Autoload
|
|
5
5
|
|
|
6
6
|
autoload :MetadataNode
|
|
7
|
+
autoload :SweetJPLTerms
|
|
8
|
+
autoload :DefaultStrategy
|
|
9
|
+
autoload :DefaultSchema
|
|
10
|
+
autoload :DefaultMetadataClassFactory
|
|
11
|
+
|
|
12
|
+
included do
|
|
13
|
+
class_attribute :metadata_class_factory
|
|
14
|
+
self.metadata_class_factory = DefaultMetadataClassFactory
|
|
15
|
+
end
|
|
7
16
|
|
|
8
17
|
def metadata_node
|
|
9
18
|
@metadata_node ||= self.class.metadata_schema.new(self)
|
|
@@ -17,19 +26,11 @@ module ActiveFedora
|
|
|
17
26
|
|
|
18
27
|
module ClassMethods
|
|
19
28
|
def metadata(&block)
|
|
20
|
-
metadata_schema.
|
|
29
|
+
@metadata_schema = metadata_class_factory.build(self, &block)
|
|
21
30
|
end
|
|
22
31
|
|
|
23
32
|
def metadata_schema
|
|
24
|
-
@metadata_schema ||=
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Make a subclass of MetadataNode named GeneratedMetadataSchema and set its
|
|
28
|
-
# parent_class attribute to have the value of the current class.
|
|
29
|
-
def MetadataNode(parent_klass)
|
|
30
|
-
klass = const_set(:GeneratedMetadataSchema, Class.new(MetadataNode))
|
|
31
|
-
klass.parent_class = parent_klass
|
|
32
|
-
klass
|
|
33
|
+
@metadata_schema ||= metadata_class_factory.build(self)
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
end
|
data/solr/config/solrconfig.xml
CHANGED
|
@@ -122,7 +122,7 @@ describe ActiveFedora::File do
|
|
|
122
122
|
end
|
|
123
123
|
|
|
124
124
|
it "is not changed" do
|
|
125
|
-
expect(test_object.attached_files[path]).to_not
|
|
125
|
+
expect(test_object.attached_files[path]).to_not be_content_changed
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it "is able to read the content from fedora" do
|
|
@@ -56,4 +56,35 @@ describe ActiveFedora::Base do
|
|
|
56
56
|
end
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
|
+
|
|
60
|
+
describe "with an autosave association, where some records are deleted" do
|
|
61
|
+
before do
|
|
62
|
+
class GenericFile < ActiveFedora::Base
|
|
63
|
+
has_many :permissions, predicate: ::RDF::Vocab::ACL.accessTo
|
|
64
|
+
accepts_nested_attributes_for :permissions, allow_destroy: true
|
|
65
|
+
property :title, predicate: ::RDF::DC.title
|
|
66
|
+
|
|
67
|
+
def to_solr
|
|
68
|
+
super.tap do |doc|
|
|
69
|
+
doc['permissions_ssim'] = permission_ids
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class Permission < ActiveFedora::Base
|
|
75
|
+
belongs_to :generic_file, predicate: ::RDF::Vocab::ACL.accessTo
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
let(:p1) { Permission.create! }
|
|
80
|
+
let(:p2) { Permission.create! }
|
|
81
|
+
let(:gf) { GenericFile.create(permissions: [p1, p2]) }
|
|
82
|
+
|
|
83
|
+
before { gf.update(permissions_attributes: [{ id: p1.id, _destroy: 'true' }]) }
|
|
84
|
+
|
|
85
|
+
it "saves to solr correctly" do
|
|
86
|
+
result = ActiveFedora::SolrService.query("id:#{gf.id}").first['permissions_ssim']
|
|
87
|
+
expect(result).to eq [p2.id]
|
|
88
|
+
end
|
|
89
|
+
end
|
|
59
90
|
end
|
|
@@ -21,24 +21,24 @@ describe ActiveFedora::OmDatastream do
|
|
|
21
21
|
subject { obj.descMetadata }
|
|
22
22
|
|
|
23
23
|
describe "#changed?" do
|
|
24
|
-
it "
|
|
24
|
+
it "is not changed when no fields have been set" do
|
|
25
25
|
expect(subject).to_not be_content_changed
|
|
26
26
|
end
|
|
27
27
|
it "is changed when a field has been set" do
|
|
28
28
|
subject.title = 'Foobar'
|
|
29
29
|
expect(subject).to be_content_changed
|
|
30
30
|
end
|
|
31
|
-
it "
|
|
31
|
+
it "is not changed if the new xml matches the old xml" do
|
|
32
32
|
subject.content = subject.content
|
|
33
|
-
expect(subject).to_not
|
|
33
|
+
expect(subject).to_not be_content_changed
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "is changed if there are minor differences in whitespace" do
|
|
37
37
|
subject.content = "<a><b>1</b></a>"
|
|
38
38
|
obj.save
|
|
39
|
-
expect(subject).to_not
|
|
39
|
+
expect(subject).to_not be_content_changed
|
|
40
40
|
subject.content = "<a>\n<b>1</b>\n</a>"
|
|
41
|
-
expect(subject).to
|
|
41
|
+
expect(subject).to be_content_changed
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
@@ -56,11 +56,11 @@ describe ActiveFedora::OmDatastream do
|
|
|
56
56
|
obj.reload
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
it "
|
|
59
|
+
it "is not dirty after .update_values is saved" do
|
|
60
60
|
obj.descMetadata.update_values([{ name: 0 }, { role: 0 }, :text] => "Funder")
|
|
61
|
-
expect(obj.descMetadata).to
|
|
61
|
+
expect(obj.descMetadata).to be_content_changed
|
|
62
62
|
obj.save
|
|
63
|
-
expect(obj.descMetadata).to_not
|
|
63
|
+
expect(obj.descMetadata).to_not be_content_changed
|
|
64
64
|
expect(obj.descMetadata.term_values({ name: 0 }, { role: 0 }, :text)).to eq ["Funder"]
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
|
2
2
|
|
|
3
3
|
describe ActiveFedora::WithMetadata do
|
|
4
4
|
before do
|
|
5
|
+
class AdditionalSchema < ActiveTriples::Schema
|
|
6
|
+
property :new_property, predicate: ::RDF::URI("http://my.new.property/")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
ActiveFedora::WithMetadata::DefaultMetadataClassFactory.file_metadata_schemas << AdditionalSchema
|
|
10
|
+
|
|
5
11
|
class SampleFile < ActiveFedora::File
|
|
6
12
|
include ActiveFedora::WithMetadata
|
|
7
13
|
|
|
@@ -13,6 +19,8 @@ describe ActiveFedora::WithMetadata do
|
|
|
13
19
|
|
|
14
20
|
after do
|
|
15
21
|
Object.send(:remove_const, :SampleFile)
|
|
22
|
+
Object.send(:remove_const, :AdditionalSchema)
|
|
23
|
+
ActiveFedora::WithMetadata::DefaultMetadataClassFactory.file_metadata_schemas = [ActiveFedora::WithMetadata::DefaultSchema]
|
|
16
24
|
end
|
|
17
25
|
|
|
18
26
|
let(:file) { SampleFile.new }
|
|
@@ -28,6 +36,18 @@ describe ActiveFedora::WithMetadata do
|
|
|
28
36
|
it "tracks changes" do
|
|
29
37
|
expect(file.title_changed?).to be true
|
|
30
38
|
end
|
|
39
|
+
|
|
40
|
+
context "with defaults" do
|
|
41
|
+
subject { file }
|
|
42
|
+
it { is_expected.to respond_to(:label) }
|
|
43
|
+
it { is_expected.to respond_to(:file_name) }
|
|
44
|
+
it { is_expected.to respond_to(:file_size) }
|
|
45
|
+
it { is_expected.to respond_to(:date_created) }
|
|
46
|
+
it { is_expected.to respond_to(:mime_type) }
|
|
47
|
+
it { is_expected.to respond_to(:date_modified) }
|
|
48
|
+
it { is_expected.to respond_to(:byte_order) }
|
|
49
|
+
it { is_expected.to respond_to(:file_hash) }
|
|
50
|
+
end
|
|
31
51
|
end
|
|
32
52
|
|
|
33
53
|
describe "#save" do
|
|
@@ -83,4 +103,9 @@ describe ActiveFedora::WithMetadata do
|
|
|
83
103
|
expect(reloaded_file.metadata_node.query(predicate: ::RDF.type).map(&:object)).to include book
|
|
84
104
|
end
|
|
85
105
|
end
|
|
106
|
+
|
|
107
|
+
context "when using additional schema" do
|
|
108
|
+
subject { SampleFile.new }
|
|
109
|
+
it { is_expected.to respond_to(:new_property) }
|
|
110
|
+
end
|
|
86
111
|
end
|
data/spec/unit/file_spec.rb
CHANGED
|
@@ -7,6 +7,21 @@ describe ActiveFedora::File do
|
|
|
7
7
|
|
|
8
8
|
it { is_expected.not_to be_metadata }
|
|
9
9
|
|
|
10
|
+
describe "#save!" do
|
|
11
|
+
context "when updating metadata" do
|
|
12
|
+
before do
|
|
13
|
+
file.content = 'foo'
|
|
14
|
+
file.save!
|
|
15
|
+
file.mime_type = 'application/pdf'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it "Updates metadata" do
|
|
19
|
+
expect(file.metadata).to receive(:save)
|
|
20
|
+
file.save!
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
10
25
|
describe "#behaves_like_io?" do
|
|
11
26
|
subject { file.send(:behaves_like_io?, object) }
|
|
12
27
|
|
|
@@ -179,6 +194,25 @@ describe ActiveFedora::File do
|
|
|
179
194
|
end
|
|
180
195
|
end
|
|
181
196
|
|
|
197
|
+
describe "#mime_type" do
|
|
198
|
+
let(:parent) { ActiveFedora::Base.create }
|
|
199
|
+
before do
|
|
200
|
+
parent.add_file('banana', path: 'apple', mime_type: 'video/webm')
|
|
201
|
+
parent.save!
|
|
202
|
+
end
|
|
203
|
+
it "persists" do
|
|
204
|
+
expect(parent.reload.apple.mime_type).to eq "video/webm"
|
|
205
|
+
end
|
|
206
|
+
it "can be updated" do
|
|
207
|
+
parent.reload
|
|
208
|
+
parent.apple.mime_type = "text/awesome"
|
|
209
|
+
expect(parent.apple.mime_type).to eq "text/awesome"
|
|
210
|
+
parent.save
|
|
211
|
+
|
|
212
|
+
expect(parent.reload.apple.mime_type).to eq "text/awesome"
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
182
216
|
context "original_name" do
|
|
183
217
|
subject { file.original_name }
|
|
184
218
|
|
|
@@ -93,4 +93,24 @@ describe ActiveFedora::Associations::HasManyAssociation do
|
|
|
93
93
|
it { is_expected.to be_kind_of ActiveFedora::NullRelation }
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
|
+
|
|
97
|
+
describe "#ids_reader" do
|
|
98
|
+
let(:owner) { double('owner') }
|
|
99
|
+
let(:reflection) { double('reflection', check_validity!: true) }
|
|
100
|
+
let(:association) { described_class.new(owner, reflection) }
|
|
101
|
+
|
|
102
|
+
let(:r1) { ActiveFedora::Base.new(id: 'r1-id', &:mark_for_destruction) }
|
|
103
|
+
let(:r2) { ActiveFedora::Base.new(id: 'r2-id') }
|
|
104
|
+
|
|
105
|
+
context "when some records are marked_for_destruction" do
|
|
106
|
+
before do
|
|
107
|
+
allow(association).to receive(:loaded?).and_return(true)
|
|
108
|
+
allow(association).to receive(:load_target).and_return([r1, r2])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "only returns the records not marked for destruction" do
|
|
112
|
+
expect(association.ids_reader).to eq ['r2-id']
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
96
116
|
end
|
data/spec/unit/indexing_spec.rb
CHANGED
|
@@ -71,10 +71,6 @@ describe ActiveFedora::Indexing do
|
|
|
71
71
|
expect(solr_doc[:id]).to eql("changeme:123")
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
it "adds self.class as the :active_fedora_model" do
|
|
75
|
-
expect(subject[ActiveFedora.index_field_mapper.solr_name("active_fedora_model", :stored_sortable)]).to eql "SpecNode"
|
|
76
|
-
end
|
|
77
|
-
|
|
78
74
|
context "with attached files" do
|
|
79
75
|
let(:mock1) { double("ds1") }
|
|
80
76
|
let(:mock2) { double("ds2") }
|
data/spec/unit/query_spec.rb
CHANGED
|
@@ -95,11 +95,11 @@ describe ActiveFedora::Base do
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
it "queries for empty strings" do
|
|
98
|
-
expect(SpecModel::Basic.where(
|
|
98
|
+
expect(SpecModel::Basic.where(has_model_ssim: '').count).to eq 0
|
|
99
99
|
end
|
|
100
100
|
|
|
101
101
|
it 'queries for empty arrays' do
|
|
102
|
-
expect(SpecModel::Basic.where(
|
|
102
|
+
expect(SpecModel::Basic.where(has_model_ssim: []).count).to eq 0
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
it "adds options" do
|
|
@@ -119,7 +119,7 @@ describe ActiveFedora::Base do
|
|
|
119
119
|
describe '#find_each' do
|
|
120
120
|
before { allow(described_class).to receive(:relation).and_return(relation) }
|
|
121
121
|
let(:relation) { ActiveFedora::Relation.new(SpecModel::Basic) }
|
|
122
|
-
it "queries solr for all objects with :
|
|
122
|
+
it "queries solr for all objects with :has_model_ssim of self.class" do
|
|
123
123
|
mock_docs = [{ "id" => "changeme-30" }, { "id" => "changeme-22" }]
|
|
124
124
|
expect(mock_docs).to receive(:has_next?).and_return(false)
|
|
125
125
|
expect(ActiveFedora::SolrService.instance.conn).to receive(:paginate)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe ActiveFedora::WithMetadata::DefaultMetadataClassFactory do
|
|
4
|
+
let(:parent) { double("Parent") }
|
|
5
|
+
|
|
6
|
+
describe "default class attributes" do
|
|
7
|
+
its(:metadata_base_class) { is_expected.to eq(ActiveFedora::WithMetadata::MetadataNode) }
|
|
8
|
+
its(:file_metadata_schemas) { is_expected.to eq([ActiveFedora::WithMetadata::DefaultSchema]) }
|
|
9
|
+
its(:file_metadata_strategy) { is_expected.to eq(ActiveFedora::WithMetadata::DefaultStrategy) }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe "::build" do
|
|
13
|
+
it "sets MetadataNode to the default schema using the default strategy" do
|
|
14
|
+
expect(parent).to receive(:const_set)
|
|
15
|
+
expect(parent).to receive(:delegate).with(:label, :label=, :label_changed?, to: :metadata_node)
|
|
16
|
+
expect(parent).to receive(:delegate).with(:file_name, :file_name=, :file_name_changed?, to: :metadata_node)
|
|
17
|
+
expect(parent).to receive(:delegate).with(:file_size, :file_size=, :file_size_changed?, to: :metadata_node)
|
|
18
|
+
expect(parent).to receive(:delegate).with(:date_created, :date_created=, :date_created_changed?, to: :metadata_node)
|
|
19
|
+
expect(parent).to receive(:delegate).with(:date_modified,
|
|
20
|
+
:date_modified=,
|
|
21
|
+
:date_modified_changed?,
|
|
22
|
+
to: :metadata_node)
|
|
23
|
+
expect(parent).to receive(:delegate).with(:byte_order, :byte_order=, :byte_order_changed?, to: :metadata_node)
|
|
24
|
+
expect(parent).to receive(:delegate).with(:file_hash, :file_hash=, :file_hash_changed?, to: :metadata_node)
|
|
25
|
+
subject.class.build(parent)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active-fedora
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 10.0.0
|
|
4
|
+
version: 10.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Zumwalt
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2016-
|
|
13
|
+
date: 2016-06-08 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rsolr
|
|
@@ -553,7 +553,11 @@ files:
|
|
|
553
553
|
- lib/active_fedora/versionable.rb
|
|
554
554
|
- lib/active_fedora/versions_graph.rb
|
|
555
555
|
- lib/active_fedora/with_metadata.rb
|
|
556
|
+
- lib/active_fedora/with_metadata/default_metadata_class_factory.rb
|
|
557
|
+
- lib/active_fedora/with_metadata/default_schema.rb
|
|
558
|
+
- lib/active_fedora/with_metadata/default_strategy.rb
|
|
556
559
|
- lib/active_fedora/with_metadata/metadata_node.rb
|
|
560
|
+
- lib/active_fedora/with_metadata/sweet_jpl_terms.rb
|
|
557
561
|
- lib/generators/active_fedora/config/USAGE
|
|
558
562
|
- lib/generators/active_fedora/config/config_generator.rb
|
|
559
563
|
- lib/generators/active_fedora/config/fedora/fedora_generator.rb
|
|
@@ -751,6 +755,7 @@ files:
|
|
|
751
755
|
- spec/unit/solr_service_spec.rb
|
|
752
756
|
- spec/unit/sparql_insert_spec.rb
|
|
753
757
|
- spec/unit/validations_spec.rb
|
|
758
|
+
- spec/unit/with_metadata/default_metadata_class_factory_spec.rb
|
|
754
759
|
- spec/unit/with_metadata/metadata_node_spec.rb
|
|
755
760
|
homepage: https://github.com/projecthydra/active_fedora
|
|
756
761
|
licenses:
|
|
@@ -767,9 +772,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
767
772
|
version: '2.0'
|
|
768
773
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
769
774
|
requirements:
|
|
770
|
-
- - "
|
|
775
|
+
- - ">="
|
|
771
776
|
- !ruby/object:Gem::Version
|
|
772
|
-
version:
|
|
777
|
+
version: '0'
|
|
773
778
|
requirements: []
|
|
774
779
|
rubyforge_project:
|
|
775
780
|
rubygems_version: 2.5.1
|