hydra-derivatives 2.0.0 → 3.0.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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -1
  3. data/History.md +43 -0
  4. data/README.md +23 -38
  5. data/VERSION +1 -1
  6. data/hydra-derivatives.gemspec +0 -1
  7. data/lib/hydra/derivatives.rb +23 -123
  8. data/lib/hydra/derivatives/io_decorator.rb +7 -1
  9. data/lib/hydra/derivatives/processors.rb +19 -0
  10. data/lib/hydra/derivatives/processors/audio.rb +6 -0
  11. data/lib/hydra/derivatives/processors/document.rb +28 -0
  12. data/lib/hydra/derivatives/processors/ffmpeg.rb +22 -0
  13. data/lib/hydra/derivatives/processors/full_text.rb +60 -0
  14. data/lib/hydra/derivatives/processors/image.rb +58 -0
  15. data/lib/hydra/derivatives/processors/jpeg2k_image.rb +129 -0
  16. data/lib/hydra/derivatives/processors/processor.rb +38 -0
  17. data/lib/hydra/derivatives/processors/raw_image.rb +37 -0
  18. data/lib/hydra/derivatives/processors/shell_based_processor.rb +108 -0
  19. data/lib/hydra/derivatives/{video.rb → processors/video.rb} +1 -1
  20. data/lib/hydra/derivatives/{video → processors/video}/config.rb +1 -1
  21. data/lib/hydra/derivatives/{video → processors/video}/processor.rb +2 -8
  22. data/lib/hydra/derivatives/runners/audio_derivatives.rb +7 -0
  23. data/lib/hydra/derivatives/runners/document_derivatives.rb +7 -0
  24. data/lib/hydra/derivatives/runners/full_text_extract.rb +16 -0
  25. data/lib/hydra/derivatives/runners/image_derivatives.rb +16 -0
  26. data/lib/hydra/derivatives/runners/jpeg2k_image_derivatives.rb +15 -0
  27. data/lib/hydra/derivatives/runners/pdf_derivatives.rb +6 -0
  28. data/lib/hydra/derivatives/runners/runner.rb +52 -0
  29. data/lib/hydra/derivatives/runners/video_derivatives.rb +7 -0
  30. data/lib/hydra/derivatives/services/mime_type_service.rb +10 -0
  31. data/lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb +23 -8
  32. data/lib/hydra/derivatives/services/persist_output_file_service.rb +4 -5
  33. data/lib/hydra/derivatives/services/retrieve_source_file_service.rb +8 -6
  34. data/spec/processors/full_text.rb +61 -0
  35. data/spec/{units → processors}/image_spec.rb +7 -17
  36. data/spec/{units → processors}/jpeg2k_spec.rb +9 -11
  37. data/spec/processors/processor_spec.rb +36 -0
  38. data/spec/processors/shell_based_processor_spec.rb +19 -0
  39. data/spec/processors/video_spec.rb +40 -0
  40. data/spec/services/audio_derivatives_spec.rb +76 -0
  41. data/spec/services/persist_basic_contained_output_file_service_spec.rb +4 -3
  42. data/spec/services/retrieve_source_file_service_spec.rb +16 -12
  43. data/spec/units/derivatives_spec.rb +18 -26
  44. data/spec/units/io_decorator_spec.rb +33 -0
  45. data/spec/units/transcoding_spec.rb +109 -86
  46. metadata +42 -44
  47. data/lib/hydra/derivatives/audio.rb +0 -19
  48. data/lib/hydra/derivatives/document.rb +0 -56
  49. data/lib/hydra/derivatives/extract_metadata.rb +0 -27
  50. data/lib/hydra/derivatives/ffmpeg.rb +0 -31
  51. data/lib/hydra/derivatives/image.rb +0 -73
  52. data/lib/hydra/derivatives/jpeg2k_image.rb +0 -136
  53. data/lib/hydra/derivatives/processor.rb +0 -33
  54. data/lib/hydra/derivatives/railtie.rb +0 -9
  55. data/lib/hydra/derivatives/raw_image.rb +0 -45
  56. data/lib/hydra/derivatives/shell_based_processor.rb +0 -81
  57. data/spec/lib/hydra/derivatives/extract_metadata_spec.rb +0 -39
  58. data/spec/units/extract_spec.rb +0 -22
  59. data/spec/units/processor_spec.rb +0 -61
  60. data/spec/units/shell_based_processor_spec.rb +0 -22
  61. data/spec/units/video_spec.rb +0 -50
@@ -0,0 +1,19 @@
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
+
14
+ describe "options_for" do
15
+ it "returns a hash" do
16
+ expect(processor.options_for("a")).to be_a Hash
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Derivatives::Processors::Video::Processor do
4
+ let(:file_name) { 'foo/bar.mov' }
5
+ subject { described_class.new(file_name, directives)}
6
+
7
+ describe ".config" do
8
+ before do
9
+ @original_config = described_class.config.dup
10
+ described_class.config.mpeg4.codec = "-vcodec mpeg4 -acodec aac -strict -2"
11
+ end
12
+
13
+ after { described_class.config = @original_config }
14
+ let(:directives) { { label: :thumb, format: "mp4", url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
15
+
16
+ it "should be configurable" do
17
+ 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 => "" })
18
+ subject.process
19
+ end
20
+ end
21
+
22
+ context "when arguments are passed as a hash" do
23
+ context "and a video format is requested" do
24
+ let(:directives) { { label: :thumb, format: 'webm', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
25
+
26
+ it "creates a fedora resource and infers the name" do
27
+ 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 => "" })
28
+ subject.process
29
+ end
30
+ end
31
+
32
+ context "and jpg is requested" do
33
+ let(:directives) { { label: :thumb, format: 'jpg', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
34
+ it "creates a fedora resource and infers the name" do
35
+ expect(subject).to receive(:encode_file).with("jpg", output_options: "-s 320x240 -vcodec mjpeg -vframes 1 -an -f rawvideo", input_options: " -itsoffset -2")
36
+ subject.process
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hydra::Derivatives::AudioDerivatives do
4
+ describe ".create" do
5
+ let(:filename) { 'spec/fixtures/piano_note.wav' }
6
+ context "with a filename", unless: $in_travis do
7
+ before do
8
+ class LocalFileService
9
+ def self.call(file_name, options, &block)
10
+ yield File.open(file_name)
11
+ end
12
+ end
13
+ described_class.source_file_service = LocalFileService
14
+ end
15
+
16
+ after do
17
+ # restore the default
18
+ described_class.source_file_service = Hydra::Derivatives::RetrieveSourceFileService
19
+ Object.send(:remove_const, :LocalFileService)
20
+ end
21
+
22
+ it "creates derivatives" do
23
+ described_class.create(filename,
24
+ outputs: [{ label: 'mp3', format: 'mp3', url: 'http://localhost:8983/fedora/rest/dev/1234/mp3' },
25
+ { label: 'ogg', format: 'ogg', url: 'http://localhost:8983/fedora/rest/dev/1234/ogg' }])
26
+ end
27
+ end
28
+
29
+ context "with an object" do
30
+ let(:object) { "Fake Object" }
31
+ let(:source_name) { :content }
32
+ let(:file) { double("the file") }
33
+
34
+ before do
35
+ allow(object).to receive(:original_file).and_return(file)
36
+ allow(Hydra::Derivatives::TempfileService).to receive(:create).with(file)
37
+ end
38
+
39
+ it "creates derivatives" do
40
+ described_class.create(object,
41
+ source: :original_file,
42
+ outputs: [{ label: 'mp3', format: 'mp3' },
43
+ { label: 'ogg', format: 'ogg' }])
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "source_file" do
49
+ subject { described_class }
50
+
51
+ it "relies on the source_file_service" do
52
+ expect(subject.source_file_service).to receive(:call).with('foo/bar.aiff', { baz: true })
53
+ subject.source_file('foo/bar.aiff', { baz: true })
54
+ end
55
+ end
56
+
57
+ describe "output_file_service" do
58
+ before do
59
+ class FakeOutputService
60
+ end
61
+ Hydra::Derivatives.output_file_service = FakeOutputService
62
+ end
63
+
64
+ after do
65
+ # restore the default
66
+ Hydra::Derivatives.output_file_service = Hydra::Derivatives::PersistBasicContainedOutputFileService
67
+ Object.send(:remove_const, :FakeOutputService)
68
+ end
69
+
70
+ subject { described_class.output_file_service }
71
+
72
+ it "defaults to the value set on Hydra::Derivatives" do
73
+ expect(subject).to eq FakeOutputService
74
+ end
75
+ end
76
+ end
@@ -16,10 +16,11 @@ describe Hydra::Derivatives::PersistBasicContainedOutputFileService do
16
16
  # alas, we have to support this as the default because all legacy code (and fedora 3 systems) created basic contained files
17
17
  # The new signature does not have a destination_name option. There is a default string that will get applied, but his might
18
18
  # not be sufficient.
19
- context "when file is basic contained (default assumption)" do
20
- let(:object) { BasicContainerObject.new }
19
+ context "when file is basic contained (default assumption)" do
20
+ let(:object) { BasicContainerObject.create }
21
+ let(:stream) { StringIO.new("fake file content") }
21
22
  it "persists the file to the specified destination on the given object" do
22
- described_class.call(object, "fake file content", destination_name)
23
+ described_class.call(stream, { format: 'jpg', url: "#{object.uri}/the_derivative_name" })
23
24
  expect(object.send(destination_name.to_sym).content).to eq("fake file content")
24
25
  expect(object.send(destination_name.to_sym).content_changed?).to eq false
25
26
  end
@@ -1,16 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::RetrieveSourceFileService do
4
-
5
4
  before(:all) do
6
-
7
- # Need a class that:
5
+ # Need a class that:
8
6
  # 1) Allows you to set .uri= (to work with directly_contains)
9
7
  # 2) has a metadata_node (to work with directly_contains_one)
10
8
  class FileWithMetadata < ActiveFedora::File
11
9
  include ActiveFedora::WithMetadata
12
10
  end
13
-
11
+
14
12
  class ObjectWithBasicContainer < ActiveFedora::Base
15
13
  contains "contained_file"
16
14
  end
@@ -22,19 +20,24 @@ describe Hydra::Derivatives::RetrieveSourceFileService do
22
20
  end
23
21
  end
24
22
 
25
- subject { described_class.call(object, source_name) }
26
-
27
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
28
24
  let(:object) { ObjectWithBasicContainer.new }
29
25
  let(:content) { "fake file content (basic container)" }
30
26
  let(:source_name) { 'contained_file' }
31
-
27
+
32
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
33
  # attaches the file as an indirectly contained object
34
34
  object.contained_file.content = content
35
35
  end
36
+
36
37
  it "persists the file to the specified destination on the given object" do
37
- expect(subject).to eq(object.contained_file)
38
+ described_class.call(object, { source: source_name }) do |f|
39
+ expect(f.read).to eq(object.contained_file.content)
40
+ end
38
41
  end
39
42
  end
40
43
 
@@ -42,15 +45,16 @@ describe Hydra::Derivatives::RetrieveSourceFileService do
42
45
  let(:object) { DirectContainerObject.new }
43
46
  let(:content) { "fake file content (direct container)" }
44
47
  let(:source_name) { 'directly_contained_file' }
45
-
48
+
46
49
  before do
47
50
  object.save # can't build directly contained objects without saving the parent first
48
51
  object.build_directly_contained_file
49
52
  object.directly_contained_file.content = content
50
53
  end
51
54
  it "retrieves the file from the specified location on the given object" do
52
- expect(subject).to eq(object.directly_contained_file)
55
+ described_class.call(object, { source: source_name }) do |f|
56
+ expect(f.read).to eq(object.directly_contained_file.content)
57
+ end
53
58
  end
54
59
  end
55
-
56
- end
60
+ end
@@ -1,12 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives do
4
-
5
4
  before(:all) do
6
5
  class CustomFile < ActiveFedora::Base
7
6
  include Hydra::Derivatives
8
7
  end
9
- class CustomProcessor < Hydra::Derivatives::Processor
8
+ class CustomProcessor < Hydra::Derivatives::Processors::Processor
10
9
  end
11
10
  class CustomSourceFileService
12
11
  end
@@ -21,34 +20,27 @@ describe Hydra::Derivatives do
21
20
  Object.send(:remove_const, :CustomOutputFileService)
22
21
  end
23
22
 
24
- describe "initialize_processor" do
25
- subject{ CustomFile.new.send(:initialize_processor, :content, { thumb: '100x100>' }, processor: Hydra::Derivatives::Video::Processor, source_file_service: CustomSourceFileService, output_file_service: CustomOutputFileService) }
26
- it "passes source_file_service and output_file_service options to the processor" do
27
- expect(subject.class).to eq(Hydra::Derivatives::Video::Processor)
28
- expect(subject.source_file_service).to eq(CustomSourceFileService)
29
- expect(subject.output_file_service).to eq(CustomOutputFileService)
23
+ describe "source_file_service" do
24
+ let(:custom_source_file_service) { "fake service" }
25
+ before do
26
+ allow(Hydra::Derivatives).to receive(:source_file_service).and_return(custom_source_file_service)
30
27
  end
31
- end
28
+ subject { Class.new { include Hydra::Derivatives } }
32
29
 
33
- context "when using an included processor" do
34
- subject { CustomFile.new.processor_class(:image) }
35
- it { is_expected.to eql Hydra::Derivatives::Image }
36
- end
30
+ context "as a global configuration setting" do
31
+ it "utilizes the default source file service" do
32
+ expect(subject.source_file_service).to eq(custom_source_file_service)
33
+ end
34
+ end
37
35
 
38
- context "when using the video processor" do
39
- subject { CustomFile.new.processor_class(:video) }
40
- it { is_expected.to eql Hydra::Derivatives::Video::Processor }
41
- end
42
-
43
- context "when using the video processor" do
44
- subject { CustomFile.new.processor_class("CustomProcessor") }
45
- it { is_expected.to eql CustomProcessor }
46
- end
36
+ context "as an instance level configuration setting" do
37
+ let(:another_custom_source_file_service) { "another fake service" }
38
+ subject { Class.new { include Hydra::Derivatives }.new }
39
+ before { subject.source_file_service = another_custom_source_file_service }
47
40
 
48
- context "when using a fake processor" do
49
- it "raises an error" do
50
- expect( lambda{ CustomFile.new.processor_class("BogusProcessor") }).to raise_error(NameError)
41
+ it "accepts a custom source file service as an option" do
42
+ expect(subject.source_file_service).to eq(another_custom_source_file_service)
43
+ end
51
44
  end
52
45
  end
53
-
54
46
  end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe Hydra::Derivatives::IoDecorator do
5
+ let(:file) { StringIO.new('hello') }
6
+
7
+ context "one argument" do
8
+ let(:decorator) { described_class.new(file) }
9
+ describe "#read" do
10
+ subject { decorator.read }
11
+ it { is_expected.to eq 'hello' }
12
+ end
13
+ end
14
+
15
+ context "three arguments" do
16
+ let(:decorator) { described_class.new(file, 'text/plain', 'help.txt') }
17
+
18
+ describe "#read" do
19
+ subject { decorator.read }
20
+ it { is_expected.to eq 'hello' }
21
+ end
22
+
23
+ describe "mime_type" do
24
+ subject { decorator.mime_type }
25
+ it { is_expected.to eq 'text/plain' }
26
+ end
27
+
28
+ describe "original_name" do
29
+ subject { decorator.original_name }
30
+ it { is_expected.to eq 'help.txt' }
31
+ end
32
+ end
33
+ end
@@ -2,10 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe "Transcoder" do
4
4
  before(:all) do
5
- class ContentDatastream < ActiveFedora::File
6
- include Hydra::Derivatives::ExtractMetadata
7
- end
8
-
9
5
  class GenericFile < ActiveFedora::Base
10
6
  include Hydra::Derivatives
11
7
  contains 'characterization', class_name: 'ActiveFedora::SimpleDatastream' do |m|
@@ -13,62 +9,65 @@ describe "Transcoder" do
13
9
  m.field "flag_as", :string
14
10
  end
15
11
 
16
- has_attributes :mime_type_from_fits, :flag_as, datastream: :characterization, multiple: false
17
- contains 'original_file', class_name: 'ContentDatastream'
12
+ property :mime_type_from_fits, delegate_to: :characterization, multiple: false
13
+ property :flag_as, delegate_to: :characterization, multiple: false
14
+ contains 'original_file'
18
15
 
19
- makes_derivatives do |obj|
20
- case obj.mime_type_from_fits
16
+ def create_derivatives(filename)
17
+ case mime_type_from_fits
21
18
  when 'application/pdf'
22
- obj.transform_file :original_file, { thumb: '100x100>' }
19
+ PdfDerivatives.create(self, source: :original_file,
20
+ outputs: [{ label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" }])
21
+ FullTextExtract.create(self, source: :original_file, outputs: [{ url: "#{uri}/fulltext" }])
23
22
  when 'audio/wav'
24
- obj.transform_file :original_file, { mp3: { format: 'mp3' }, ogg: { format: 'ogg'} }, processor: :audio
23
+ AudioDerivatives.create(self, source: :original_file, outputs: [{ label: :mp3, format: 'mp3', url: "#{uri}/mp3" }, { label: :ogg, format: 'ogg', url: "#{uri}/ogg" }])
25
24
  when 'video/avi'
26
- obj.transform_file :original_file, { mp4: { format: 'mp4' }, webm: { format: 'webm'}, thumbnail: { format: 'jpg', datastream: 'thumbnail' } }, processor: :video
25
+ VideoDerivatives.create(self, source: :original_file,
26
+ outputs: [
27
+ { label: :mp4, format: 'mp4', url: "#{uri}/original_file_mp4" },
28
+ { label: :webm, format: 'webm', url: "#{uri}/original_file_webm" },
29
+ { label: :thumbnail, format: 'jpg', url: "#{uri}/thumbnail" }])
27
30
  when 'image/png', 'image/jpg'
28
- obj.transform_file :original_file, { medium: "300x300>", thumb: "100x100>", access: { format: 'jpg', datastream: 'access'} }
31
+ ImageDerivatives.create(self, source: :original_file,
32
+ outputs: [
33
+ { label: :medium, size: "300x300>", url: "#{uri}/original_file_medium" },
34
+ { label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" },
35
+ { label: :access, url: "#{uri}/access", format: 'jpg' },
36
+ ])
29
37
  when 'application/vnd.ms-powerpoint'
30
- obj.transform_file :original_file, { preservation: { format: 'pptx'}, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
38
+ DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'pptx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
31
39
  when 'text/rtf'
32
- obj.transform_file :original_file, { preservation: { format: 'odf' }, access: { format: 'pdf' }, thumbnail: { format: 'jpg' } }, processor: 'document'
40
+ DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'odf' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
33
41
  when 'application/msword'
34
- obj.transform_file :original_file, { access: { format: 'pdf' }, preservation: { format: 'docx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
42
+ DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'docx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
35
43
  when 'application/vnd.ms-excel'
36
- obj.transform_file :original_file, { access: { format: 'pdf' }, preservation: { format: 'xslx' }, thumbnail: { format: 'jpg' } }, processor: 'document'
44
+ DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'xslx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
37
45
  when 'image/tiff'
38
- obj.transform_file :original_file, {
39
- resized: { recipe: :default, resize: "600x600>", datastream: 'resized' },
40
- config_lookup: { recipe: :default, datastream: 'config_lookup' },
41
- string_recipe: { recipe: '-quiet', datastream: 'string_recipe' },
42
- diy: { }
43
- }, processor: 'jpeg2k_image'
46
+ Jpeg2kImageDerivatives.create(self, source: :original_file, outputs: [
47
+ { label: :resized, recipe: :default, resize: "600x600>", processor: 'jpeg2k_image', url: "#{uri}/resized" },
48
+ { label: :config_lookup, recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" },
49
+ { label: :string_recipe, recipe: '-quiet', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" },
50
+ { label: :diy, processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }
51
+ ])
44
52
  when 'image/x-adobe-dng'
45
- obj.transform_file :original_file,
46
- {
47
- access: { size: "300x300>", format: "jpg", datastream: "access" },
48
- thumb: { size: "100x100>", format: "jpg", datastream: "thumb" }
49
- }, processor: :raw_image
53
+ ImageDerivatives.create(self, source: :original_file, outputs: [
54
+ { label: :access, size: "300x300>", format: 'jpg', processor: :raw_image },
55
+ { label: :thumb, size: "100x100>", format: 'jpg', processor: :raw_image }
56
+ ])
50
57
  end
51
58
  end
52
-
53
- makes_derivatives :generate_special_derivatives
54
-
55
- def generate_special_derivatives
56
- if flag_as == "special" && mime_type_from_fits == 'image/png'
57
- transform_file :original_file, { medium: { size: "200x300>", datastream: 'special_ds' } }
58
- end
59
- end
60
59
  end
61
60
  end
62
61
 
63
62
  after(:all) do
64
63
  Object.send(:remove_const, :GenericFile);
65
- Object.send(:remove_const, :ContentDatastream);
66
64
  end
67
65
 
68
66
  describe "with an attached image" do
69
- let(:attachment) { File.open(File.expand_path('../../fixtures/world.png', __FILE__))}
67
+ let(:filename) { File.expand_path('../../fixtures/world.png', __FILE__) }
68
+ let(:attachment) { File.open(filename) }
70
69
  let(:file) do
71
- GenericFile.new(mime_type_from_fits: 'image/png').tap do |f|
70
+ GenericFile.new(mime_type_from_fits: 'image/png') do |f|
72
71
  f.original_file.content = attachment
73
72
  f.save!
74
73
  end
@@ -76,7 +75,8 @@ describe "Transcoder" do
76
75
 
77
76
  it "should transcode" do
78
77
  expect(file.attached_files.key?('original_file_medium')).to be_falsey
79
- file.create_derivatives
78
+ file.create_derivatives(filename)
79
+ file.reload
80
80
  expect(file.attached_files['original_file_medium']).to have_content
81
81
  expect(file.attached_files['original_file_medium'].mime_type).to eq('image/png')
82
82
  expect(file.attached_files['original_file_thumb']).to have_content
@@ -88,7 +88,8 @@ describe "Transcoder" do
88
88
  end
89
89
 
90
90
  describe "with an attached RAW image", unless: $in_travis do
91
- let(:attachment) { File.open(File.expand_path('../../fixtures/test.dng', __FILE__))}
91
+ let(:filename) { File.expand_path('../../fixtures/test.dng', __FILE__) }
92
+ let(:attachment) { File.open(filename) }
92
93
  let(:file) do
93
94
  GenericFile.new(mime_type_from_fits: 'image/x-adobe-dng') do |f|
94
95
  f.original_file.content = attachment
@@ -101,7 +102,7 @@ describe "Transcoder" do
101
102
  expect(file.attached_files.key?('access')).to be_falsey
102
103
  expect(file.attached_files.key?('thumb')).to be_falsey
103
104
 
104
- file.create_derivatives
105
+ file.create_derivatives(filename)
105
106
  expect(file.attached_files['access']).to have_content
106
107
  expect(file.attached_files['access'].mime_type).to eq('image/jpeg')
107
108
  expect(file.attached_files['thumb']).to have_content
@@ -109,24 +110,36 @@ describe "Transcoder" do
109
110
  end
110
111
  end
111
112
 
112
- describe "with an attached pdf" do
113
- let(:attachment) { File.open(File.expand_path('../../fixtures/test.pdf', __FILE__))}
114
- let(:file) { GenericFile.new(mime_type_from_fits: 'application/pdf').tap { |t| t.original_file.content = attachment; t.save } }
113
+ describe "with an attached pdf", unless: $in_travis do
114
+ let(:filename) { File.expand_path('../../fixtures/test.pdf', __FILE__) }
115
+ let(:attachment) { File.open(filename) }
116
+ let(:file) do
117
+ GenericFile.new(mime_type_from_fits: 'application/pdf') do |t|
118
+ t.original_file.content = attachment
119
+ t.original_file.mime_type = 'application/pdf'
120
+ t.save
121
+ end
122
+ end
115
123
 
116
124
  it "should transcode" do
117
125
  expect(file.attached_files.key?('original_file_thumb')).to be_falsey
118
- file.create_derivatives
126
+ file.create_derivatives(filename)
127
+ file.reload
119
128
  expect(file.attached_files['original_file_thumb']).to have_content
120
129
  expect(file.attached_files['original_file_thumb'].mime_type).to eq('image/png')
130
+ expect(file.attached_files['fulltext'].content).to match /This PDF file was created using CutePDF/
131
+ expect(file.attached_files['fulltext'].mime_type).to eq 'text/plain'
121
132
  end
122
133
  end
123
134
 
124
- describe "with an attached audio", unless: ENV['TRAVIS'] == 'true' do
125
- let(:attachment) { File.open(File.expand_path('../../fixtures/piano_note.wav', __FILE__))}
135
+ describe "with an attached audio", unless: $in_travis do
136
+ let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
137
+ let(:attachment) { File.open(filename) }
126
138
  let(:file) { GenericFile.new(mime_type_from_fits: 'audio/wav').tap { |t| t.original_file.content = attachment; t.save } }
127
139
 
128
140
  it "should transcode" do
129
- file.create_derivatives
141
+ file.create_derivatives(filename)
142
+ file.reload
130
143
  expect(file.attached_files['original_file_mp3']).to have_content
131
144
  expect(file.attached_files['original_file_mp3'].mime_type).to eq('audio/mpeg')
132
145
  expect(file.attached_files['original_file_ogg']).to have_content
@@ -134,8 +147,9 @@ describe "Transcoder" do
134
147
  end
135
148
  end
136
149
 
137
- describe "when the source datastrem has an unknown mime_type", unless: ENV['TRAVIS'] == 'true' do
138
- let(:attachment) { File.open(File.expand_path('../../fixtures/piano_note.wav', __FILE__))}
150
+ describe "when the source datastrem has an unknown mime_type", unless: $in_travis do
151
+ let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
152
+ let(:attachment) { File.open(filename) }
139
153
  let(:file) do
140
154
  GenericFile.new(mime_type_from_fits: 'audio/wav').tap do |t|
141
155
  t.original_file.content = attachment;
@@ -146,18 +160,26 @@ describe "Transcoder" do
146
160
 
147
161
  it "should transcode" do
148
162
  allow_any_instance_of(::Logger).to receive(:warn)
149
- file.create_derivatives
163
+ file.create_derivatives(filename)
164
+ file.reload
150
165
  expect(file.attached_files['original_file_mp3']).to have_content
151
166
  expect(file.attached_files['original_file_mp3'].mime_type).to eq('audio/mpeg')
152
167
  end
153
168
  end
154
169
 
155
- describe "with an attached video", unless: ENV['TRAVIS'] == 'true' do
156
- let(:attachment) { File.open(File.expand_path('../../fixtures/countdown.avi', __FILE__))}
157
- let(:file) { GenericFile.new(mime_type_from_fits: 'video/avi').tap { |t| t.original_file.content = attachment; t.save } }
170
+ describe "with an attached video", unless: $in_travis do
171
+ let(:filename) { File.expand_path('../../fixtures/countdown.avi', __FILE__) }
172
+ let(:attachment) { File.open(filename) }
173
+ let(:file) do
174
+ GenericFile.create(mime_type_from_fits: 'video/avi') do |t|
175
+ t.original_file.content = attachment
176
+ t.original_file.mime_type = 'video/msvideo'
177
+ end
178
+ end
158
179
 
159
180
  it "should transcode" do
160
- file.create_derivatives
181
+ file.create_derivatives(filename)
182
+ file.reload
161
183
  expect(file.attached_files['original_file_mp4']).to have_content
162
184
  expect(file.attached_files['original_file_mp4'].mime_type).to eq('video/mp4')
163
185
  expect(file.attached_files['original_file_webm']).to have_content
@@ -168,37 +190,30 @@ describe "Transcoder" do
168
190
 
169
191
  context "and the timeout is set" do
170
192
  before do
171
- Hydra::Derivatives::Video::Processor.timeout = 1 # one second
193
+ Hydra::Derivatives::Processors::Video::Processor.timeout = 0.2 # 200ms
172
194
  end
173
195
  after do
174
- Hydra::Derivatives::Video::Processor.timeout = nil # clear timeout
196
+ Hydra::Derivatives::Processors::Video::Processor.timeout = nil # clear timeout
175
197
  end
176
198
 
177
199
  it "should raise a timeout" do
178
- expect { file.create_derivatives }.to raise_error Hydra::Derivatives::TimeoutError
200
+ expect { file.create_derivatives(filename) }.to raise_error Hydra::Derivatives::TimeoutError
179
201
  end
180
202
  end
181
203
  end
182
204
 
183
- describe "using callback methods" do
184
- let(:attachment) { File.open(File.expand_path('../../fixtures/world.png', __FILE__))}
185
- let(:file) { GenericFile.new(mime_type_from_fits: 'image/png', flag_as: "special").tap { |t| t.original_file.content = attachment; t.save } }
186
-
187
- it "should transcode" do
188
- expect(file.attached_files.key?('special_ds')).to be_falsey
189
- file.create_derivatives
190
- expect(file.attached_files['special_ds']).to have_content
191
- expect(file.attached_files['special_ds'].mime_type).to eq('image/png')
192
- expect(file.attached_files['special_ds']).to have_content
205
+ describe "with an attached Powerpoint", unless: $in_travis do
206
+ let(:filename) { File.expand_path('../../fixtures/FlashPix.ppt', __FILE__) }
207
+ let(:attachment) { File.open(filename) }
208
+ let(:file) do
209
+ GenericFile.create(mime_type_from_fits: 'application/vnd.ms-powerpoint') do |t|
210
+ t.original_file.content = attachment
211
+ end
193
212
  end
194
- end
195
-
196
- describe "with an attached Powerpoint", unless: ENV['TRAVIS'] == 'true' do
197
- let(:attachment) { File.open(File.expand_path('../../fixtures/FlashPix.ppt', __FILE__))}
198
- let(:file) { GenericFile.new(mime_type_from_fits: 'application/vnd.ms-powerpoint').tap { |t| t.original_file.content = attachment; t.save } }
199
213
 
200
214
  it "should transcode" do
201
- file.create_derivatives
215
+ file.create_derivatives(filename)
216
+ file.reload
202
217
  expect(file.attached_files['original_file_thumbnail']).to have_content
203
218
  expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
204
219
  expect(file.attached_files['original_file_access']).to have_content
@@ -208,12 +223,14 @@ describe "Transcoder" do
208
223
  end
209
224
  end
210
225
 
211
- describe "with an attached rich text format", unless: ENV['TRAVIS'] == 'true' do
212
- let(:attachment) { File.open(File.expand_path('../../fixtures/sample.rtf', __FILE__))}
226
+ describe "with an attached rich text format", unless: $in_travis do
227
+ let(:filename) { File.expand_path('../../fixtures/sample.rtf', __FILE__) }
228
+ let(:attachment) { File.open(filename) }
213
229
  let(:file) { GenericFile.new(mime_type_from_fits: 'text/rtf').tap { |t| t.original_file.content = attachment; t.save } }
214
230
 
215
231
  it "should transcode" do
216
- file.create_derivatives
232
+ file.create_derivatives(filename)
233
+ file.reload
217
234
  expect(file.attached_files['original_file_thumbnail']).to have_content
218
235
  expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
219
236
  expect(file.attached_files['original_file_access']).to have_content
@@ -223,12 +240,14 @@ describe "Transcoder" do
223
240
  end
224
241
  end
225
242
 
226
- describe "with an attached word doc format", unless: ENV['TRAVIS'] == 'true' do
227
- let(:attachment) { File.open(File.expand_path('../../fixtures/test.doc', __FILE__))}
243
+ describe "with an attached word doc format", unless: $in_travis do
244
+ let(:filename) { File.expand_path('../../fixtures/test.doc', __FILE__) }
245
+ let(:attachment) { File.open(filename) }
228
246
  let(:file) { GenericFile.new(mime_type_from_fits: 'application/msword').tap { |t| t.original_file.content = attachment; t.save } }
229
247
 
230
248
  it "should transcode" do
231
- file.create_derivatives
249
+ file.create_derivatives(filename)
250
+ file.reload
232
251
  expect(file.attached_files['original_file_thumbnail']).to have_content
233
252
  expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
234
253
  expect(file.attached_files['original_file_access']).to have_content
@@ -238,12 +257,14 @@ describe "Transcoder" do
238
257
  end
239
258
  end
240
259
 
241
- describe "with an attached excel format", unless: ENV['TRAVIS'] == 'true' do
242
- let(:attachment) { File.open(File.expand_path('../../fixtures/test.xls', __FILE__))}
260
+ describe "with an attached excel format", unless: $in_travis do
261
+ let(:filename) { File.expand_path('../../fixtures/test.xls', __FILE__) }
262
+ let(:attachment) { File.open(filename)}
243
263
  let(:file) { GenericFile.new(mime_type_from_fits: 'application/vnd.ms-excel').tap { |t| t.original_file.content = attachment; t.save } }
244
264
 
245
265
  it "should transcode" do
246
- file.create_derivatives
266
+ file.create_derivatives(filename)
267
+ file.reload
247
268
  expect(file.attached_files['original_file_thumbnail']).to have_content
248
269
  expect(file.attached_files['original_file_thumbnail'].mime_type).to eq('image/jpeg')
249
270
  expect(file.attached_files['original_file_access']).to have_content
@@ -253,11 +274,13 @@ describe "Transcoder" do
253
274
  end
254
275
  end
255
276
 
256
- describe "with an attached tiff", unless: ENV['TRAVIS'] == 'true' do
257
- let(:attachment) { File.open(File.expand_path('../../fixtures/test.tif', __FILE__))}
277
+ describe "with an attached tiff", unless: $in_travis do
278
+ let(:filename) { File.expand_path('../../fixtures/test.tif', __FILE__) }
279
+ let(:attachment) { File.open(filename)}
258
280
  let(:file) { GenericFile.new(mime_type_from_fits: 'image/tiff').tap { |t| t.original_file.content = attachment; t.save } }
259
281
  it "should transcode" do
260
- file.create_derivatives
282
+ file.create_derivatives(filename)
283
+ file.reload
261
284
  expect(file.attached_files['original_file_diy']).to have_content
262
285
  expect(file.attached_files['original_file_diy'].mime_type).to eq('image/jp2')
263
286
  expect(file.attached_files['config_lookup']).to have_content