hydra-derivatives 3.5.0 → 3.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +56 -23
- data/Gemfile +3 -2
- data/README.md +16 -5
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/hydra-derivatives.gemspec +9 -6
- data/lib/hydra/derivatives/config.rb +1 -1
- data/lib/hydra/derivatives/processors/document.rb +4 -1
- data/lib/hydra/derivatives/processors/full_text.rb +5 -3
- data/lib/hydra/derivatives/processors/image.rb +4 -2
- data/solr/config/xslt/example.xsl +1 -1
- data/solr/config/xslt/luke.xsl +1 -1
- metadata +134 -94
- data/spec/fixtures/FlashPix.ppt +0 -0
- data/spec/fixtures/adobe1998.tif +0 -0
- data/spec/fixtures/countdown.avi +0 -0
- data/spec/fixtures/jpeg2k_config.yml +0 -20
- data/spec/fixtures/piano_note.wav +0 -0
- data/spec/fixtures/sample.rtf +0 -68
- data/spec/fixtures/test.dng +0 -0
- data/spec/fixtures/test.doc +0 -0
- data/spec/fixtures/test.docx +0 -0
- data/spec/fixtures/test.pdf +0 -0
- data/spec/fixtures/test.pptx +0 -0
- data/spec/fixtures/test.tif +0 -0
- data/spec/fixtures/test.xls +0 -0
- data/spec/fixtures/test.xlsx +0 -0
- data/spec/fixtures/world.png +0 -0
- data/spec/processors/active_encode_spec.rb +0 -132
- data/spec/processors/document_spec.rb +0 -41
- data/spec/processors/full_text_spec.rb +0 -127
- data/spec/processors/image_spec.rb +0 -124
- data/spec/processors/jpeg2k_spec.rb +0 -82
- data/spec/processors/processor_spec.rb +0 -53
- data/spec/processors/shell_based_processor_spec.rb +0 -28
- data/spec/processors/video_spec.rb +0 -59
- data/spec/runners/active_encode_derivatives_spec.rb +0 -38
- data/spec/runners/runner_spec.rb +0 -9
- data/spec/services/audio_derivatives_spec.rb +0 -78
- data/spec/services/persist_basic_contained_output_file_service_spec.rb +0 -42
- data/spec/services/persist_external_file_output_file_service_spec.rb +0 -26
- data/spec/services/persist_output_file_service_spec.rb +0 -47
- data/spec/services/remote_source_file_spec.rb +0 -33
- data/spec/services/retrieve_source_file_service_spec.rb +0 -60
- data/spec/services/tempfile_service_spec.rb +0 -54
- data/spec/spec_helper.rb +0 -40
- data/spec/units/audio_encoder_spec.rb +0 -34
- data/spec/units/config_spec.rb +0 -50
- data/spec/units/derivatives_spec.rb +0 -70
- data/spec/units/io_decorator_spec.rb +0 -45
- data/spec/units/logger_spec.rb +0 -27
- data/spec/units/transcoding_spec.rb +0 -354
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::Processors::Processor do
|
4
|
-
subject { described_class.new(file_path, directives) }
|
5
|
-
|
6
|
-
let(:object) { "Fake Object" }
|
7
|
-
let(:source_name) { 'content' }
|
8
|
-
let(:directives) { { thumb: "100x100>" } }
|
9
|
-
let(:file_path) { Pathname.new("test/unicorn.jpg") }
|
10
|
-
|
11
|
-
describe "output_file_service" do
|
12
|
-
let(:custom_output_file_service) { "fake service" }
|
13
|
-
let(:another_custom_output_file_service) { "another fake service" }
|
14
|
-
|
15
|
-
context "with a global configuration setting" do
|
16
|
-
before do
|
17
|
-
allow(Hydra::Derivatives).to receive(:output_file_service).and_return(custom_output_file_service)
|
18
|
-
end
|
19
|
-
it "utilizes the default output file service" do
|
20
|
-
expect(subject.output_file_service).to eq(custom_output_file_service)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "with an instance level configuration setting" do
|
25
|
-
subject do
|
26
|
-
described_class.new('/opt/derivatives/foo.mp4', directives,
|
27
|
-
output_file_service: another_custom_output_file_service)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "accepts a custom output file service as an option" do
|
31
|
-
expect(subject.output_file_service).to eq(another_custom_output_file_service)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "#process" do
|
37
|
-
it "raises an implementation error" do
|
38
|
-
expect { subject.process }.to raise_error "Processor is an abstract class. Implement `process' on Hydra::Derivatives::Processors::Processor"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#output_file" do
|
43
|
-
it "raises an implementation error" do
|
44
|
-
expect { subject.output_file }.to raise_error "Processor is an abstract class. Utilize an implementation of a PersistOutputFileService class in Hydra::Derivatives::Processors::Processor"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "#output_filename_for" do
|
49
|
-
it "returns the basename of the source file" do
|
50
|
-
expect(subject.output_filename_for("ignored")).to eq "unicorn.jpg"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::Processors::ShellBasedProcessor do
|
4
|
-
before do
|
5
|
-
class TestProcessor
|
6
|
-
include Hydra::Derivatives::Processors::ShellBasedProcessor
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
after { Object.send(:remove_const, :TestProcessor) }
|
11
|
-
|
12
|
-
let(:processor) { TestProcessor.new }
|
13
|
-
let(:proc_class) { TestProcessor }
|
14
|
-
|
15
|
-
describe "options_for" do
|
16
|
-
it "returns a hash" do
|
17
|
-
expect(processor.options_for("a")).to be_a Hash
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe ".execute" do
|
22
|
-
context "when an EOF error occurs" do
|
23
|
-
it "doesn't crash" do
|
24
|
-
proc_class.execute("echo foo")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::Processors::Video::Processor do
|
4
|
-
subject { described_class.new(file_name, directives) }
|
5
|
-
|
6
|
-
let(:file_name) { 'foo/bar.mov' }
|
7
|
-
|
8
|
-
describe ".config" do
|
9
|
-
before do
|
10
|
-
@original_config = described_class.config.dup
|
11
|
-
described_class.config.mpeg4.codec = "-vcodec mpeg4 -acodec aac -strict -2"
|
12
|
-
end
|
13
|
-
|
14
|
-
after { described_class.config = @original_config }
|
15
|
-
let(:directives) { { label: :thumb, format: "mp4", url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
|
16
|
-
|
17
|
-
it "is configurable" do
|
18
|
-
expect(subject).to receive(:encode_file).with("mp4", Hydra::Derivatives::Processors::Ffmpeg::OUTPUT_OPTIONS => "-s 320x240 -vcodec mpeg4 -acodec aac -strict -2 -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100", Hydra::Derivatives::Processors::Ffmpeg::INPUT_OPTIONS => "")
|
19
|
-
subject.process
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when arguments are passed as a hash" do
|
24
|
-
context "when a video format is requested" do
|
25
|
-
let(:directives) { { label: :thumb, format: 'webm', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
|
26
|
-
|
27
|
-
it "creates a fedora resource and infers the name" do
|
28
|
-
expect(subject).to receive(:encode_file).with("webm", Hydra::Derivatives::Processors::Ffmpeg::OUTPUT_OPTIONS => "-s 320x240 -vcodec libvpx -acodec libvorbis -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100", Hydra::Derivatives::Processors::Ffmpeg::INPUT_OPTIONS => "")
|
29
|
-
subject.process
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "when a jpg is requested" do
|
34
|
-
let(:directives) { { label: :thumb, format: 'jpg', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
|
35
|
-
|
36
|
-
it "creates a fedora resource and infers the name" do
|
37
|
-
expect(subject).to receive(:encode_file).with("jpg", output_options: "-s 320x240 -vcodec mjpeg -vframes 1 -an -f rawvideo", input_options: " -itsoffset -2")
|
38
|
-
subject.process
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when an mkv is requested" do
|
43
|
-
let(:directives) { { label: :thumb, format: 'mkv', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
|
44
|
-
|
45
|
-
it "creates a fedora resource and infers the name" do
|
46
|
-
expect(subject).to receive(:encode_file).with("mkv", Hydra::Derivatives::Processors::Ffmpeg::OUTPUT_OPTIONS => "-s 320x240 -vcodec ffv1 -g 30 -b:v 345k -ac 2 -ab 96k -ar 44100", Hydra::Derivatives::Processors::Ffmpeg::INPUT_OPTIONS => "")
|
47
|
-
subject.process
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when an unknown format is requested" do
|
52
|
-
let(:directives) { { label: :thumb, format: 'nocnv', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
|
53
|
-
|
54
|
-
it "raises an ArgumentError" do
|
55
|
-
expect { subject.process }.to raise_error ArgumentError, "Unknown format `nocnv'"
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::ActiveEncodeDerivatives do
|
4
|
-
describe '.create' do
|
5
|
-
before do
|
6
|
-
class TestVideo < ActiveFedora::Base
|
7
|
-
attr_accessor :remote_file_name
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
after { Object.send(:remove_const, :TestVideo) }
|
12
|
-
|
13
|
-
let(:file_path) { 'some/path/to/my_video.mp4' }
|
14
|
-
let(:video_record) { TestVideo.new(remote_file_name: file_path) }
|
15
|
-
let(:options) { { source: :remote_file_name, outputs: [low_res_video] } }
|
16
|
-
let(:low_res_video) { { some_key: 'some options to pass to my encoder service' } }
|
17
|
-
let(:processor) { instance_double('processor') }
|
18
|
-
|
19
|
-
it 'calls the processor with the right arguments' do
|
20
|
-
expect(Hydra::Derivatives::Processors::ActiveEncode).to receive(:new).with(file_path, low_res_video, output_file_service: Hydra::Derivatives::PersistExternalFileOutputFileService).and_return(processor)
|
21
|
-
expect(processor).to receive(:process)
|
22
|
-
described_class.create(video_record, options)
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'with a custom encode class' do
|
26
|
-
before { class TestEncode < ::ActiveEncode::Base; end }
|
27
|
-
after { Object.send(:remove_const, :TestEncode) }
|
28
|
-
|
29
|
-
let(:options) { { encode_class: TestEncode, source: :remote_file_name, outputs: [low_res_video] } }
|
30
|
-
|
31
|
-
it 'calls the processor with the right arguments' do
|
32
|
-
expect(Hydra::Derivatives::Processors::ActiveEncode).to receive(:new).with(file_path, low_res_video, output_file_service: Hydra::Derivatives::PersistExternalFileOutputFileService, encode_class: TestEncode).and_return(processor)
|
33
|
-
expect(processor).to receive(:process)
|
34
|
-
described_class.create(video_record, options)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
data/spec/runners/runner_spec.rb
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Hydra::Derivatives::Runner do
|
4
|
-
describe ".processor_class" do
|
5
|
-
it "raises an error if it's not overridden" do
|
6
|
-
expect { described_class.processor_class }.to raise_error "Overide the processor_class method in a sub class"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::AudioDerivatives do
|
4
|
-
describe ".create" do
|
5
|
-
let(:filename) { 'spec/fixtures/piano_note.wav' }
|
6
|
-
let(:af_path) { ActiveFedora.fedora.host + ActiveFedora.fedora.base_path }
|
7
|
-
|
8
|
-
context "with a filename", requires_ffmpeg: true do
|
9
|
-
before do
|
10
|
-
class LocalFileService
|
11
|
-
def self.call(file_name, _options, &_block)
|
12
|
-
yield File.open(file_name)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
described_class.source_file_service = LocalFileService
|
16
|
-
end
|
17
|
-
|
18
|
-
after do
|
19
|
-
# restore the default
|
20
|
-
described_class.source_file_service = Hydra::Derivatives::RetrieveSourceFileService
|
21
|
-
Object.send(:remove_const, :LocalFileService)
|
22
|
-
end
|
23
|
-
|
24
|
-
it "creates derivatives" do
|
25
|
-
described_class.create(filename,
|
26
|
-
outputs: [{ label: 'mp3', format: 'mp3', url: "#{af_path}/1234/mp3" },
|
27
|
-
{ label: 'ogg', format: 'ogg', url: "#{af_path}/1234/ogg" }])
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context "with an object" do
|
32
|
-
let(:object) { "Fake Object" }
|
33
|
-
let(:source_name) { :content }
|
34
|
-
let(:file) { instance_double("the file") }
|
35
|
-
|
36
|
-
before do
|
37
|
-
allow(object).to receive(:original_file).and_return(file)
|
38
|
-
allow(Hydra::Derivatives::TempfileService).to receive(:create).with(file)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "creates derivatives" do
|
42
|
-
described_class.create(object,
|
43
|
-
source: :original_file,
|
44
|
-
outputs: [{ label: 'mp3', format: 'mp3' },
|
45
|
-
{ label: 'ogg', format: 'ogg' }])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "source_file" do
|
51
|
-
subject { described_class }
|
52
|
-
|
53
|
-
it "relies on the source_file_service" do
|
54
|
-
expect(subject.source_file_service).to receive(:call).with('foo/bar.aiff', baz: true)
|
55
|
-
subject.source_file('foo/bar.aiff', baz: true)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "output_file_service" do
|
60
|
-
before do
|
61
|
-
class FakeOutputService
|
62
|
-
end
|
63
|
-
Hydra::Derivatives.output_file_service = FakeOutputService
|
64
|
-
end
|
65
|
-
|
66
|
-
after do
|
67
|
-
# restore the default
|
68
|
-
Hydra::Derivatives.output_file_service = Hydra::Derivatives::PersistBasicContainedOutputFileService
|
69
|
-
Object.send(:remove_const, :FakeOutputService)
|
70
|
-
end
|
71
|
-
|
72
|
-
subject { described_class.output_file_service }
|
73
|
-
|
74
|
-
it "defaults to the value set on Hydra::Derivatives" do
|
75
|
-
expect(subject).to eq FakeOutputService
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::PersistBasicContainedOutputFileService do
|
4
|
-
before(:all) do
|
5
|
-
class BasicContainerObject < ActiveFedora::Base
|
6
|
-
has_subresource "the_derivative_name"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
let(:object) { BasicContainerObject.new }
|
11
|
-
let(:file_path) { File.join(fixture_path, 'test.tif') }
|
12
|
-
let(:file) { File.new(file_path) }
|
13
|
-
let(:destination_name) { 'the_derivative_name' }
|
14
|
-
|
15
|
-
# alas, we have to support this as the default because all legacy code (and fedora 3 systems) created basic contained files
|
16
|
-
# The new signature does not have a destination_name option. There is a default string that will get applied, but his might
|
17
|
-
# not be sufficient.
|
18
|
-
context "when file is basic contained (default assumption)" do
|
19
|
-
let(:object) { BasicContainerObject.create }
|
20
|
-
let(:content) { StringIO.new("fake file content") }
|
21
|
-
let(:resource) { object.public_send(destination_name.to_sym) }
|
22
|
-
|
23
|
-
context "when the content is a stream" do
|
24
|
-
it "persists the file to the specified destination on the given object" do
|
25
|
-
described_class.call(content, format: 'jpg', url: "#{object.uri}/the_derivative_name")
|
26
|
-
expect(resource.content).to start_with("fake file content")
|
27
|
-
expect(resource.content_changed?).to eq false
|
28
|
-
expect(resource.mime_type).to eq 'image/jpeg'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "when the content is a string" do
|
33
|
-
let(:content) { "fake file content - ÅÄÖ" }
|
34
|
-
|
35
|
-
it "persists the file to the specified destination on the given object" do
|
36
|
-
described_class.call(content, format: 'txt', url: "#{object.uri}/the_derivative_name")
|
37
|
-
expect(resource.content).to eq("fake file content - ÅÄÖ")
|
38
|
-
expect(resource.mime_type).to eq 'text/plain;charset=UTF-8'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::PersistExternalFileOutputFileService do
|
4
|
-
before do
|
5
|
-
class ExternalDerivativeContainerObject < ActiveFedora::Base
|
6
|
-
has_subresource "external_derivative"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
after do
|
10
|
-
Object.send(:remove_const, :ExternalDerivativeContainerObject)
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:object) { ExternalDerivativeContainerObject.create }
|
14
|
-
let(:directives) { { url: "#{object.uri}/external_derivative" } }
|
15
|
-
let(:external_url) { 'http://www.example.com/external/content' }
|
16
|
-
let(:output) { { url: external_url } }
|
17
|
-
let(:destination_name) { 'external_derivative' }
|
18
|
-
|
19
|
-
describe '.call' do
|
20
|
-
it "persists the external file to the specified destination on the given object" do
|
21
|
-
described_class.call(output, directives)
|
22
|
-
expect(object.send(destination_name.to_sym).mime_type).to eq "message/external-body;access-type=URL;url=\"http://www.example.com/external/content\""
|
23
|
-
expect(object.send(destination_name.to_sym).content).to eq ''
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe Hydra::Derivatives::PersistOutputFileService do
|
4
|
-
let(:original_filename_class) do
|
5
|
-
Class.new do
|
6
|
-
def original_filename
|
7
|
-
"original filename"
|
8
|
-
end
|
9
|
-
|
10
|
-
def mime_type
|
11
|
-
"image/tiff"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".call" do
|
17
|
-
it "raises an error if not implemented" do
|
18
|
-
expect { described_class.call(nil, nil) }.to raise_error NotImplementedError, "PersistOutputFileService is an abstract class. Implement `call' on Class"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe ".determine_original_name" do
|
23
|
-
context "when given something with an original filename" do
|
24
|
-
it "returns it from that file" do
|
25
|
-
expect(described_class.determine_original_name(original_filename_class.new)).to eq "original filename"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
context "when given something without an original filename" do
|
29
|
-
it "returns derivative" do
|
30
|
-
expect(described_class.determine_original_name("tardis")).to eq "derivative"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe ".determine_mime_type" do
|
36
|
-
context "when given something with #mime_type" do
|
37
|
-
it "returns it from that file" do
|
38
|
-
expect(described_class.determine_mime_type(original_filename_class.new)).to eq "image/tiff"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
context "when given something without #mime_type" do
|
42
|
-
it "returns application/octet-stream" do
|
43
|
-
expect(described_class.determine_mime_type("tardis")).to eq "application/octet-stream"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class TestObject < ActiveFedora::Base
|
4
|
-
attr_accessor :source_file_name
|
5
|
-
end
|
6
|
-
|
7
|
-
describe Hydra::Derivatives::RemoteSourceFile do
|
8
|
-
describe '.call' do
|
9
|
-
let(:file_name) { 'my_source_file.mp4' }
|
10
|
-
|
11
|
-
context 'when you pass in a String file name' do
|
12
|
-
let(:input_obj) { file_name }
|
13
|
-
let(:options) { {} }
|
14
|
-
|
15
|
-
it 'yields the file name' do
|
16
|
-
expect do |blk|
|
17
|
-
described_class.call(input_obj, options, &blk)
|
18
|
-
end.to yield_with_args(file_name)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when you pass in an ActiveFedora::Base object ' do
|
23
|
-
let(:input_obj) { TestObject.new(source_file_name: file_name) }
|
24
|
-
let(:options) { { source: :source_file_name } }
|
25
|
-
|
26
|
-
it 'yields the file name' do
|
27
|
-
expect do |blk|
|
28
|
-
described_class.call(input_obj, options, &blk)
|
29
|
-
end.to yield_with_args(file_name)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::RetrieveSourceFileService do
|
4
|
-
before(:all) do
|
5
|
-
# Need a class that:
|
6
|
-
# 1) Allows you to set .uri= (to work with directly_contains)
|
7
|
-
# 2) has a metadata_node (to work with directly_contains_one)
|
8
|
-
class FileWithMetadata < ActiveFedora::File
|
9
|
-
include ActiveFedora::WithMetadata
|
10
|
-
end
|
11
|
-
|
12
|
-
class ObjectWithBasicContainer < ActiveFedora::Base
|
13
|
-
has_subresource "contained_file"
|
14
|
-
end
|
15
|
-
|
16
|
-
class DirectContainerObject < ActiveFedora::Base
|
17
|
-
directly_contains :files, has_member_relation: ::RDF::URI("http://pcdm.org/use#hasFile"),
|
18
|
-
class_name: "FileWithMetadata"
|
19
|
-
directly_contains_one :directly_contained_file, through: :files, type: ::RDF::URI("http://pcdm.org/use#OriginalFile")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when file is in basic container (default assumption)" do # alas, we have to support this as the default because all legacy code (and fedora 3 systems) created indirectly contained files
|
24
|
-
let(:object) { ObjectWithBasicContainer.new }
|
25
|
-
let(:content) { "fake file content (basic container)" }
|
26
|
-
let(:source_name) { 'contained_file' }
|
27
|
-
|
28
|
-
before do
|
29
|
-
allow(object).to receive(:uri).and_return('http://foo/bar')
|
30
|
-
allow(object.contained_file).to receive(:new_record?).and_return(false)
|
31
|
-
allow(object.contained_file).to receive(:has_content?).and_return(true)
|
32
|
-
allow(object.contained_file).to receive(:mime_type).and_return('text/html')
|
33
|
-
# attaches the file as an indirectly contained object
|
34
|
-
object.contained_file.content = content
|
35
|
-
end
|
36
|
-
|
37
|
-
it "persists the file to the specified destination on the given object" do
|
38
|
-
described_class.call(object, source: source_name) do |f|
|
39
|
-
expect(f.read).to eq(object.contained_file.content)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
context "when file is directly contained" do # direct containers are more efficient, but most legacy code will have indirect containers
|
45
|
-
let(:object) { DirectContainerObject.new }
|
46
|
-
let(:content) { "fake file content (direct container)" }
|
47
|
-
let(:source_name) { 'directly_contained_file' }
|
48
|
-
|
49
|
-
before do
|
50
|
-
object.save # can't build directly contained objects without saving the parent first
|
51
|
-
object.build_directly_contained_file
|
52
|
-
object.directly_contained_file.content = content
|
53
|
-
end
|
54
|
-
it "retrieves the file from the specified location on the given object" do
|
55
|
-
described_class.call(object, source: source_name) do |f|
|
56
|
-
expect(f.read).to eq(object.directly_contained_file.content)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::TempfileService do
|
4
|
-
subject { described_class.new(file) }
|
5
|
-
|
6
|
-
let(:class_with_metadata_extraction) do
|
7
|
-
Class.new do
|
8
|
-
attr_reader :content, :mime_type, :uri
|
9
|
-
|
10
|
-
def initialize(options = {})
|
11
|
-
@content = options.fetch(:content, '')
|
12
|
-
@mime_uype = options.fetch(:mime_type, nil)
|
13
|
-
@uri = 'http://example.com/pid/123'
|
14
|
-
end
|
15
|
-
|
16
|
-
def has_content?
|
17
|
-
content.present?
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:class_with_tempfile) do
|
23
|
-
Class.new do
|
24
|
-
def to_tempfile
|
25
|
-
"stub"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:initialization_options) { { content: 'abc', mime_type: 'text/plain' } }
|
31
|
-
|
32
|
-
let(:file) { class_with_metadata_extraction.new(initialization_options) }
|
33
|
-
|
34
|
-
describe '#tempfile' do
|
35
|
-
it 'has a method called to_tempfile' do
|
36
|
-
expect { |b| subject.tempfile(&b) }.to yield_with_args(Tempfile)
|
37
|
-
end
|
38
|
-
it "will call read on passed content if available" do
|
39
|
-
file_with_readable_content = class_with_metadata_extraction.new(content: StringIO.new("test"), mime_type: 'text/plain')
|
40
|
-
|
41
|
-
service = described_class.new(file_with_readable_content)
|
42
|
-
|
43
|
-
service.tempfile do |t|
|
44
|
-
expect(t.read).to eq "test"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
it "delegates down to `to_tempfile` if available" do
|
48
|
-
tempfile_stub = class_with_tempfile.new
|
49
|
-
service = described_class.new(tempfile_stub)
|
50
|
-
|
51
|
-
expect(service.tempfile).to eq "stub"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
ENV['environment'] ||= 'test'
|
2
|
-
ENV['RAILS_ENV'] = 'test'
|
3
|
-
|
4
|
-
require 'simplecov'
|
5
|
-
require 'coveralls'
|
6
|
-
|
7
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
|
8
|
-
[
|
9
|
-
SimpleCov::Formatter::HTMLFormatter,
|
10
|
-
Coveralls::SimpleCov::Formatter
|
11
|
-
]
|
12
|
-
)
|
13
|
-
SimpleCov.minimum_coverage 100
|
14
|
-
SimpleCov.start do
|
15
|
-
add_filter '/spec'
|
16
|
-
end
|
17
|
-
|
18
|
-
# - RSpec adds ./lib to the $LOAD_PATH
|
19
|
-
require 'hydra/derivatives'
|
20
|
-
# Resque.inline = Rails.env.test?
|
21
|
-
require 'byebug' unless ENV['TRAVIS']
|
22
|
-
|
23
|
-
require 'active_fedora/cleaner'
|
24
|
-
ActiveFedora::Base.logger = Logger.new(STDOUT)
|
25
|
-
RSpec.configure do |config|
|
26
|
-
config.before(:each) do
|
27
|
-
ActiveFedora::Cleaner.clean!
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# Workaround for RAW image support until these are pushed upstream to
|
32
|
-
# the MIME Types gem
|
33
|
-
require 'mime-types'
|
34
|
-
dng_format = MIME::Type.new('image/x-adobe-dng')
|
35
|
-
dng_format.extensions = 'dng'
|
36
|
-
MIME::Types.add(dng_format)
|
37
|
-
|
38
|
-
def fixture_path
|
39
|
-
File.expand_path("../fixtures", __FILE__)
|
40
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hydra::Derivatives::AudioEncoder do
|
4
|
-
before do
|
5
|
-
@audio_encoder = described_class.new
|
6
|
-
end
|
7
|
-
|
8
|
-
describe 'fdk_aac?' do
|
9
|
-
it 'outpus libfdk_aac if your ffmpeg was compiled with the library' do
|
10
|
-
enable_libfdk_flags = '--enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --with-fdk-aac'
|
11
|
-
@audio_encoder.instance_variable_set(:@ffmpeg_output, enable_libfdk_flags)
|
12
|
-
audio_encoder = @audio_encoder.audio_encoder
|
13
|
-
expect(audio_encoder).to eq('libfdk_aac')
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'outputs aac if your ffmpeg was compiled with the library' do
|
17
|
-
enable_libfdk_flags = '--enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample'
|
18
|
-
@audio_encoder.instance_variable_set(:@ffmpeg_output, enable_libfdk_flags)
|
19
|
-
audio_encoder = @audio_encoder.audio_encoder
|
20
|
-
expect(audio_encoder).to eq('aac')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when ffmpeg is not installed" do
|
25
|
-
it "logs a warning" do
|
26
|
-
allow(ActiveFedora::Base.logger).to receive(:warn)
|
27
|
-
allow(Open3).to receive(:capture3).with('ffmpeg -codecs').and_raise StandardError
|
28
|
-
|
29
|
-
described_class.new
|
30
|
-
|
31
|
-
expect(ActiveFedora::Base.logger).to have_received(:warn).with('Unable to find ffmpeg')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/spec/units/config_spec.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "the configuration" do
|
4
|
-
subject { Hydra::Derivatives::Config.new }
|
5
|
-
|
6
|
-
before do
|
7
|
-
# It's not always /tmp; it depends on OS and ENV vars
|
8
|
-
allow(Dir).to receive(:tmpdir).and_return('/tmp')
|
9
|
-
end
|
10
|
-
|
11
|
-
it "has some configuration defaults" do
|
12
|
-
expect(subject.ffmpeg_path).to eq('ffmpeg')
|
13
|
-
expect(subject.enable_ffmpeg).to be true
|
14
|
-
expect(subject.libreoffice_path).to eq('soffice')
|
15
|
-
expect(subject.temp_file_base).to eq('/tmp')
|
16
|
-
expect(subject.fits_path).to eq('fits.sh')
|
17
|
-
expect(subject.kdu_compress_path).to eq('kdu_compress')
|
18
|
-
expect(subject.output_file_service).to eq(Hydra::Derivatives::PersistBasicContainedOutputFileService)
|
19
|
-
expect(subject.source_file_service).to eq(Hydra::Derivatives::RetrieveSourceFileService)
|
20
|
-
end
|
21
|
-
|
22
|
-
it "lets you change the configuration" do
|
23
|
-
subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
|
24
|
-
expect(subject.ffmpeg_path).to eq('/usr/local/ffmpeg-1.0/bin/ffmpeg')
|
25
|
-
|
26
|
-
subject.kdu_compress_path = '/opt/local/bin/kdu_compress'
|
27
|
-
expect(subject.kdu_compress_path).to eq('/opt/local/bin/kdu_compress')
|
28
|
-
|
29
|
-
subject.enable_ffmpeg = false
|
30
|
-
expect(subject.enable_ffmpeg).to be false
|
31
|
-
end
|
32
|
-
|
33
|
-
it "lets you set a custom output file service" do
|
34
|
-
output_file_service = instance_double("MyOutputFileService")
|
35
|
-
subject.output_file_service = output_file_service
|
36
|
-
expect(subject.output_file_service).to eq(output_file_service)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "lets you set a custom source file service" do
|
40
|
-
source_file_service = instance_double("MyRetriveSourceFileService")
|
41
|
-
subject.source_file_service = source_file_service
|
42
|
-
expect(subject.source_file_service).to eq(source_file_service)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "lets you set the poll time for ActiveEncode jobs" do
|
46
|
-
expect(subject.active_encode_poll_time).to eq 10
|
47
|
-
subject.active_encode_poll_time = 15
|
48
|
-
expect(subject.active_encode_poll_time).to eq 15
|
49
|
-
end
|
50
|
-
end
|