active-fedora 10.0.0.beta2 → 10.0.0.beta3
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.rb +15 -19
- data/lib/active_fedora/file/attributes.rb +5 -5
- data/lib/active_fedora/railtie.rb +4 -1
- data/lib/active_fedora/rake_support.rb +9 -4
- data/lib/active_fedora/version.rb +1 -1
- data/lib/active_fedora/with_metadata/default_schema.rb +0 -1
- data/lib/active_fedora/with_metadata/metadata_node.rb +12 -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 +1 -1
- data/spec/unit/file_spec.rb +19 -0
- data/spec/unit/has_many_association_spec.rb +20 -0
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +10 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02a7ebf7a35811e4066a8fe6c45d1ac3c295c35b
|
4
|
+
data.tar.gz: ff66c823b1eada725f5d49a91bcb024c394a19e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa74e8f37edda9ac76f75f7171314ec8fa3d5ecbe3777acc9634ede021ae598475bbc9632b82da45a661584cd651b1ca31b9c8641134e45bbbed1af4de760550
|
7
|
+
data.tar.gz: 531c7c807e725d6186d37954185b3045d5790c392d39ef23ee7489642cbfa1bde0c5786b1bb66688f845780f8dd1904f62fc96c4db2d54ccc5f8a9000d1ec556
|
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)
|
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
|
@@ -50,6 +48,12 @@ module ActiveFedora
|
|
50
48
|
end
|
51
49
|
end
|
52
50
|
|
51
|
+
def save
|
52
|
+
super.tap do
|
53
|
+
metadata.save if metadata.changed?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
53
57
|
def described_by
|
54
58
|
raise "#{self} isn't persisted yet" if new_record?
|
55
59
|
links['describedby'].first
|
@@ -99,11 +103,8 @@ module ActiveFedora
|
|
99
103
|
end
|
100
104
|
|
101
105
|
def attribute_will_change!(attr)
|
102
|
-
|
103
|
-
|
104
|
-
else
|
105
|
-
super
|
106
|
-
end
|
106
|
+
return super unless attr == 'content'
|
107
|
+
changed_attributes['content'] = true
|
107
108
|
end
|
108
109
|
|
109
110
|
def remote_content
|
@@ -124,8 +125,13 @@ module ActiveFedora
|
|
124
125
|
local_or_remote_content(false) != @ds_content
|
125
126
|
end
|
126
127
|
|
128
|
+
def metadata_changed?
|
129
|
+
return false if new_record? || links['describedby'].blank?
|
130
|
+
metadata.changed?
|
131
|
+
end
|
132
|
+
|
127
133
|
def changed?
|
128
|
-
super || content_changed?
|
134
|
+
super || content_changed? || metadata_changed?
|
129
135
|
end
|
130
136
|
|
131
137
|
def inspect
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -9,7 +9,12 @@ def with_server(environment)
|
|
9
9
|
|
10
10
|
ENV["#{environment}_SERVER_STARTED"] = 'true'
|
11
11
|
|
12
|
-
|
12
|
+
# setting port: nil assigns a random port.
|
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|
|
13
18
|
ENV["SOLR_#{environment.upcase}_PORT"] = solr.port.to_s
|
14
19
|
solr_config_path = File.join('solr', 'config')
|
15
20
|
# Check to see if configs exist in a path relative to the working directory
|
@@ -19,7 +24,7 @@ def with_server(environment)
|
|
19
24
|
solr_config_path = File.join(File.expand_path("../..", File.dirname(__FILE__)), "solr", "config")
|
20
25
|
end
|
21
26
|
solr.with_collection(name: "hydra-#{environment}", dir: solr_config_path) do
|
22
|
-
FcrepoWrapper.wrap(load_config(:fcrepo, environment)) do |fcrepo|
|
27
|
+
FcrepoWrapper.wrap(load_config(:fcrepo, environment, fcrepo_defaults)) do |fcrepo|
|
23
28
|
ENV["FCREPO_#{environment.upcase}_PORT"] = fcrepo.port.to_s
|
24
29
|
yield
|
25
30
|
end
|
@@ -30,8 +35,8 @@ end
|
|
30
35
|
|
31
36
|
private
|
32
37
|
|
33
|
-
def load_config(service, environment)
|
38
|
+
def load_config(service, environment, defaults)
|
34
39
|
config_file = environment == 'test' ? "config/#{service}_wrapper_test.yml" : ".#{service}_wrapper"
|
35
40
|
return { config: config_file } if File.exist?(config_file)
|
36
|
-
|
41
|
+
defaults
|
37
42
|
end
|
@@ -7,7 +7,6 @@ module ActiveFedora::WithMetadata
|
|
7
7
|
property :file_name, predicate: ::RDF::Vocab::EBUCore.filename
|
8
8
|
property :file_size, predicate: ::RDF::Vocab::EBUCore.fileSize
|
9
9
|
property :date_created, predicate: ::RDF::Vocab::EBUCore.dateCreated
|
10
|
-
property :has_mime_type, predicate: ::RDF::Vocab::EBUCore.hasMimeType
|
11
10
|
property :date_modified, predicate: ::RDF::Vocab::EBUCore.dateModified
|
12
11
|
property :byte_order, predicate: SweetJPLTerms.byteOrder
|
13
12
|
# This is a server-managed predicate which means Fedora does not let us change it.
|
@@ -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
|
@@ -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
|
@@ -43,7 +43,7 @@ describe ActiveFedora::WithMetadata do
|
|
43
43
|
it { is_expected.to respond_to(:file_name) }
|
44
44
|
it { is_expected.to respond_to(:file_size) }
|
45
45
|
it { is_expected.to respond_to(:date_created) }
|
46
|
-
it { is_expected.to respond_to(:
|
46
|
+
it { is_expected.to respond_to(:mime_type) }
|
47
47
|
it { is_expected.to respond_to(:date_modified) }
|
48
48
|
it { is_expected.to respond_to(:byte_order) }
|
49
49
|
it { is_expected.to respond_to(:file_hash) }
|
data/spec/unit/file_spec.rb
CHANGED
@@ -179,6 +179,25 @@ describe ActiveFedora::File do
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
+
describe "#mime_type" do
|
183
|
+
let(:parent) { ActiveFedora::Base.create }
|
184
|
+
before do
|
185
|
+
parent.add_file('banana', path: 'apple', mime_type: 'video/webm')
|
186
|
+
parent.save!
|
187
|
+
end
|
188
|
+
it "persists" do
|
189
|
+
expect(parent.reload.apple.mime_type).to eq "video/webm"
|
190
|
+
end
|
191
|
+
it "can be updated" do
|
192
|
+
parent.reload
|
193
|
+
parent.apple.mime_type = "text/awesome"
|
194
|
+
expect(parent.apple.mime_type).to eq "text/awesome"
|
195
|
+
parent.save
|
196
|
+
|
197
|
+
expect(parent.reload.apple.mime_type).to eq "text/awesome"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
182
201
|
context "original_name" do
|
183
202
|
subject { file.original_name }
|
184
203
|
|
@@ -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
|
@@ -12,7 +12,16 @@ describe ActiveFedora::WithMetadata::DefaultMetadataClassFactory do
|
|
12
12
|
describe "::build" do
|
13
13
|
it "sets MetadataNode to the default schema using the default strategy" do
|
14
14
|
expect(parent).to receive(:const_set)
|
15
|
-
expect(parent).to receive(:delegate).
|
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)
|
16
25
|
subject.class.build(parent)
|
17
26
|
end
|
18
27
|
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.beta3
|
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-05-
|
13
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|