active-fedora 9.0.0.beta7 → 9.0.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0efb77ba5a2ca5e2a3a904bf1f6181eb8ec1b7b6
4
- data.tar.gz: f3996a300d97a4237839bb8875754a5c8eb8a54d
3
+ metadata.gz: c24dde2e32be3f35bb1d77501279572cb2695ca4
4
+ data.tar.gz: 87e6796cd6ae6aac4bf464e11b2a2739f3a803fa
5
5
  SHA512:
6
- metadata.gz: cb3b8dc10a355f976a397a67ae4d638a4de029bab93dbe63993e317890e1a3b0c9e75e7403c29b2accb349a1ee1e14984321aa4877aed56bb0a91dd2d8152922
7
- data.tar.gz: 8305e854f8477f0796b094cbf7e048874971687801d7d19450c05b22a82b9f8e016c316f0c4b13c24144b3956026898a3ee6a2d8d5aed7450802ef0e76e9b60e
6
+ metadata.gz: 43b3dbe69386c97045ea8652f286c872bd3874d9c95b11b28f99203e357a7445f0287d27daefcb5c74fca1a6fab6d8f9af33389300033ff5f45218e582af8fda
7
+ data.tar.gz: b6f025e13de2def11b8361663ae55510989a25e38e8fe3cf9ccc7e99ed89a87f4fef380fead464a6a13ed0ad8146a2c5b55ffab1b490aeabd223425d696371d3
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ cache: bundler
3
+ sudo: false
2
4
  rvm:
3
5
  - 2.1
4
6
 
@@ -69,8 +69,9 @@ module ActiveFedora #:nodoc:
69
69
  autoload :NomDatastream
70
70
  autoload :NullRelation
71
71
  autoload :OmDatastream
72
- autoload :Property
73
72
  autoload :Persistence
73
+ autoload :ProfileIndexingService
74
+ autoload :Property
74
75
  autoload :QualifiedDublinCoreDatastream
75
76
  autoload :Querying
76
77
  autoload :QueryResultBuilder
@@ -1,7 +1,9 @@
1
+ require 'active_model/forbidden_attributes_protection'
1
2
  module ActiveFedora
2
3
  module Attributes
3
4
  extend ActiveSupport::Concern
4
5
  include ActiveModel::Dirty
6
+ include ActiveModel::ForbiddenAttributesProtection
5
7
 
6
8
  included do
7
9
  include Serializers
@@ -15,7 +17,7 @@ module ActiveFedora
15
17
  end
16
18
 
17
19
  def attributes=(properties)
18
- properties.each do |k, v|
20
+ sanitize_for_mass_assignment(properties).each do |k, v|
19
21
  respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(UnknownAttributeError, "#{self.class} does not have an attribute `#{k}'")
20
22
  end
21
23
  end
@@ -27,7 +27,9 @@ module ActiveFedora::Attributes
27
27
  def self.define_singular_readers(mixin, name)
28
28
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
29
29
  def #{name}(*args)
30
- get_values(:#{name}).first
30
+ vals = get_values(:#{name})
31
+ raise ActiveFedora::ConstraintError, "Expected \\"#{name}\\" to have 0-1 statements, but there are \#{vals.size}" if vals.size > 1
32
+ vals.first
31
33
  end
32
34
  CODE
33
35
  end
@@ -54,6 +54,20 @@ module ActiveFedora #:nodoc:
54
54
  class IllegalOperation < ActiveFedoraError
55
55
  end
56
56
 
57
+ # Raised when the data has more than one statement for a predicate, but our constraints say it's singular
58
+ # This helps to prevent overwriting multiple values with a single value when round tripping:
59
+ # class Book < ActiveFedora::Base
60
+ # property :title, predicate: RDF::DC.title, multiple: false
61
+ # end
62
+ #
63
+ # b = Book.new
64
+ # b.resource.title = ['foo', 'bar']
65
+ # b.title # Raises ConstraintError
66
+ # # which prevents us from doing:
67
+ # b.title = b.title
68
+ class ConstraintError < ActiveFedoraError
69
+ end
70
+
57
71
  # Used to rollback a transaction in a deliberate way without raising an exception.
58
72
  # Transactions are currently incomplete
59
73
  class Rollback < ActiveFedoraError
@@ -20,6 +20,10 @@ module ActiveFedora
20
20
  @profile_solr_name ||= ActiveFedora::SolrQueryBuilder.solr_name("object_profile", :displayable)
21
21
  end
22
22
 
23
+ def profile_service
24
+ ProfileIndexingService
25
+ end
26
+
23
27
 
24
28
  def generate_solr_document
25
29
  solr_doc = {}
@@ -28,7 +32,7 @@ module ActiveFedora
28
32
  Solrizer.set_field(solr_doc, 'active_fedora_model', object.class.inspect, :stored_sortable)
29
33
  solr_doc.merge!(QueryResultBuilder::HAS_MODEL_SOLR_FIELD => object.has_model)
30
34
  solr_doc.merge!(SOLR_DOCUMENT_ID.to_sym => object.id)
31
- solr_doc.merge!(self.class.profile_solr_name => object.to_json)
35
+ solr_doc.merge!(self.class.profile_solr_name => profile_service.new(object).export)
32
36
  object.attached_files.each do |name, file|
33
37
  solr_doc.merge! file.to_solr(solr_doc, name: name.to_s)
34
38
  end
@@ -103,7 +103,7 @@ module ActiveFedora
103
103
  attached_files[key] = SolrBackedMetadataFile.new
104
104
  end
105
105
  @resource = SolrBackedResource.new(self.class)
106
- self.attributes = attrs.except(datastream_keys)
106
+ self.attributes = attrs.slice(*self.class.attribute_names)
107
107
  # TODO Should we clear the change tracking, or make this object Read-only?
108
108
 
109
109
  run_callbacks :find
@@ -0,0 +1,11 @@
1
+ module ActiveFedora
2
+ class ProfileIndexingService
3
+ def initialize(object)
4
+ @object = object
5
+ end
6
+
7
+ def export
8
+ @object.serializable_hash.to_json
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.0.0.beta7"
2
+ VERSION = "9.0.0.beta8"
3
3
  end
@@ -22,8 +22,12 @@ module ActiveFedora
22
22
 
23
23
  # Returns an array of ActiveFedora::VersionsGraph::ResourceVersion objects.
24
24
  # Excludes auto-snapshot versions from Fedora.
25
- def versions
26
- @versions ||= ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
25
+ def versions(reload=false)
26
+ if reload
27
+ @versions = ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
28
+ else
29
+ @versions ||= ActiveFedora::VersionsGraph.new << ::RDF::Reader.for(:ttl).new(versions_request)
30
+ end
27
31
  end
28
32
 
29
33
  def create_version
@@ -50,7 +50,8 @@ module ActiveFedora
50
50
  end
51
51
 
52
52
  def fedora_versions
53
- resources.map { |statement| version_from_resource(statement) }
53
+ list = resources.map { |statement| version_from_resource(statement) }
54
+ list.sort_by(&:created)
54
55
  end
55
56
 
56
57
  end
@@ -83,4 +83,13 @@ describe ActiveFedora::SolrInstanceLoader do
83
83
  expect(subject.title).to eq 'My Title'
84
84
  end
85
85
  end
86
+
87
+ context "when the model has extra values in its json" do
88
+ let(:profile) { { "foo"=>["baz"], "bar"=>"quix", "title"=>"My Title", "extra_value"=>"Bonus values!"}.to_json }
89
+ let(:doc) { { 'id' => 'test-123', 'has_model_ssim'=>['Foo'], 'object_profile_ssm' => profile } }
90
+ let(:loader) { ActiveFedora::SolrInstanceLoader.new(Foo, obj.id, doc) }
91
+ it "should load the object without trouble" do
92
+ expect(loader.object).to be_instance_of Foo
93
+ end
94
+ end
86
95
  end
@@ -8,6 +8,7 @@ if ENV["COVERAGE"]
8
8
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
9
9
  SimpleCov.start do
10
10
  add_filter "/spec/"
11
+ add_filter "/gemfiles/"
11
12
  end
12
13
  end
13
14
 
@@ -418,6 +418,17 @@ describe ActiveFedora::Base do
418
418
  expect(subject[:abstract]).to be_nil
419
419
  end
420
420
 
421
+ context "when there are two assertions for the predicate" do
422
+ before do
423
+ subject.resource[:abstract] = ['foo', 'bar']
424
+ end
425
+ it "should raise an error if just returning the first value would cause data loss" do
426
+ expect { subject[:abstract] }.to raise_error ActiveFedora::ConstraintError, "Expected \"abstract\" to have 0-1 statements, but there are 2"
427
+ end
428
+ end
429
+ end
430
+
431
+ context "multiple values" do
421
432
  it "should return values" do
422
433
  expect(subject[:title]).to eq ['test1']
423
434
  end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Mass assignment protection" do
4
+ before(:all) do
5
+ class ProtectedParams < ActiveSupport::HashWithIndifferentAccess
6
+ attr_accessor :permitted
7
+ alias :permitted? :permitted
8
+
9
+ def initialize(attributes)
10
+ super(attributes)
11
+ @permitted = false
12
+ end
13
+
14
+ def permit!
15
+ @permitted = true
16
+ self
17
+ end
18
+
19
+ def dup
20
+ super.tap do |duplicate|
21
+ duplicate.instance_variable_set :@permitted, @permitted
22
+ end
23
+ end
24
+ end
25
+
26
+ class Person < ActiveFedora::Base
27
+ property :first_name, predicate: ::RDF::FOAF.firstName, multiple: false
28
+ property :gender, predicate: ::RDF::FOAF.gender, multiple: false
29
+ end
30
+ end
31
+
32
+ after(:all) do
33
+ Object.send(:remove_const, :ProtectedParams)
34
+ Object.send(:remove_const, :Person)
35
+ end
36
+
37
+
38
+ context "forbidden attributes" do
39
+ let(:params) { ProtectedParams.new(first_name: 'Guille', gender: 'm') }
40
+ it "cannot be used for mass assignment" do
41
+ expect { Person.new(params) }.to raise_error ActiveModel::ForbiddenAttributesError
42
+ end
43
+ end
44
+
45
+ context "permitted attributes" do
46
+ let(:params) { ProtectedParams.new(first_name: 'Guille', gender: 'm').permit! }
47
+ it "cannot be used for mass assignment" do
48
+ expect { Person.new(params) }.not_to raise_error
49
+ end
50
+ end
51
+
52
+ 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.0.0.beta7
4
+ version: 9.0.0.beta8
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: 2014-12-11 00:00:00.000000000 Z
13
+ date: 2014-12-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -347,6 +347,7 @@ files:
347
347
  - lib/active_fedora/om_datastream.rb
348
348
  - lib/active_fedora/persistence.rb
349
349
  - lib/active_fedora/predicates.rb
350
+ - lib/active_fedora/profile_indexing_service.rb
350
351
  - lib/active_fedora/property.rb
351
352
  - lib/active_fedora/qualified_dublin_core_datastream.rb
352
353
  - lib/active_fedora/query_result_builder.rb
@@ -496,6 +497,7 @@ files:
496
497
  - spec/unit/file_spec.rb
497
498
  - spec/unit/files_hash_spec.rb
498
499
  - spec/unit/fixity_service_spec.rb
500
+ - spec/unit/forbidden_attributes_protection_spec.rb
499
501
  - spec/unit/has_and_belongs_to_many_association_spec.rb
500
502
  - spec/unit/has_many_association_spec.rb
501
503
  - spec/unit/indexing_service_spec.rb