active-fedora 9.2.1 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +9 -0
- data/lib/active_fedora/associations.rb +5 -4
- data/lib/active_fedora/associations/association.rb +5 -0
- data/lib/active_fedora/associations/builder/association.rb +1 -1
- data/lib/active_fedora/associations/builder/property.rb +1 -1
- data/lib/active_fedora/associations/collection_association.rb +4 -0
- data/lib/active_fedora/associations/null_validator.rb +8 -0
- data/lib/active_fedora/associations/rdf.rb +4 -3
- data/lib/active_fedora/ldp_resource.rb +10 -0
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/associations/rdf_spec.rb +13 -0
- data/spec/integration/associations_spec.rb +46 -0
- data/spec/integration/collection_association_spec.rb +5 -3
- data/spec/integration/marshal_spec.rb +39 -0
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a9499d1539f4cfe6d15bd6240a7636945f49251
|
4
|
+
data.tar.gz: 62c6f9a13eb35a9eaaf269680de4e6624b25fd5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 180ae74d2fd67d14b7d205b186cee646915b376257687fe7d9c85731ba5acd6bce8fe4a9990fb065200b2d954c9a10f3006960cec37ca27fbd41b12dc1761ee3
|
7
|
+
data.tar.gz: 99a9bfb6277533275cab73575d3a6c474bed490d6ec51973fcc99ef6e124e23445f85bae8d78f62ca6f316dbe2849026ef6d96d5723e707755ea7c1c4ac23313
|
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
v9.3.0
|
2
|
+
2015-08-06: Records should be able to be marshaled and loaded [Justin Coyne]
|
3
|
+
|
4
|
+
2015-07-31: RDF association ids setter should handle nil [Justin Coyne]
|
5
|
+
|
6
|
+
2015-07-31: Add collection#select using block syntax [Trey Terrell]
|
7
|
+
|
8
|
+
2015-07-24: Add type validator objects to associations. [Trey Terrell]
|
9
|
+
|
1
10
|
v9.2.1
|
2
11
|
2015-07-20: Don't delete objects not part of the association. [Trey Terrell]
|
3
12
|
|
@@ -30,10 +30,11 @@ module ActiveFedora
|
|
30
30
|
autoload :DirectlyContainsOneAssociation, 'active_fedora/associations/directly_contains_one_association'
|
31
31
|
autoload :IndirectlyContainsAssociation, 'active_fedora/associations/indirectly_contains_association'
|
32
32
|
autoload :ContainsAssociation, 'active_fedora/associations/contains_association'
|
33
|
-
autoload :DeleteProxy,
|
34
|
-
autoload :ContainedFinder,
|
35
|
-
autoload :RecordComposite,
|
36
|
-
autoload :IDComposite,
|
33
|
+
autoload :DeleteProxy, 'active_fedora/associations/delete_proxy'
|
34
|
+
autoload :ContainedFinder, 'active_fedora/associations/contained_finder'
|
35
|
+
autoload :RecordComposite, 'active_fedora/associations/record_composite'
|
36
|
+
autoload :IDComposite, 'active_fedora/associations/id_composite'
|
37
|
+
autoload :NullValidator, 'active_fedora/associations/null_validator'
|
37
38
|
|
38
39
|
module Builder
|
39
40
|
autoload :Association, 'active_fedora/associations/builder/association'
|
@@ -149,6 +149,11 @@ module ActiveFedora
|
|
149
149
|
message = "#{@reflection.class_name}(##{@reflection.klass.object_id}) expected, got #{record.class}(##{record.class.object_id})"
|
150
150
|
raise ActiveFedora::AssociationTypeMismatch, message
|
151
151
|
end
|
152
|
+
type_validator.validate!(self, record)
|
153
|
+
end
|
154
|
+
|
155
|
+
def type_validator
|
156
|
+
options[:type_validator] || NullValidator
|
152
157
|
end
|
153
158
|
|
154
159
|
# Can be redefined by subclasses, notably polymorphic belongs_to
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActiveFedora::Associations::Builder
|
2
2
|
class Association #:nodoc:
|
3
3
|
class_attribute :valid_options
|
4
|
-
self.valid_options = [:class_name, :predicate]
|
4
|
+
self.valid_options = [:class_name, :predicate, :type_validator]
|
5
5
|
|
6
6
|
# Set by subclasses
|
7
7
|
class_attribute :macro
|
@@ -3,11 +3,12 @@ module ActiveFedora
|
|
3
3
|
class RDF < SingularAssociation #:nodoc:
|
4
4
|
|
5
5
|
def replace(values)
|
6
|
+
ids = Array(values).reject(&:blank?)
|
6
7
|
raise "can't modify frozen #{owner.class}" if owner.frozen?
|
7
8
|
destroy
|
8
|
-
|
9
|
-
uri = ActiveFedora::Base.id_to_uri(
|
10
|
-
owner.resource.insert [owner.rdf_subject, reflection.predicate,
|
9
|
+
ids.each do |id|
|
10
|
+
uri = ::RDF::URI(ActiveFedora::Base.id_to_uri(id))
|
11
|
+
owner.resource.insert [owner.rdf_subject, reflection.predicate, uri]
|
11
12
|
end
|
12
13
|
owner.send(:attribute_will_change!, reflection.name)
|
13
14
|
end
|
@@ -22,5 +22,15 @@ module ActiveFedora
|
|
22
22
|
# forces a cast to FedoraRdfResource
|
23
23
|
graph_without_inlined_resources(original_graph, inlined_resources)
|
24
24
|
end
|
25
|
+
|
26
|
+
# Don't dump @client, it has a proc and thus can't be serialized.
|
27
|
+
def marshal_dump
|
28
|
+
ivars = (instance_variables - [:@client]).map { |name| [name, instance_variable_get(name)] }
|
29
|
+
end
|
30
|
+
|
31
|
+
def marshal_load(data)
|
32
|
+
ivars = data
|
33
|
+
ivars.each { |name, val| instance_variable_set(name, val) }
|
34
|
+
end
|
25
35
|
end
|
26
36
|
end
|
@@ -20,6 +20,19 @@ describe "rdf associations" do
|
|
20
20
|
expect(library.association(:foo_ids)).not_to receive(:filter_by_class)
|
21
21
|
library.foos.to_a
|
22
22
|
end
|
23
|
+
|
24
|
+
describe "the id setter" do
|
25
|
+
it "can handle nil" do
|
26
|
+
library.foo_ids = nil
|
27
|
+
expect(library.foo_ids).to eq []
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can handle array with nils" do
|
31
|
+
library.foo_ids = [nil, nil]
|
32
|
+
expect(library.foo_ids).to eq []
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
23
36
|
end
|
24
37
|
|
25
38
|
context "when two relationships have the same predicate" do
|
@@ -56,6 +56,52 @@ describe ActiveFedora::Base do
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
describe "type validator" do
|
60
|
+
before do
|
61
|
+
class EnsureBanana
|
62
|
+
def self.validate!(reflection, object)
|
63
|
+
unless object.try(:banana?)
|
64
|
+
raise ActiveFedora::AssociationTypeMismatch.new "#{object} must be a banana"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
class FooThing < ActiveFedora::Base
|
69
|
+
attr_accessor :banana
|
70
|
+
has_many :bars, class_name: 'BarThing', predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, as: :foothing, type_validator: EnsureBanana
|
71
|
+
def banana?
|
72
|
+
!!banana
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class BarThing < ActiveFedora::Base
|
77
|
+
attr_accessor :banana
|
78
|
+
belongs_to :foothing, class_name: 'FooThing', predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, type_validator: EnsureBanana
|
79
|
+
def banana?
|
80
|
+
!!banana
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
after do
|
86
|
+
Object.send(:remove_const, :FooThing)
|
87
|
+
Object.send(:remove_const, :BarThing)
|
88
|
+
end
|
89
|
+
|
90
|
+
let(:foo) { FooThing.create }
|
91
|
+
let(:bar) { BarThing.create }
|
92
|
+
|
93
|
+
it "should validate on singular associations" do
|
94
|
+
expect{bar.foothing = foo}.to raise_error ActiveFedora::AssociationTypeMismatch, "#{foo} must be a banana"
|
95
|
+
foo.banana = true
|
96
|
+
expect{bar.foothing = foo}.not_to raise_error
|
97
|
+
end
|
98
|
+
it "should validate on collection associations" do
|
99
|
+
expect{foo.bars << bar}.to raise_error ActiveFedora::AssociationTypeMismatch, "#{bar} must be a banana"
|
100
|
+
bar.banana = true
|
101
|
+
expect{foo.bars << bar}.not_to raise_error
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
59
105
|
describe "complex example" do
|
60
106
|
before do
|
61
107
|
class Library < ActiveFedora::Base
|
@@ -79,12 +79,14 @@ describe ActiveFedora::Base do
|
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
-
# TODO: Bug described in issue #609
|
83
82
|
describe "#select" do
|
84
|
-
|
85
|
-
|
83
|
+
# TODO: Bug described in issue #609
|
84
|
+
xit "should choose a subset of objects in the relationship" do
|
86
85
|
expect(library.books.select([:id])).to include(book1.id)
|
87
86
|
end
|
87
|
+
it "should work as a block" do
|
88
|
+
expect(library.books.select{|x| x.id == book1.id}).to eq [book1]
|
89
|
+
end
|
88
90
|
end
|
89
91
|
|
90
92
|
describe "finding the inverse" do
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Marshalling and loading" do
|
4
|
+
before do
|
5
|
+
class Post < ActiveFedora::Base
|
6
|
+
has_many :comments
|
7
|
+
property :text, predicate: ::RDF::URI('http://example.com/text')
|
8
|
+
end
|
9
|
+
|
10
|
+
class Comment < ActiveFedora::Base
|
11
|
+
belongs_to :post, predicate: ::RDF::URI('http://example.com/post')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
Object.send(:remove_const, :Post)
|
17
|
+
Object.send(:remove_const, :Comment)
|
18
|
+
end
|
19
|
+
|
20
|
+
context "persisted records" do
|
21
|
+
let(:post) { Post.create(text: ['serialize me']) }
|
22
|
+
it "marshals them" do
|
23
|
+
marshalled = Marshal.dump(post)
|
24
|
+
loaded = Marshal.load(marshalled)
|
25
|
+
|
26
|
+
expect(loaded.attributes).to eq post.attributes
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with associations" do
|
31
|
+
let(:post) { Post.create(comments: [Comment.new]) }
|
32
|
+
it "marshals associations" do
|
33
|
+
marshalled = Marshal.dump(post)
|
34
|
+
loaded = Marshal.load(marshalled)
|
35
|
+
|
36
|
+
expect(loaded.comments.size).to eq 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Associations::Builder::HasAndBelongsToMany do
|
4
4
|
describe "valid_options" do
|
5
5
|
subject { ActiveFedora::Associations::Builder::HasAndBelongsToMany.valid_options }
|
6
|
-
it { should eq [:class_name, :predicate, :before_add, :after_add, :before_remove,
|
6
|
+
it { should eq [:class_name, :predicate, :type_validator, :before_add, :after_add, :before_remove,
|
7
7
|
:after_remove, :inverse_of, :solr_page_size, :autosave] }
|
8
8
|
end
|
9
9
|
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: 9.
|
4
|
+
version: 9.3.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: 2015-07
|
13
|
+
date: 2015-08-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rsolr
|
@@ -314,6 +314,7 @@ files:
|
|
314
314
|
- lib/active_fedora/associations/has_many_association.rb
|
315
315
|
- lib/active_fedora/associations/id_composite.rb
|
316
316
|
- lib/active_fedora/associations/indirectly_contains_association.rb
|
317
|
+
- lib/active_fedora/associations/null_validator.rb
|
317
318
|
- lib/active_fedora/associations/rdf.rb
|
318
319
|
- lib/active_fedora/associations/record_composite.rb
|
319
320
|
- lib/active_fedora/associations/singular_association.rb
|
@@ -496,6 +497,7 @@ files:
|
|
496
497
|
- spec/integration/indexing_spec.rb
|
497
498
|
- spec/integration/indirect_container_spec.rb
|
498
499
|
- spec/integration/json_serialization_spec.rb
|
500
|
+
- spec/integration/marshal_spec.rb
|
499
501
|
- spec/integration/model_spec.rb
|
500
502
|
- spec/integration/nested_attribute_spec.rb
|
501
503
|
- spec/integration/ntriples_datastream_spec.rb
|