active-fedora 9.0.1 → 9.0.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: bcb26f9bfdb6735d9ce9a9b0b296c002960d10f4
4
- data.tar.gz: b41e2e83f13386a5b2c64c4e37c53319920cfdec
3
+ metadata.gz: d965581bccc2e324f6336a4f7c5efb78efad4fcc
4
+ data.tar.gz: 72afbee2a1034a97575d0bfbfb74fed1e3d1ca14
5
5
  SHA512:
6
- metadata.gz: 2e374f17c791d3ad5284cff49c624e9c922f2a459bb163bcd649f3c3f5abcfdab72875d750bb923a80f03887fbe844440e1545a11ac9af9da3cdb77bf998c17a
7
- data.tar.gz: 7d4c6d6c3d2267244ac337ad0d4b5e1f5543e4e161665c302ea6989db0dc3bc1295678efcc9c1481e81679cea138033e3b4bb0c58d58d681ac7b30476eb5831d
6
+ metadata.gz: e72f35a6d6effd301066113a82479a9924e67b6f137e97db989cef3e9d7ac48790835d074fb617f222a07d7b9641ca49aac0bba4ec6e778da23340eff3edf857
7
+ data.tar.gz: 0689886286c8acc0aea9f4a19b70fac85b7da7d011ecdfcf13c140ab5e5479f900063d5ca5d88e94a315a83d88d72ccdd26b268240a6615596a481542f16c89b
@@ -19,7 +19,11 @@ module ActiveFedora::Associations::Builder
19
19
  mixin.send(:define_method, name) do |*params|
20
20
  association(name).reader(*params).tap do |file|
21
21
  set_uri = uri.kind_of?(RDF::URI) ? uri.value.present? : uri.present?
22
- file.uri = "#{uri}/#{name}" if set_uri
22
+ if set_uri
23
+ file_uri = "#{uri}/#{name}"
24
+ file.uri = file_uri
25
+ file.exists! if contains_assertions.include?(file_uri)
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -13,8 +13,16 @@ module ActiveFedora
13
13
  @config[:base_path] || '/'
14
14
  end
15
15
 
16
+ def user
17
+ @config[:user]
18
+ end
19
+
20
+ def password
21
+ @config[:password]
22
+ end
23
+
16
24
  def connection
17
- @connection ||= CachingConnection.new(host)
25
+ @connection ||= CachingConnection.new(authorized_connection)
18
26
  end
19
27
 
20
28
  def ldp_resource_service
@@ -41,5 +49,11 @@ module ActiveFedora
41
49
  @root_resource_path ||= base_path.sub(SLASH, BLANK)
42
50
  end
43
51
 
52
+ def authorized_connection
53
+ connection = Faraday.new(host)
54
+ connection.basic_auth(user, password)
55
+ connection
56
+ end
57
+
44
58
  end
45
59
  end
@@ -58,14 +58,21 @@ module ActiveFedora
58
58
  ldp_source.subject
59
59
  end
60
60
 
61
+ # If this file have a parent with ldp#contains, we know it is not new.
62
+ # By tracking exists we prevent an unnecessary HEAD request.
61
63
  def new_record?
62
- ldp_source.new?
64
+ !@exists && ldp_source.new?
63
65
  end
64
66
 
65
67
  def uri= uri
66
68
  @ldp_source = Ldp::Resource::BinarySource.new(ldp_connection, uri, '', ActiveFedora.fedora.host + ActiveFedora.fedora.base_path)
67
69
  end
68
70
 
71
+ # If we know the record to exist (parent has LDP:contains), we can avoid unnecessary HEAD requests
72
+ def exists!
73
+ @exists = true
74
+ end
75
+
69
76
  # When restoring from previous versions, we need to reload certain attributes from Fedora
70
77
  def reload
71
78
  return if new_record?
@@ -248,11 +255,11 @@ module ActiveFedora
248
255
  ldp_source.content = content
249
256
  if new_record?
250
257
  ldp_source.create do |req|
251
- req.headers = headers
258
+ req.headers.merge!(headers)
252
259
  end
253
260
  else
254
261
  ldp_source.update do |req|
255
- req.headers = headers
262
+ req.headers.merge!(headers)
256
263
  end
257
264
  end
258
265
  reset
@@ -293,9 +300,21 @@ module ActiveFedora
293
300
  # @returns [Stream] an object that responds to each
294
301
  def stream(range = nil)
295
302
  uri = URI.parse(self.uri)
296
- headers = {}
297
- headers['Range'] = range if range
298
- FileBody.new(uri, headers)
303
+ FileBody.new(uri, headers(range, authorization_key))
304
+ end
305
+
306
+ # @returns current authorization token from Ldp::Client
307
+ def authorization_key
308
+ self.ldp_source.client.http.headers.fetch("Authorization", nil)
309
+ end
310
+
311
+ # @param range [String] from #stream
312
+ # @param key [String] from #authorization_key
313
+ # @returns [Hash]
314
+ def headers(range, key, result = Hash.new)
315
+ result["Range"] = range if range
316
+ result["Authorization"] = key if key
317
+ result
299
318
  end
300
319
 
301
320
  class FileBody
@@ -62,6 +62,10 @@ module ActiveFedora
62
62
  @values.map {|v| FakeStatement.new(v) }
63
63
  end
64
64
 
65
+ def objects
66
+ @values
67
+ end
68
+
65
69
  class FakeStatement
66
70
  def initialize(value)
67
71
  @value = value
@@ -89,7 +93,7 @@ module ActiveFedora
89
93
  end
90
94
 
91
95
  def reflection(predicate)
92
- @model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }.first
96
+ Array(@model.outgoing_reflections.find { |key, reflection| reflection.predicate == predicate }).first
93
97
  end
94
98
  end
95
99
 
@@ -39,9 +39,10 @@ module ActiveFedora
39
39
 
40
40
  alias update_attributes update
41
41
 
42
- #Deletes a Base object, also deletes the info indexed in Solr, and
43
- #the underlying inner_object. If this object is held in any relationships (ie inbound relationships
44
- #outside of this object it will remove it from those items rels-ext as well
42
+ # Deletes an object from Fedora and deletes the indexed record from Solr.
43
+ # Delete does not run any callbacks, so consider using _destroy_ instead.
44
+ # @param [Hash] opts
45
+ # @option opts [Boolean] :eradicate if passed in, eradicate the tombstone from Fedora
45
46
  def delete(opts = {})
46
47
  return self if new_record?
47
48
 
@@ -68,6 +69,9 @@ module ActiveFedora
68
69
  freeze
69
70
  end
70
71
 
72
+ # Delete the object from Fedora and Solr. Run any before/after/around callbacks for destroy
73
+ # @param [Hash] opts
74
+ # @option opts [Boolean] :eradicate if passed in, eradicate the tombstone from Fedora
71
75
  def destroy(*args)
72
76
  raise ReadOnlyRecord if readonly?
73
77
  delete(*args)
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "9.0.1"
2
+ VERSION = "9.0.2"
3
3
  end
@@ -1,6 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::AttachedFiles do
4
+ describe "#contains" do
5
+ before do
6
+ class FooHistory < ActiveFedora::Base
7
+ contains 'child'
8
+ end
9
+ end
10
+ after do
11
+ Object.send(:remove_const, :FooHistory)
12
+ end
13
+
14
+ context "when the object exists" do
15
+ let!(:o) { FooHistory.create }
16
+ before do
17
+ o.child.content = "HMMM"
18
+ o.save
19
+ end
20
+
21
+ it "should not need to do a head on the children" do
22
+ f = FooHistory.find(o.id)
23
+ expect(f.ldp_source.client).not_to receive(:head)
24
+ f.child.content
25
+ end
26
+ end
27
+ end
4
28
  describe "serializing datastreams" do
5
29
  before do
6
30
  class TestingMetadataSerializing < ActiveFedora::Base
@@ -19,16 +19,18 @@ describe ActiveFedora do
19
19
 
20
20
  let(:good_url) { ActiveFedora.fedora_config.credentials[:url] }
21
21
  let(:bad_url) { good_url.gsub('/rest', '/') }
22
+ let(:user) { ActiveFedora.fedora_config.credentials[:user] }
23
+ let(:password) { ActiveFedora.fedora_config.credentials[:password] }
22
24
 
23
25
  it "should connect OK" do
24
26
  expect(ActiveFedora::Base.logger).to_not receive(:warn)
25
- ActiveFedora::Fedora.new(url: good_url, base_path: '/test')
27
+ ActiveFedora::Fedora.new(url: good_url, base_path: '/test', user: user, password: password)
26
28
  end
27
29
 
28
30
  it "should not connect and warn" do
29
31
  expect(ActiveFedora::Base.logger).to receive(:warn)
30
32
  expect {
31
- ActiveFedora::Fedora.new(url: bad_url, base_path: '/test')
33
+ ActiveFedora::Fedora.new(url: bad_url, base_path: '/test', user: user, password: password)
32
34
  }.to raise_error Ldp::HttpError
33
35
  end
34
36
  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.1
4
+ version: 9.0.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-02-10 00:00:00.000000000 Z
13
+ date: 2015-02-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -560,7 +560,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
560
560
  version: '0'
561
561
  requirements: []
562
562
  rubyforge_project:
563
- rubygems_version: 2.2.2
563
+ rubygems_version: 2.4.5
564
564
  signing_key:
565
565
  specification_version: 4
566
566
  summary: A convenience libary for manipulating documents in the Fedora Repository.