Skip to content

Commit

Permalink
Fix ActiveFedora adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
escowles committed Sep 7, 2017
1 parent e5bbf53 commit d552847
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 38 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -24,6 +24,9 @@ Style/PredicateName:
Style/MethodMissing:
Exclude:
- "lib/valkyrie/persistence/active_fedora/resource_factory.rb"
Lint/UselessAssignment:
Exclude:
- 'lib/valkyrie/persistence/active_fedora/orm/resource.rb'
Metrics/BlockLength:
Exclude:
- 'config/environments/**/*'
Expand Down
Expand Up @@ -34,7 +34,7 @@ def characterize(save: true)
# Provides the SHA256 hexdigest string for the file
# @return String
def checksum
Digest::SHA256.file(filename).hexdigest
Digest::SHA256.file(filename).hexdigest if filename
end

def json_output
Expand Down
4 changes: 2 additions & 2 deletions lib/tasks/multispec.rake
@@ -1,10 +1,10 @@
# frozen_string_literal: true
desc "Runs tests with a variety of backends"
task :multispec do
# TODO: fix fedora/fedora
profiles = [
{ metadata: 'memory', storage: 'memory' },
{ metadata: 'postgres', storage: 'disk' }
{ metadata: 'postgres', storage: 'disk' },
{ metadata: 'fedora', storage: 'fedora' }
]
profiles.each do |profile|
ENV['VALKYRIE_METADATA'] = profile[:metadata]
Expand Down
9 changes: 9 additions & 0 deletions lib/valkyrie/persistence/active_fedora/orm/resource.rb
Expand Up @@ -22,6 +22,7 @@ class Schema < ActiveTriples::Schema
property :height, predicate: ::RDF::URI("http://example.com/height")
property :width, predicate: ::RDF::URI("http://example.com/height")
property :checksum, predicate: ::RDF::URI("http://example.com/checksum")
property :file_size, predicate: ::RDF::URI("http://example.com/file_size")
end
class NestedResource < ActiveTriples::Resource
def initialize(uri = RDF::Node.new, _parent = ActiveTriples::Resource.new)
Expand Down Expand Up @@ -52,6 +53,14 @@ class Resource < ActiveFedora::Base
property :nested_resource, predicate: ::RDF::URI("http://example.com/nested_resource"), class_name: "Valkyrie::Persistence::ActiveFedora::ORM::NestedResource"
accepts_nested_attributes_for :nested_resource

def size=(size)
file_size = size
end

def size
file_size
end

def to_solr(doc = {})
super.merge(
uri_ssi: uri.to_s
Expand Down
2 changes: 1 addition & 1 deletion spec/derivative_services/image_derivative_service_spec.rb
Expand Up @@ -50,7 +50,7 @@

expect(derivative).to be_present
derivative_file = Valkyrie::StorageAdapter.find_by(id: derivative.file_identifiers.first)
image = MiniMagick::Image.open(derivative_file.io.path)
image = MiniMagick::Image.open(derivative_file.disk_path)
expect(image.width).to eq 105
expect(image.height).to eq 150
end
Expand Down
4 changes: 2 additions & 2 deletions valkyrie/lib/valkyrie/storage/disk.rb
Expand Up @@ -30,10 +30,10 @@ def file_path(id)

# Return the file associated with the given identifier
# @param id [Valkyrie::ID]
# @return [Valkyrie::StorageAdapter::DiskFile]
# @return [Valkyrie::StorageAdapter::File]
def find_by(id:)
return unless handles?(id: id)
Valkyrie::StorageAdapter::DiskFile.new(id: Valkyrie::ID.new(id.to_s), io: ::File.open(file_path(id), 'rb'))
Valkyrie::StorageAdapter::File.new(id: Valkyrie::ID.new(id.to_s), io: ::File.open(file_path(id), 'rb'))
end

class BucketedStorage
Expand Down
2 changes: 1 addition & 1 deletion valkyrie/lib/valkyrie/storage/fedora.rb
Expand Up @@ -42,7 +42,7 @@ def initialize(source, size)
@source = source
@size = size
end
delegate :read, :rewind, to: :io
delegate :each, :read, :rewind, to: :io

# There is no streaming support in faraday (https://github.com/lostisland/faraday/pull/604)
# @return [StringIO]
Expand Down
12 changes: 5 additions & 7 deletions valkyrie/lib/valkyrie/storage_adapter.rb
Expand Up @@ -45,6 +45,10 @@ def stream
io
end

def disk_path
Pathname.new(io.path)
end

# @param id [Valkyre::ID]
# @param digests [Array<Digest>]
# @return [Array<Digest>]
Expand All @@ -70,12 +74,6 @@ def valid?(size: nil, digests:)
end
end

class DiskFile < File
def disk_path
Pathname.new(io.path)
end
end

class StreamFile < File
def disk_path
Pathname.new(tmp_file.path)
Expand All @@ -84,7 +82,7 @@ def disk_path
private

def tmp_file_name
id.to_s.split('://').last
id.to_s.tr(':/', '__')
end

def tmp_file_path
Expand Down
23 changes: 0 additions & 23 deletions valkyrie/spec/valkyrie/storage_adapter/disk_file_spec.rb

This file was deleted.

17 changes: 16 additions & 1 deletion valkyrie/spec/valkyrie/storage_adapter/file_spec.rb
Expand Up @@ -3,7 +3,22 @@
require 'valkyrie/specs/shared_specs'

RSpec.describe Valkyrie::StorageAdapter::File do
let(:io) { instance_double(IO) }
let(:io) { instance_double(::File) }
let(:file) { described_class.new(id: "test_file", io: io) }
it_behaves_like "a Valkyrie::StorageAdapter::File"

describe '#disk_path' do
before do
allow(io).to receive(:read).and_return('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
end
context 'with the disk or memory storage adapter' do
before do
allow(io).to receive(:path).and_return('/test/path')
end

it 'provides a path to the file for the storage adapter' do
expect(file.disk_path).to eq Pathname.new('/test/path')
end
end
end
end

0 comments on commit d552847

Please sign in to comment.