active-fedora 9.1.1 → 9.1.2

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: 1d27733036fa2ceffef04a07c51f6287e1a29345
4
- data.tar.gz: 45c6e01a1d0508a3a316771973183cc48a7f08eb
3
+ metadata.gz: da18bdd03d130d9d80945cd2c2ce0cbbe6056831
4
+ data.tar.gz: 7709031721c4ccb85bf411d49d61731b097de430
5
5
  SHA512:
6
- metadata.gz: 921a3c46c4485ec83789512be1fe9caf1d16445f18121d68944a3a3f742b64a1010a7db5bbcf05b77e1d8c094d36ef2e7ea8f506ee8a0f5c046fe16a0788c5f0
7
- data.tar.gz: c491773b0438275c4d75e998e54eae06940a4a6137b92630fee5530eafa16e77dc1e56ca003114ccabe9604bf686f443492b40e4ff0581bb856dfc5c39d8aef3
6
+ metadata.gz: 3e685a07394f367818b44898dba0c8d059dfec46702534f915840cae1dabda372f50ebe60eb68962295186e588b76dced9624861b545e3611bb83fa89e60737c
7
+ data.tar.gz: 048eb130c747e5e96be4593b25c4ab51ccf7fee443df5aa8c67c91108f839f50b01dc8455c86a07cef1417a238e54385d4d2f092138abb17e1797a7a292b359c
@@ -1,3 +1,20 @@
1
+ v9.1.2
2
+ 2015-06-11: Remove unnecessary dependency on rdf-vocab [Justin Coyne]
3
+
4
+ 2015-05-05: Track type as a changed attribute in MetadataNode [Justin Coyne]
5
+
6
+ 2015-05-05: Don't try to save the metadata node if the file is unsaved [Justin
7
+ Coyne]
8
+
9
+ 2015-05-05: File#save should return true if there is nothing to save Fixes #784
10
+ This parallels how ActiveRecord objects behave if there are no changes, e.g.:
11
+ [Justin Coyne]
12
+
13
+ 2015-05-04: CollectionAssociation should generate a solr query lazily When a
14
+ CollectionAssociation is loaded before the owing object is saved the solr query
15
+ is produced without the id of the owner, so all the objects of the correct type
16
+ are returned. Ref #781 [Justin Coyne]
17
+
1
18
  v9.1.0
2
19
  2015-04-16: Use delegate_to instead of datastream in the options for property
3
20
  Trying to reduce/elimnate the useage of "datastream" especially in the public
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency "linkeddata"
24
24
  s.add_dependency "deprecation"
25
25
  s.add_dependency "ldp", '~> 0.3.0'
26
- s.add_dependency "rdf-ldp"
27
26
 
28
27
  s.add_development_dependency "rdoc"
29
28
  s.add_development_dependency "yard"
@@ -8,7 +8,6 @@ require 'active_support/core_ext/object'
8
8
  require 'active_support/core_ext/hash/indifferent_access'
9
9
  require 'active_support/core_ext/hash/except'
10
10
  require 'active_triples'
11
- require 'rdf/ldp'
12
11
 
13
12
  SOLR_DOCUMENT_ID = Solrizer.default_field_mapper.id_field unless defined?(SOLR_DOCUMENT_ID)
14
13
  ENABLE_SOLR_UPDATES = true unless defined?(ENABLE_SOLR_UPDATES)
@@ -3,11 +3,6 @@ module ActiveFedora
3
3
  class CollectionAssociation < Association #:nodoc:
4
4
  attr_reader :proxy
5
5
 
6
- def initialize(owner, reflection)
7
- super
8
- construct_query
9
- end
10
-
11
6
  # Implements the reader method, e.g. foo.items for Foo.has_many :items
12
7
  # @param opts [Boolean, Hash] if true, force a reload
13
8
  # @option opts [Symbol] :response_format can be ':solr' to return a solr result.
@@ -233,7 +228,7 @@ module ActiveFedora
233
228
  # Count all records using solr. Construct options and pass them with
234
229
  # scope to the target class's +count+.
235
230
  def count(options = {})
236
- @reflection.klass.count(:conditions => @counter_query)
231
+ @reflection.klass.count(conditions: construct_query)
237
232
  end
238
233
 
239
234
  # Sets the target of this proxy to <tt>\target</tt>, and the \loaded flag to +true+.
@@ -291,10 +286,11 @@ module ActiveFedora
291
286
 
292
287
  # @param opts [Hash] Options that will be passed through to ActiveFedora::SolrService.query.
293
288
  def load_from_solr(opts = Hash.new)
294
- return [] if @finder_query.empty?
289
+ finder_query = construct_query
290
+ return [] if finder_query.empty?
295
291
  rows = opts.delete(:rows) { count }
296
292
  return [] if rows == 0
297
- SolrService.query(@finder_query, {rows: rows}.merge(opts))
293
+ SolrService.query(finder_query, { rows: rows }.merge(opts))
298
294
  end
299
295
 
300
296
  def add_to_target(record, skip_callbacks = false)
@@ -330,11 +326,12 @@ module ActiveFedora
330
326
  end
331
327
 
332
328
  def construct_query
333
-
334
- #TODO use primary_key instead of id
335
- clauses = { find_reflection => @owner.id }
336
- clauses[:has_model] = @reflection.class_name.constantize.to_class_uri if @reflection.class_name && @reflection.class_name != 'ActiveFedora::Base'
337
- @counter_query = @finder_query = ActiveFedora::SolrQueryBuilder.construct_query_for_rel(clauses)
329
+ @solr_query ||= begin
330
+ #TODO use primary_key instead of id
331
+ clauses = { find_reflection => @owner.id }
332
+ clauses[:has_model] = @reflection.class_name.constantize.to_class_uri if @reflection.class_name && @reflection.class_name != 'ActiveFedora::Base'
333
+ ActiveFedora::SolrQueryBuilder.construct_query_for_rel(clauses)
334
+ end
338
335
  end
339
336
 
340
337
 
@@ -17,7 +17,7 @@ module ActiveFedora
17
17
  count = if loaded?
18
18
  @target.size
19
19
  else
20
- @reflection.klass.count(:conditions => @counter_query)
20
+ @reflection.klass.count(conditions: construct_query)
21
21
  end
22
22
 
23
23
  # If there's nothing in the database and @target has no new records
@@ -17,6 +17,7 @@ module ActiveFedora
17
17
  changes.empty?
18
18
  end
19
19
 
20
+ # @return [Hash<RDF::URI, RDF::Queryable::Enumerator>] hash of predicate uris to statements
20
21
  def changes
21
22
  @changes ||= changed_attributes.each_with_object({}) do |key, result|
22
23
  if object.respond_to?(:association) && object.association(key.to_sym).present?
@@ -25,6 +26,10 @@ module ActiveFedora
25
26
  elsif object.class.properties.keys.include?(key)
26
27
  predicate = graph.reflections.reflect_on_property(key).predicate
27
28
  result[predicate] = graph.query(predicate: predicate)
29
+ elsif key == 'type'.freeze
30
+ # working around https://github.com/ActiveTriples/ActiveTriples/issues/122
31
+ predicate = ::RDF.type
32
+ result[predicate] = graph.query(predicate: predicate)
28
33
  elsif object.local_attributes.include?(key)
29
34
  raise "Unable to find a graph predicate corresponding to the attribute: \"#{key}\""
30
35
  end
@@ -235,7 +235,7 @@ module ActiveFedora
235
235
  end
236
236
 
237
237
  def save(*)
238
- return unless content_changed?
238
+ return true unless content_changed?
239
239
  headers = { 'Content-Type'.freeze => mime_type, 'Content-Length'.freeze => content.size.to_s }
240
240
  headers['Content-Disposition'.freeze] = "attachment; filename=\"#{URI.encode(@original_name)}\"" if @original_name
241
241
 
@@ -98,7 +98,7 @@ module ActiveFedora
98
98
  # GET could be slow if it's a big resource, we're using HEAD to avoid this problem,
99
99
  # but this causes more requests to Fedora.
100
100
  return [] unless Ldp::Response.rdf_source?(resource.head)
101
- immediate_descendant_uris = resource.graph.query(predicate: ::RDF::LDP.contains).map { |descendant| descendant.object.to_s }
101
+ immediate_descendant_uris = resource.graph.query(predicate: ::RDF::Vocab::LDP.contains).map { |descendant| descendant.object.to_s }
102
102
  all_descendants_uris = [uri]
103
103
  immediate_descendant_uris.each do |descendant_uri|
104
104
  all_descendants_uris += descendant_uris(descendant_uri)
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.1.1"
2
+ VERSION = "9.1.2"
3
3
  end
@@ -10,7 +10,7 @@ module ActiveFedora
10
10
  end
11
11
 
12
12
  def save(*)
13
- if super
13
+ if super && !new_record?
14
14
  metadata_node.metadata_uri = described_by # TODO only necessary if the URI was < > before
15
15
  metadata_node.save # TODO if changed?
16
16
  end
@@ -7,6 +7,10 @@ module ActiveFedora
7
7
  def initialize(file)
8
8
  @file = file
9
9
  super(file.uri, ldp_source.graph)
10
+ if self.class.type && !self.type.include?(self.class.type)
11
+ # Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123
12
+ self.get_values(:type) << self.class.type
13
+ end
10
14
  end
11
15
 
12
16
  def metadata_uri= uri
@@ -37,12 +41,26 @@ module ActiveFedora
37
41
 
38
42
  def save
39
43
  raise "Save the file first" if file.new_record?
40
- change_set = ChangeSet.new(self, self, changed_attributes.keys)
41
- SparqlInsert.new(change_set.changes, ::RDF::URI.new(file.uri)).execute(metadata_uri)
44
+ SparqlInsert.new(changes_for_update, ::RDF::URI.new(file.uri)).execute(metadata_uri)
42
45
  @ldp_source = nil
43
46
  true
44
47
  end
45
48
 
49
+ def changed_attributes
50
+ super.tap do |changed|
51
+ if type.present?
52
+ changed['type'] = true
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def changes_for_update
60
+ ChangeSet.new(self, self, changed_attributes.keys).changes
61
+ end
62
+
63
+
46
64
  class << self
47
65
  def parent_class= parent
48
66
  @parent_class = parent
@@ -25,6 +25,17 @@ describe "Collection members" do
25
25
  expect(library.books.any?).to be false
26
26
  end
27
27
  end
28
+
29
+ context "loading the association prior to a save that affects the association" do
30
+ let(:library) { Library.new }
31
+ before do
32
+ Book.create
33
+ library.books
34
+ library.save
35
+ end
36
+ subject { library.books.size }
37
+ it { is_expected.to eq 0 }
38
+ end
28
39
  end
29
40
 
30
41
  describe "looking up has_many" do
@@ -2,10 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::WithMetadata do
4
4
  before do
5
- class Sample < ActiveFedora::Base
6
- contains :file, class_name: 'SampleFile'
7
- end
8
-
9
5
  class SampleFile < ActiveFedora::File
10
6
  include ActiveFedora::WithMetadata
11
7
 
@@ -17,11 +13,9 @@ describe ActiveFedora::WithMetadata do
17
13
 
18
14
  after do
19
15
  Object.send(:remove_const, :SampleFile)
20
- Object.send(:remove_const, :Sample)
21
16
  end
22
17
 
23
- let(:base) { Sample.new }
24
- let(:file) { base.file }
18
+ let(:file) { SampleFile.new }
25
19
 
26
20
  describe "properties" do
27
21
  before do
@@ -38,15 +32,57 @@ describe ActiveFedora::WithMetadata do
38
32
 
39
33
  describe "#save" do
40
34
  before do
41
- file.content = "Hey"
42
35
  file.title = ["foo"]
43
- base.save
44
- base.reload
45
36
  end
46
37
 
47
- it "should save the metadata too" do
48
- expect(base.file.title).to eq ['foo']
38
+ context "if the object saves (because it has content)" do
39
+ before do
40
+ file.content = "Hey"
41
+ file.save
42
+ end
43
+
44
+ let(:reloaded) { SampleFile.new(file.uri) }
45
+
46
+ it "should save the metadata too" do
47
+ expect(reloaded.title).to eq ['foo']
48
+ end
49
+ end
50
+
51
+ context "if the object is a new_record (didn't save)" do
52
+ it "doesn't save the metadata" do
53
+ expect(file.metadata_node).not_to receive(:save)
54
+ file.save
55
+ end
49
56
  end
50
57
  end
51
58
 
59
+ context "when RDF.type is set" do
60
+ let(:book) { RDF::URI.new("http://example.com/ns/Book") }
61
+
62
+ before do
63
+ class SampleBook < ActiveFedora::File
64
+ include ActiveFedora::WithMetadata
65
+
66
+ metadata do
67
+ configure type: RDF::URI.new("http://example.com/ns/Book")
68
+ end
69
+ end
70
+
71
+ file.content = 'foo'
72
+ file.save
73
+ end
74
+
75
+ after do
76
+ Object.send(:remove_const, :SampleBook)
77
+ end
78
+
79
+ let(:file) { SampleBook.new }
80
+ let(:reloaded_file) { SampleBook.new(file.uri) }
81
+
82
+ it "persists the configured type" do
83
+ expect(reloaded_file.metadata_node.query(predicate: ::RDF.type).map(&:object)).to include book
84
+ end
85
+
86
+ end
87
+
52
88
  end
@@ -222,4 +222,14 @@ describe ActiveFedora::Datastream do
222
222
  end
223
223
  end
224
224
  end
225
+
226
+ describe "#save" do
227
+ let(:file) { described_class.new }
228
+ context "when there is nothing to save" do
229
+ it "should not write" do
230
+ expect(file.ldp_source).not_to receive(:create)
231
+ expect(file.save).to be true
232
+ end
233
+ end
234
+ end
225
235
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::WithMetadata::MetadataNode do
4
+ let(:generated_schema) { Class.new(described_class) }
5
+
6
+ let(:file) { ActiveFedora::File.new }
7
+ let(:node) { generated_schema.new(file) }
8
+ let(:book) { RDF::URI.new('http://example.com/ns/Book') }
9
+
10
+ describe "#changed_attributes" do
11
+ subject { node.changed_attributes }
12
+
13
+ context "when type is not set" do
14
+ it { is_expected.to eq({}) }
15
+ end
16
+
17
+ context "when type is set" do
18
+ before do
19
+ generated_schema.configure type: book
20
+ end
21
+
22
+ it { is_expected.to eq('type' => true) }
23
+ end
24
+ end
25
+
26
+ describe "changes_for_update" do
27
+ subject { node.send(:changes_for_update) }
28
+
29
+ context "when type is not set" do
30
+ it { is_expected.to eq({}) }
31
+ end
32
+
33
+ context "when type is set" do
34
+ before do
35
+ generated_schema.configure type: book
36
+ end
37
+
38
+ it "is expected to have the rdf type statement" do
39
+ expect(subject[::RDF.type]).to be_kind_of RDF::Queryable::Enumerator
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+ 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.1.1
4
+ version: 9.1.2
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-04-17 00:00:00.000000000 Z
13
+ date: 2015-06-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -138,20 +138,6 @@ dependencies:
138
138
  - - "~>"
139
139
  - !ruby/object:Gem::Version
140
140
  version: 0.3.0
141
- - !ruby/object:Gem::Dependency
142
- name: rdf-ldp
143
- requirement: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: '0'
148
- type: :runtime
149
- prerelease: false
150
- version_requirements: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- version: '0'
155
141
  - !ruby/object:Gem::Dependency
156
142
  name: rdoc
157
143
  requirement: !ruby/object:Gem::Requirement
@@ -555,6 +541,7 @@ files:
555
541
  - spec/unit/solr_service_spec.rb
556
542
  - spec/unit/sparql_insert_spec.rb
557
543
  - spec/unit/validations_spec.rb
544
+ - spec/unit/with_metadata/metadata_node_spec.rb
558
545
  homepage: https://github.com/projecthydra/active_fedora
559
546
  licenses:
560
547
  - APACHE2
@@ -575,7 +562,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
575
562
  version: '0'
576
563
  requirements: []
577
564
  rubyforge_project:
578
- rubygems_version: 2.4.5
565
+ rubygems_version: 2.4.8
579
566
  signing_key:
580
567
  specification_version: 4
581
568
  summary: A convenience libary for manipulating documents in the Fedora Repository.