active-fedora 9.2.1 → 9.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 912cef8852fb193d0e8c55b2996b060608b04426
4
- data.tar.gz: a9b6e0994fbd8edefb197a93ca5031a3bd439f9f
3
+ metadata.gz: 1a9499d1539f4cfe6d15bd6240a7636945f49251
4
+ data.tar.gz: 62c6f9a13eb35a9eaaf269680de4e6624b25fd5f
5
5
  SHA512:
6
- metadata.gz: 0a8e668c4d8ce320ada6b10a9104a61ced5901802f24f9aeca5fbd5381ddb30573ef270dbbc0e42c9c0b0f51bd70df8d108deb285e34e15ce229abe644d48edd
7
- data.tar.gz: 5a9bb242cf7d205c5f853457f4d458afdbfdf0862f041610ffc2705c9e2e32c04ca7c0fb32cf0730be078f3e4da22a3de37efe55137b0ba2673898822fe513b6
6
+ metadata.gz: 180ae74d2fd67d14b7d205b186cee646915b376257687fe7d9c85731ba5acd6bce8fe4a9990fb065200b2d954c9a10f3006960cec37ca27fbd41b12dc1761ee3
7
+ data.tar.gz: 99a9bfb6277533275cab73575d3a6c474bed490d6ec51973fcc99ef6e124e23445f85bae8d78f62ca6f316dbe2849026ef6d96d5723e707755ea7c1c4ac23313
@@ -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, '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'
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
@@ -2,7 +2,7 @@ module ActiveFedora::Associations::Builder
2
2
  class Property < Association
3
3
 
4
4
  self.macro = :rdf
5
- self.valid_options = [:class_name, :predicate]
5
+ self.valid_options = [:class_name, :predicate, :type_validator]
6
6
 
7
7
  def initialize(model, name, options)
8
8
  super
@@ -284,6 +284,10 @@ module ActiveFedora
284
284
  owner.new_record? && !foreign_key_present?
285
285
  end
286
286
 
287
+ def select(select=nil, &block)
288
+ to_a.select(&block)
289
+ end
290
+
287
291
  protected
288
292
 
289
293
  def construct_query
@@ -0,0 +1,8 @@
1
+ module ActiveFedora::Associations
2
+ ##
3
+ # An association type validator which does no validation.
4
+ class NullValidator
5
+ def self.validate!(reflection, object)
6
+ end
7
+ end
8
+ end
@@ -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
- values.each do |value|
9
- uri = ActiveFedora::Base.id_to_uri(value)
10
- owner.resource.insert [owner.rdf_subject, reflection.predicate, ::RDF::URI.new(uri)]
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
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.2.1"
2
+ VERSION = "9.3.0"
3
3
  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
- it "should choose a subset of objects in the relationship" do
85
- pending "method has private visibility"
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.2.1
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-23 00:00:00.000000000 Z
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