hydra-derivatives 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +14 -7
  3. data/Gemfile +3 -2
  4. data/README.md +6 -1
  5. data/Rakefile +1 -1
  6. data/VERSION +1 -1
  7. data/hydra-derivatives.gemspec +9 -6
  8. data/lib/hydra/derivatives/config.rb +1 -1
  9. data/lib/hydra/derivatives/processors/document.rb +4 -1
  10. data/lib/hydra/derivatives/processors/full_text.rb +5 -3
  11. data/solr/config/xslt/example.xsl +1 -1
  12. data/solr/config/xslt/luke.xsl +1 -1
  13. metadata +132 -92
  14. data/spec/fixtures/FlashPix.ppt +0 -0
  15. data/spec/fixtures/adobe1998.tif +0 -0
  16. data/spec/fixtures/countdown.avi +0 -0
  17. data/spec/fixtures/jpeg2k_config.yml +0 -20
  18. data/spec/fixtures/piano_note.wav +0 -0
  19. data/spec/fixtures/sample.rtf +0 -68
  20. data/spec/fixtures/test.dng +0 -0
  21. data/spec/fixtures/test.doc +0 -0
  22. data/spec/fixtures/test.docx +0 -0
  23. data/spec/fixtures/test.pdf +0 -0
  24. data/spec/fixtures/test.pptx +0 -0
  25. data/spec/fixtures/test.tif +0 -0
  26. data/spec/fixtures/test.xls +0 -0
  27. data/spec/fixtures/test.xlsx +0 -0
  28. data/spec/fixtures/world.png +0 -0
  29. data/spec/processors/active_encode_spec.rb +0 -132
  30. data/spec/processors/document_spec.rb +0 -41
  31. data/spec/processors/full_text_spec.rb +0 -127
  32. data/spec/processors/image_spec.rb +0 -124
  33. data/spec/processors/jpeg2k_spec.rb +0 -82
  34. data/spec/processors/processor_spec.rb +0 -53
  35. data/spec/processors/shell_based_processor_spec.rb +0 -28
  36. data/spec/processors/video_spec.rb +0 -59
  37. data/spec/runners/active_encode_derivatives_spec.rb +0 -38
  38. data/spec/runners/runner_spec.rb +0 -9
  39. data/spec/services/audio_derivatives_spec.rb +0 -78
  40. data/spec/services/persist_basic_contained_output_file_service_spec.rb +0 -42
  41. data/spec/services/persist_external_file_output_file_service_spec.rb +0 -26
  42. data/spec/services/persist_output_file_service_spec.rb +0 -47
  43. data/spec/services/remote_source_file_spec.rb +0 -33
  44. data/spec/services/retrieve_source_file_service_spec.rb +0 -60
  45. data/spec/services/tempfile_service_spec.rb +0 -54
  46. data/spec/spec_helper.rb +0 -40
  47. data/spec/units/audio_encoder_spec.rb +0 -34
  48. data/spec/units/config_spec.rb +0 -50
  49. data/spec/units/derivatives_spec.rb +0 -70
  50. data/spec/units/io_decorator_spec.rb +0 -45
  51. data/spec/units/logger_spec.rb +0 -27
  52. data/spec/units/transcoding_spec.rb +0 -354
@@ -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
@@ -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
@@ -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
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Derivatives do
4
- before(:all) do
5
- class CustomFile < ActiveFedora::Base
6
- include Hydra::Derivatives
7
- end
8
- end
9
-
10
- after(:all) { Object.send(:remove_const, :CustomFile) }
11
-
12
- describe "source_file_service" do
13
- before { subject.source_file_service = custom_source_file_service }
14
-
15
- context "with a global configuration setting" do
16
- subject { CustomFile }
17
-
18
- let(:custom_source_file_service) { "fake service" }
19
-
20
- it "utilizes the default source file service" do
21
- expect(subject.source_file_service).to eq(custom_source_file_service)
22
- end
23
- end
24
-
25
- context "with an instance level configuration setting" do
26
- subject { CustomFile.new }
27
-
28
- let(:custom_source_file_service) { "another fake service" }
29
-
30
- it "accepts a custom source file service as an option" do
31
- expect(subject.source_file_service).to eq(custom_source_file_service)
32
- end
33
- end
34
- end
35
-
36
- Hydra::Derivatives::CONFIG_METHODS.each do |method|
37
- describe method.to_s do
38
- it 'returns the config value' do
39
- expect(subject.send(method)).to eq subject.config.send(method)
40
- end
41
- end
42
- describe "#{method}=" do
43
- around do |example|
44
- value = subject.config.send(method)
45
- example.call
46
- subject.send("#{method}=", value)
47
- end
48
-
49
- it 'stores config changes' do
50
- expect { subject.send("#{method}=", "new_value") }.to change { subject.config.send(method) }.from(subject.config.send(method)).to("new_value")
51
- end
52
- end
53
- end
54
-
55
- describe 'reset_config!' do
56
- it "resets the configuration" do
57
- subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
58
- subject.reset_config!
59
- expect(subject.ffmpeg_path).to eq('ffmpeg')
60
-
61
- subject.kdu_compress_path = '/usr/local/bin/kdu_compress'
62
- subject.reset_config!
63
- expect(subject.kdu_compress_path).to eq('kdu_compress')
64
-
65
- subject.active_encode_poll_time = 2
66
- subject.reset_config!
67
- expect(subject.active_encode_poll_time).to eq 10
68
- end
69
- end
70
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
- require 'stringio'
3
-
4
- describe Hydra::Derivatives::IoDecorator do
5
- let(:file) { StringIO.new('hello') }
6
-
7
- context "with one argument" do
8
- let(:decorator) { described_class.new(file) }
9
-
10
- describe "#read" do
11
- subject { decorator.read }
12
-
13
- it { is_expected.to eq 'hello' }
14
- end
15
- end
16
-
17
- context "with three arguments" do
18
- let(:decorator) { described_class.new(file, 'text/plain', 'help.txt') }
19
-
20
- describe "#read" do
21
- subject { decorator.read }
22
-
23
- it { is_expected.to eq 'hello' }
24
- end
25
-
26
- describe "mime_type" do
27
- subject { decorator.mime_type }
28
-
29
- it { is_expected.to eq 'text/plain' }
30
- end
31
-
32
- describe "original_filename" do
33
- subject { decorator.original_filename }
34
-
35
- it { is_expected.to eq 'help.txt' }
36
- end
37
-
38
- describe "original_name" do
39
- subject { decorator.original_name }
40
-
41
- before { allow(Deprecation).to receive(:warn) }
42
- it { is_expected.to eq 'help.txt' }
43
- end
44
- end
45
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Hydra::Derivatives::Logger do
4
- context "with log levels" do
5
- let(:levels) { %w[unknown fatal error warn info debug] }
6
-
7
- it "responds successfully" do
8
- levels.each do |level|
9
- expect(described_class.respond_to?(level)).to be_truthy
10
- end
11
- end
12
- it "accepts messages" do
13
- expect(described_class.warn("message")).to be_truthy
14
- end
15
- end
16
-
17
- it "delegates respond_to_missing" do
18
- allow(ActiveFedora::Base.logger).to receive(:respond_to_missing?).with(:weird, false).and_return(true)
19
- expect(described_class.respond_to_missing?(:weird)).to be_truthy
20
- end
21
-
22
- context "with garbage" do
23
- it "raises an error" do
24
- expect { described_class.garbage }.to raise_error(NoMethodError)
25
- end
26
- end
27
- end
@@ -1,354 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Transcoding" do
4
- before(:all) do
5
- class GenericFile < ActiveFedora::Base
6
- include Hydra::Derivatives
7
- property :mime_type_from_fits, predicate: ::RDF::URI('http://example.com/mime'), multiple: false
8
- has_subresource 'original_file'
9
-
10
- def create_derivatives(_filename)
11
- case mime_type_from_fits
12
- when 'application/pdf'
13
- PdfDerivatives.create(self, source: :original_file,
14
- outputs: [{ label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" }])
15
- FullTextExtract.create(self, source: :original_file, outputs: [{ url: "#{uri}/fulltext" }])
16
- when 'audio/x-wav'
17
- AudioDerivatives.create(self, source: :original_file,
18
- outputs: [
19
- { label: :mp3, format: 'mp3', url: "#{uri}/original_file_mp3" },
20
- { label: :ogg, format: 'ogg', url: "#{uri}/original_file_ogg" }
21
- ])
22
- when 'video/x-msvideo'
23
- VideoDerivatives.create(self, source: :original_file,
24
- outputs: [
25
- { label: :mp4, format: 'mp4', url: "#{uri}/original_file_mp4" },
26
- { label: :webm, format: 'webm', url: "#{uri}/original_file_webm" },
27
- { label: :thumbnail, format: 'jpg', url: "#{uri}/thumbnail" }
28
- ])
29
- when 'image/png', 'image/jpg'
30
- ImageDerivatives.create(self, source: :original_file,
31
- outputs: [
32
- { label: :medium, size: "300x300>", url: "#{uri}/original_file_medium" },
33
- { label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" },
34
- { label: :access, format: 'jpg', url: "#{uri}/access" }
35
- ])
36
- when 'application/vnd.ms-powerpoint'
37
- DocumentDerivatives.create(self, source: :original_file,
38
- outputs: [
39
- { label: :preservation, format: 'pptx', url: "#{uri}/original_file_preservation" },
40
- { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
41
- { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }
42
- ])
43
- when 'text/rtf'
44
- DocumentDerivatives.create(self, source: :original_file,
45
- outputs: [
46
- { label: :preservation, format: 'odt', url: "#{uri}/original_file_preservation" },
47
- { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
48
- { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }
49
- ])
50
- when 'application/msword'
51
- DocumentDerivatives.create(self, source: :original_file,
52
- outputs: [
53
- { label: :preservation, format: 'docx', url: "#{uri}/original_file_preservation" },
54
- { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
55
- { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }
56
- ])
57
- when 'application/vnd.ms-excel'
58
- DocumentDerivatives.create(self, source: :original_file,
59
- outputs: [
60
- { label: :preservation, format: 'xlsx', url: "#{uri}/original_file_preservation" },
61
- { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
62
- { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }
63
- ])
64
- when 'image/tiff'
65
- Jpeg2kImageDerivatives.create(self, source: :original_file,
66
- outputs: [
67
- { label: :resized, format: 'jp2', recipe: :default, processor: 'jpeg2k_image', resize: "600x600>", url: "#{uri}/resized" },
68
- { label: :config_lookup, format: 'jp2', recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" },
69
- { label: :string_recipe, format: 'jp2', recipe: '-jp2_space sRGB', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" },
70
- { label: :diy, format: 'jp2', processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }
71
- ])
72
- when 'image/x-adobe-dng'
73
- ImageDerivatives.create(self, source: :original_file,
74
- outputs: [
75
- { label: :access, size: "300x300>", format: 'jpg', processor: :raw_image, url: "#{uri}/original_file_access" },
76
- { label: :thumb, size: "100x100>", format: 'jpg', processor: :raw_image, url: "#{uri}/original_file_thumb" }
77
- ])
78
- end
79
- end
80
- end
81
- end
82
-
83
- after(:all) do
84
- Object.send(:remove_const, :GenericFile)
85
- end
86
-
87
- describe "with an attached image" do
88
- let(:filename) { File.expand_path('../../fixtures/world.png', __FILE__) }
89
- let(:attachment) { File.open(filename) }
90
- let(:file) do
91
- GenericFile.new(mime_type_from_fits: 'image/png') do |f|
92
- f.original_file.content = attachment
93
- f.original_file.mime_type = f.mime_type_from_fits
94
- f.save!
95
- end
96
- end
97
-
98
- it "transcodes" do
99
- expect(file.attached_files.key?('original_file_medium')).to be_falsey
100
- file.create_derivatives(filename)
101
- file.reload
102
- expect(file.attached_files['original_file_medium']).to have_content
103
- expect(file.attached_files['original_file_medium'].mime_type).to eq('image/png')
104
- expect(file.attached_files['original_file_thumb']).to have_content
105
- expect(file.attached_files['original_file_thumb'].mime_type).to eq('image/png')
106
- expect(file.attached_files['access']).to have_content
107
- expect(file.attached_files['access'].mime_type).to eq('image/jpeg')
108
- expect(file.attached_files.key?('original_file_text')).to be_falsey
109
- end
110
- end
111
-
112
- describe "with an attached RAW image", requires_imagemagick: true do
113
- let(:filename) { File.expand_path('../../fixtures/test.dng', __FILE__) }
114
- let(:attachment) { File.open(filename) }
115
- let(:file) do
116
- GenericFile.new(mime_type_from_fits: 'image/x-adobe-dng') do |f|
117
- f.original_file.content = attachment
118
- f.original_file.mime_type = f.mime_type_from_fits
119
- f.save!
120
- end
121
- end
122
-
123
- it "transcodes" do
124
- expect(file.attached_files.key?('original_file_access')).to be_falsey
125
- expect(file.attached_files.key?('original_file_thumb')).to be_falsey
126
-
127
- file.create_derivatives(filename)
128
- file.reload
129
- expect(file.attached_files['original_file_access']).to have_content
130
- expect(file.attached_files['original_file_access'].mime_type).to eq('image/jpeg')
131
- expect(file.attached_files['original_file_thumb']).to have_content
132
- expect(file.attached_files['original_file_thumb'].mime_type).to eq('image/jpeg')
133
- end
134
- end
135
-
136
- describe "with an attached pdf", requires_imagemagick: true do
137
- let(:filename) { File.expand_path('../../fixtures/test.pdf', __FILE__) }
138
- let(:attachment) { File.open(filename) }
139
- let(:file) do
140
- GenericFile.new(mime_type_from_fits: 'application/pdf') do |t|
141
- t.original_file.content = attachment
142
- t.original_file.mime_type = t.mime_type_from_fits
143
- t.save
144
- end
145
- end
146
-
147
- it "transcodes" do
148
- expect(file.attached_files.key?('original_file_thumb')).to be_falsey
149
- file.create_derivatives(filename)
150
- file.reload
151
- expect(file.attached_files['original_file_thumb']).to have_content
152
- expect(file.attached_files['original_file_thumb'].mime_type).to eq('image/png')
153
- expect(file.attached_files['fulltext'].content).to match(/This PDF file was created using CutePDF/)
154
- expect(file.attached_files['fulltext'].mime_type).to eq 'text/plain;charset=UTF-8'
155
- end
156
- end
157
-
158
- describe "with an attached audio", requires_ffmpeg: true do
159
- let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
160
- let(:attachment) { File.open(filename) }
161
- let(:file) do
162
- GenericFile.new(mime_type_from_fits: 'audio/x-wav').tap do |t|
163
- t.original_file.content = attachment
164
- t.original_file.mime_type = t.mime_type_from_fits
165
- t.save
166
- end
167
- end
168
-
169
- it "transcodes" do
170
- file.create_derivatives(filename)
171
- file.reload
172
- expect(file.attached_files['original_file_mp3']).to have_content
173
- expect(file.attached_files['original_file_mp3'].mime_type).to eq('audio/mpeg')
174
- expect(file.attached_files['original_file_ogg']).to have_content
175
- expect(file.attached_files['original_file_ogg'].mime_type).to eq('audio/ogg')
176
- end
177
- end
178
-
179
- describe "when the source datastrem has an unknown mime_type", requires_ffmpeg: true do
180
- let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
181
- let(:attachment) { File.open(filename) }
182
- let(:file) do
183
- GenericFile.new(mime_type_from_fits: 'audio/x-wav').tap do |t|
184
- t.original_file.content = attachment
185
- t.original_file.mime_type = 'audio/vnd.wav'
186
- t.save
187
- end
188
- end
189
-
190
- it "transcodes" do
191
- allow_any_instance_of(::Logger).to receive(:warn)
192
- file.create_derivatives(filename)
193
- file.reload
194
- expect(file.attached_files['original_file_mp3']).to have_content
195
- expect(file.attached_files['original_file_mp3'].mime_type).to eq('audio/mpeg')
196
- end
197
- end
198
-
199
- describe "with an attached video", requires_ffmpeg: true do
200
- let(:filename) { File.expand_path('../../fixtures/countdown.avi', __FILE__) }
201
- let(:attachment) { File.open(filename) }
202
- let(:file) do
203
- GenericFile.create(mime_type_from_fits: 'video/x-msvideo') do |t|
204
- t.original_file.content = attachment
205
- t.original_file.mime_type = t.mime_type_from_fits
206
- t.save
207
- end
208
- end
209
-
210
- it "transcodes" do
211
- file.create_derivatives(filename)
212
- file.reload
213
- expect(file.attached_files['original_file_mp4']).to have_content
214
- expect(file.attached_files['original_file_mp4'].mime_type).to eq('video/mp4')
215
- expect(file.attached_files['original_file_webm']).to have_content
216
- expect(file.attached_files['original_file_webm'].mime_type).to eq('video/webm')
217
- expect(file.attached_files['thumbnail']).to have_content
218
- expect(file.attached_files['thumbnail'].mime_type).to eq('image/jpeg')
219
- end
220
-
221
- context "when the timeout is set" do
222
- before do
223
- Hydra::Derivatives::Processors::Video::Processor.timeout = 0.2 # 200ms
224
- end
225
- after do
226
- Hydra::Derivatives::Processors::Video::Processor.timeout = nil # clear timeout
227
- end
228
-
229
- it "raises a timeout" do
230
- expect { file.create_derivatives(filename) }.to raise_error Hydra::Derivatives::TimeoutError
231
- end
232
- end
233
- end
234
-
235
- describe "with an attached Powerpoint", requires_libreoffice: true do
236
- let(:filename) { File.expand_path('../../fixtures/FlashPix.ppt', __FILE__) }
237
- let(:attachment) { File.open(filename) }
238
- let(:file) do
239
- GenericFile.create(mime_type_from_fits: 'application/vnd.ms-powerpoint') do |t|
240
- t.original_file.content = attachment
241
- t.original_file.mime_type = t.mime_type_from_fits
242
- t.save
243
- end
244
- end
245
-
246
- it "transcodes" do
247
- file.create_derivatives(filename)
248
- file.reload
249
- expect(file.attached_files['original_file_thumbnail']).to have_content
250
- expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
251
- expect(file.attached_files['original_file_access']).to have_content
252
- expect(file.attached_files['original_file_access'].mime_type).to eq('application/pdf')
253
- expect(file.attached_files['original_file_preservation']).to have_content
254
- expect(file.attached_files['original_file_preservation'].mime_type).to eq('application/vnd.openxmlformats-officedocument.presentationml.presentation')
255
- end
256
- end
257
-
258
- describe "with an attached rich text format", requires_libreoffice: true do
259
- let(:filename) { File.expand_path('../../fixtures/sample.rtf', __FILE__) }
260
- let(:attachment) { File.open(filename) }
261
- let(:file) do
262
- GenericFile.new(mime_type_from_fits: 'text/rtf').tap do |t|
263
- t.original_file.content = attachment
264
- t.original_file.mime_type = t.mime_type_from_fits
265
- t.save
266
- end
267
- end
268
-
269
- it "transcodes" do
270
- file.create_derivatives(filename)
271
- file.reload
272
- expect(file.attached_files['original_file_thumbnail']).to have_content
273
- expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
274
- expect(file.attached_files['original_file_access']).to have_content
275
- expect(file.attached_files['original_file_access'].mime_type).to eq('application/pdf')
276
- expect(file.attached_files['original_file_preservation']).to have_content
277
- expect(file.attached_files['original_file_preservation'].mime_type).to eq('application/vnd.oasis.opendocument.text')
278
- end
279
- end
280
-
281
- describe "with an attached word doc format", requires_libreoffice: true do
282
- let(:filename) { File.expand_path('../../fixtures/test.doc', __FILE__) }
283
- let(:attachment) { File.open(filename) }
284
-
285
- let(:file) do
286
- GenericFile.new(mime_type_from_fits: 'application/msword').tap do |t|
287
- t.original_file.content = attachment
288
- t.original_file.mime_type = t.mime_type_from_fits
289
- t.save
290
- end
291
- end
292
-
293
- it "transcodes" do
294
- file.create_derivatives(filename)
295
- file.reload
296
- expect(file.attached_files['original_file_thumbnail']).to have_content
297
- expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
298
- expect(file.attached_files['original_file_access']).to have_content
299
- expect(file.attached_files['original_file_access'].mime_type).to eq('application/pdf')
300
- expect(file.attached_files['original_file_preservation']).to have_content
301
- expect(file.attached_files['original_file_preservation'].mime_type).to eq('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
302
- end
303
- end
304
-
305
- describe "with an attached excel format", requires_libreoffice: true do
306
- let(:filename) { File.expand_path('../../fixtures/test.xls', __FILE__) }
307
- let(:attachment) { File.open(filename) }
308
-
309
- let(:file) do
310
- GenericFile.new(mime_type_from_fits: 'application/vnd.ms-excel').tap do |t|
311
- t.original_file.content = attachment
312
- t.original_file.mime_type = t.mime_type_from_fits
313
- t.save
314
- end
315
- end
316
-
317
- it "transcodes" do
318
- file.create_derivatives(filename)
319
- file.reload
320
- expect(file.attached_files['original_file_thumbnail']).to have_content
321
- expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
322
- expect(file.attached_files['original_file_access']).to have_content
323
- expect(file.attached_files['original_file_access'].mime_type).to eq('application/pdf')
324
- expect(file.attached_files['original_file_preservation']).to have_content
325
- expect(file.attached_files['original_file_preservation'].mime_type).to eq('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
326
- end
327
- end
328
-
329
- describe "with an attached tiff", requires_kdu_compress: true do
330
- let(:filename) { File.expand_path('../../fixtures/test.tif', __FILE__) }
331
- let(:attachment) { File.open(filename) }
332
-
333
- let(:file) do
334
- GenericFile.new(mime_type_from_fits: 'image/tiff').tap do |t|
335
- t.original_file.content = attachment
336
- t.original_file.mime_type = t.mime_type_from_fits
337
- t.save
338
- end
339
- end
340
-
341
- it "transcodes" do
342
- file.create_derivatives(filename)
343
- file.reload
344
- expect(file.attached_files['original_file_diy']).to have_content
345
- expect(file.attached_files['original_file_diy'].mime_type).to eq('image/jp2')
346
- expect(file.attached_files['config_lookup']).to have_content
347
- expect(file.attached_files['config_lookup'].mime_type).to eq('image/jp2')
348
- expect(file.attached_files['resized']).to have_content
349
- expect(file.attached_files['resized'].mime_type).to eq('image/jp2')
350
- expect(file.attached_files['string_recipe']).to have_content
351
- expect(file.attached_files['string_recipe'].mime_type).to eq('image/jp2')
352
- end
353
- end
354
- end