hydra-derivatives 3.1.3 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +66 -0
  3. data/.rubocop_todo.yml +29 -0
  4. data/Gemfile +2 -0
  5. data/Rakefile +19 -4
  6. data/VERSION +1 -1
  7. data/lib/hydra/derivatives.rb +5 -5
  8. data/lib/hydra/derivatives/config.rb +7 -8
  9. data/lib/hydra/derivatives/logger.rb +2 -5
  10. data/lib/hydra/derivatives/processors/audio.rb +0 -1
  11. data/lib/hydra/derivatives/processors/document.rb +33 -18
  12. data/lib/hydra/derivatives/processors/ffmpeg.rb +2 -3
  13. data/lib/hydra/derivatives/processors/full_text.rb +1 -1
  14. data/lib/hydra/derivatives/processors/image.rb +39 -36
  15. data/lib/hydra/derivatives/processors/jpeg2k_image.rb +91 -89
  16. data/lib/hydra/derivatives/processors/processor.rb +1 -1
  17. data/lib/hydra/derivatives/processors/raw_image.rb +25 -25
  18. data/lib/hydra/derivatives/processors/shell_based_processor.rb +24 -32
  19. data/lib/hydra/derivatives/processors/video.rb +0 -2
  20. data/lib/hydra/derivatives/processors/video/config.rb +2 -4
  21. data/lib/hydra/derivatives/processors/video/processor.rb +24 -24
  22. data/lib/hydra/derivatives/runners/full_text_extract.rb +0 -1
  23. data/lib/hydra/derivatives/runners/image_derivatives.rb +0 -1
  24. data/lib/hydra/derivatives/runners/runner.rb +4 -7
  25. data/lib/hydra/derivatives/services/persist_basic_contained_output_file_service.rb +0 -1
  26. data/lib/hydra/derivatives/services/persist_output_file_service.rb +11 -13
  27. data/lib/hydra/derivatives/services/retrieve_source_file_service.rb +0 -1
  28. data/lib/hydra/derivatives/services/tempfile_service.rb +4 -5
  29. data/spec/processors/document_spec.rb +41 -0
  30. data/spec/processors/{full_text.rb → full_text_spec.rb} +10 -19
  31. data/spec/processors/image_spec.rb +28 -21
  32. data/spec/processors/jpeg2k_spec.rb +1 -2
  33. data/spec/processors/processor_spec.rb +2 -3
  34. data/spec/processors/shell_based_processor_spec.rb +1 -1
  35. data/spec/processors/video_spec.rb +4 -4
  36. data/spec/services/audio_derivatives_spec.rb +5 -5
  37. data/spec/services/persist_basic_contained_output_file_service_spec.rb +4 -6
  38. data/spec/services/retrieve_source_file_service_spec.rb +7 -7
  39. data/spec/services/tempfile_service_spec.rb +4 -2
  40. data/spec/spec_helper.rb +5 -3
  41. data/spec/units/config_spec.rb +5 -7
  42. data/spec/units/derivatives_spec.rb +8 -21
  43. data/spec/units/logger_spec.rb +7 -10
  44. data/spec/units/transcoding_spec.rb +111 -61
  45. metadata +9 -5
@@ -1,46 +1,53 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::Processors::Image do
4
- let(:output_file) { double }
5
- let(:file_name) { double }
6
-
4
+ let(:file_name) { "file_name" }
7
5
  subject { described_class.new(file_name, directives) }
8
6
 
9
- before { allow(subject).to receive(:output_file).with(file_name).and_return(output_file) }
7
+ context "when arguments are passed as a hash" do
8
+ let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75 } }
9
+ let(:mock_transformer) { double("MockTransformer") }
10
10
 
11
- describe "when arguments are passed as a hash" do
12
- let(:directives) { { label: :thumb, size: "200x300>", format: 'png', quality: 75 } }
13
- let(:file_name) { 'thumbnail' }
11
+ before do
12
+ allow(subject).to receive(:load_image_transformer).and_return(mock_transformer)
13
+ allow(subject).to receive(:write_image).with(mock_transformer)
14
+ end
14
15
 
15
16
  it "uses the specified size and name and quality" do
16
- expect(subject).to receive(:create_resized_image).with(file_name, "200x300>", 'png', 75)
17
+ expect(mock_transformer).to receive(:flatten)
18
+ expect(mock_transformer).to receive(:resize).with("200x300>")
19
+ expect(mock_transformer).to receive(:format).with("png")
20
+ expect(mock_transformer).to receive(:quality).with("75")
17
21
  subject.process
18
22
  end
19
23
  end
20
24
 
21
- describe 'timeout' do
22
- let(:directives) { { thumb: "100x100>" } }
23
- let(:file_name) { 'content_thumb' }
24
-
25
- before do
26
- allow(subject).to receive(:create_resized_image).with("100x100>", 'png')
27
- end
25
+ describe "#process" do
26
+ let(:directives) { { size: "100x100>", format: "png" } }
28
27
 
29
- context 'when set' do
28
+ context "when a timeout is set" do
30
29
  before do
31
30
  subject.timeout = 0.1
32
- allow_any_instance_of(described_class).to receive(:process_without_timeout) { sleep 0.2 }
31
+ allow(subject).to receive(:create_resized_image) { sleep 0.2 }
33
32
  end
34
- it 'raises a timeout exception' do
33
+ it "raises a timeout exception" do
35
34
  expect { subject.process }.to raise_error Hydra::Derivatives::TimeoutError
36
35
  end
37
36
  end
38
37
 
39
- context 'when not set' do
38
+ context "when not set" do
40
39
  before { subject.timeout = nil }
41
- it 'processes without a timeout' do
40
+ it "processes without a timeout" do
42
41
  expect(subject).to receive(:process_with_timeout).never
43
- expect(subject).to receive(:process_without_timeout).once
42
+ expect(subject).to receive(:create_resized_image).once
43
+ subject.process
44
+ end
45
+ end
46
+
47
+ context "when running the complete command", unless: in_travis? do
48
+ let(:file_name) { File.join(fixture_path, "test.tif") }
49
+ it "converts the image" do
50
+ expect(Hydra::Derivatives::PersistBasicContainedOutputFileService).to receive(:call).with(kind_of(StringIO), directives)
44
51
  subject.process
45
52
  end
46
53
  end
@@ -16,12 +16,11 @@ describe Hydra::Derivatives::Processors::Jpeg2kImage do
16
16
  calc = described_class.layer_rates(layers, compression_num)
17
17
  expect(calc).to eq("2.4,1.48331273,0.91675694,0.56659885,0.3501847,0.21643059,0.13376427,0.0826726")
18
18
  end
19
-
20
19
  end
21
20
 
22
21
  describe ".srgb_profile_path" do
23
22
  it "exists" do
24
- expect(File.exists?(described_class.srgb_profile_path)).to eq true
23
+ expect(File.exist?(described_class.srgb_profile_path)).to eq true
25
24
  end
26
25
  end
27
26
 
@@ -1,13 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::Processors::Processor do
4
-
5
- let(:object) { "Fake Object" }
4
+ let(:object) { "Fake Object" }
6
5
  let(:source_name) { 'content' }
7
6
  let(:directives) { { thumb: "100x100>" } }
8
7
  let(:file_path) { double }
9
8
 
10
- subject { described_class.new(file_path, directives)}
9
+ subject { described_class.new(file_path, directives) }
11
10
 
12
11
  describe "output_file_service" do
13
12
  let(:custom_output_file_service) { "fake service" }
@@ -9,7 +9,7 @@ describe Hydra::Derivatives::Processors::ShellBasedProcessor do
9
9
 
10
10
  after { Object.send(:remove_const, :TestProcessor) }
11
11
 
12
- let (:processor) { TestProcessor.new }
12
+ let(:processor) { TestProcessor.new }
13
13
 
14
14
  describe "options_for" do
15
15
  it "returns a hash" do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::Processors::Video::Processor do
4
4
  let(:file_name) { 'foo/bar.mov' }
5
- subject { described_class.new(file_name, directives)}
5
+ subject { described_class.new(file_name, directives) }
6
6
 
7
7
  describe ".config" do
8
8
  before do
@@ -13,8 +13,8 @@ describe Hydra::Derivatives::Processors::Video::Processor do
13
13
  after { described_class.config = @original_config }
14
14
  let(:directives) { { label: :thumb, format: "mp4", url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
15
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 => "" })
16
+ it "is 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
18
  subject.process
19
19
  end
20
20
  end
@@ -24,7 +24,7 @@ describe Hydra::Derivatives::Processors::Video::Processor do
24
24
  let(:directives) { { label: :thumb, format: 'webm', url: 'http://localhost:8983/fedora/rest/dev/1234/thumbnail' } }
25
25
 
26
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 => "" })
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
28
  subject.process
29
29
  end
30
30
  end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  describe Hydra::Derivatives::AudioDerivatives do
4
4
  describe ".create" do
5
5
  let(:filename) { 'spec/fixtures/piano_note.wav' }
6
- context "with a filename", unless: $in_travis do
6
+ context "with a filename", unless: in_travis? do
7
7
  before do
8
8
  class LocalFileService
9
- def self.call(file_name, options, &block)
9
+ def self.call(file_name, _options, &_block)
10
10
  yield File.open(file_name)
11
11
  end
12
12
  end
@@ -27,7 +27,7 @@ describe Hydra::Derivatives::AudioDerivatives do
27
27
  end
28
28
 
29
29
  context "with an object" do
30
- let(:object) { "Fake Object" }
30
+ let(:object) { "Fake Object" }
31
31
  let(:source_name) { :content }
32
32
  let(:file) { double("the file") }
33
33
 
@@ -49,8 +49,8 @@ describe Hydra::Derivatives::AudioDerivatives do
49
49
  subject { described_class }
50
50
 
51
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 })
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
54
  end
55
55
  end
56
56
 
@@ -1,29 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::PersistBasicContainedOutputFileService do
4
-
5
4
  before(:all) do
6
5
  class BasicContainerObject < ActiveFedora::Base
7
6
  has_subresource "the_derivative_name"
8
7
  end
9
8
  end
10
9
 
11
- let(:object) { BasicContainerObject.new }
10
+ let(:object) { BasicContainerObject.new }
12
11
  let(:file_path) { File.join(fixture_path, 'test.tif') }
13
- let(:file) { File.new(file_path)}
12
+ let(:file) { File.new(file_path) }
14
13
  let(:destination_name) { 'the_derivative_name' }
15
14
 
16
15
  # alas, we have to support this as the default because all legacy code (and fedora 3 systems) created basic contained files
17
16
  # The new signature does not have a destination_name option. There is a default string that will get applied, but his might
18
17
  # not be sufficient.
19
18
  context "when file is basic contained (default assumption)" do
20
- let(:object) { BasicContainerObject.create }
19
+ let(:object) { BasicContainerObject.create }
21
20
  let(:stream) { StringIO.new("fake file content") }
22
21
  it "persists the file to the specified destination on the given object" do
23
- described_class.call(stream, { format: 'jpg', url: "#{object.uri}/the_derivative_name" })
22
+ described_class.call(stream, format: 'jpg', url: "#{object.uri}/the_derivative_name")
24
23
  expect(object.send(destination_name.to_sym).content).to eq("fake file content")
25
24
  expect(object.send(destination_name.to_sym).content_changed?).to eq false
26
25
  end
27
26
  end
28
-
29
27
  end
@@ -15,13 +15,13 @@ describe Hydra::Derivatives::RetrieveSourceFileService do
15
15
 
16
16
  class DirectContainerObject < ActiveFedora::Base
17
17
  directly_contains :files, has_member_relation: ::RDF::URI("http://pcdm.org/use#hasFile"),
18
- class_name: "FileWithMetadata"
18
+ class_name: "FileWithMetadata"
19
19
  directly_contains_one :directly_contained_file, through: :files, type: ::RDF::URI("http://pcdm.org/use#OriginalFile")
20
20
  end
21
21
  end
22
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 }
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
25
  let(:content) { "fake file content (basic container)" }
26
26
  let(:source_name) { 'contained_file' }
27
27
 
@@ -35,24 +35,24 @@ describe Hydra::Derivatives::RetrieveSourceFileService do
35
35
  end
36
36
 
37
37
  it "persists the file to the specified destination on the given object" do
38
- described_class.call(object, { source: source_name }) do |f|
38
+ described_class.call(object, source: source_name) do |f|
39
39
  expect(f.read).to eq(object.contained_file.content)
40
40
  end
41
41
  end
42
42
  end
43
43
 
44
- context "when file is directly contained" do # direct containers are more efficient, but most legacy code will have indirect containers
44
+ context "when file is directly contained" do # direct containers are more efficient, but most legacy code will have indirect containers
45
45
  let(:object) { DirectContainerObject.new }
46
46
  let(:content) { "fake file content (direct container)" }
47
47
  let(:source_name) { 'directly_contained_file' }
48
48
 
49
49
  before do
50
- object.save # can't build directly contained objects without saving the parent first
50
+ object.save # can't build directly contained objects without saving the parent first
51
51
  object.build_directly_contained_file
52
52
  object.directly_contained_file.content = content
53
53
  end
54
54
  it "retrieves the file from the specified location on the given object" do
55
- described_class.call(object, { source: source_name }) do |f|
55
+ described_class.call(object, source: source_name) do |f|
56
56
  expect(f.read).to eq(object.directly_contained_file.content)
57
57
  end
58
58
  end
@@ -11,7 +11,9 @@ describe Hydra::Derivatives::TempfileService do
11
11
  @uri = 'http://example.com/pid/123'
12
12
  end
13
13
 
14
- def has_content?; content.present?; end
14
+ def has_content?
15
+ content.present?
16
+ end
15
17
  end
16
18
  end
17
19
 
@@ -19,7 +21,7 @@ describe Hydra::Derivatives::TempfileService do
19
21
 
20
22
  let(:file) { class_with_metadata_extraction.new(initialization_options) }
21
23
 
22
- subject { Hydra::Derivatives::TempfileService.new(file) }
24
+ subject { described_class.new(file) }
23
25
  context '#tempfile' do
24
26
  it 'has a method called to_tempfile' do
25
27
  expect { |b| subject.tempfile(&b) }.to yield_with_args(Tempfile)
@@ -1,7 +1,7 @@
1
1
  ENV['environment'] ||= 'test'
2
2
  # - RSpec adds ./lib to the $LOAD_PATH
3
3
  require 'hydra/derivatives'
4
- #Resque.inline = Rails.env.test?
4
+ # Resque.inline = Rails.env.test?
5
5
  require 'byebug' unless ENV['TRAVIS']
6
6
 
7
7
  require 'active_fedora/cleaner'
@@ -19,8 +19,10 @@ dng_format = MIME::Type.new('image/x-adobe-dng')
19
19
  dng_format.extensions = 'dng'
20
20
  MIME::Types.add(dng_format)
21
21
 
22
- $in_travis = !ENV['TRAVIS'].nil? && ENV['TRAVIS'] == 'true'
23
-
24
22
  def fixture_path
25
23
  File.expand_path("../fixtures", __FILE__)
26
24
  end
25
+
26
+ def in_travis?
27
+ !ENV['TRAVIS'].nil? && ENV['TRAVIS'] == 'true'
28
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe "the configuration" do
4
4
  subject { Hydra::Derivatives }
5
5
 
6
- it "should have some configuration defaults" do
6
+ it "has some configuration defaults" do
7
7
  expect(subject.ffmpeg_path).to eq('ffmpeg')
8
8
  expect(subject.enable_ffmpeg).to be true
9
9
  expect(subject.libreoffice_path).to eq('soffice')
@@ -14,28 +14,27 @@ describe "the configuration" do
14
14
  expect(subject.source_file_service).to eq(Hydra::Derivatives::RetrieveSourceFileService)
15
15
  end
16
16
 
17
- it "should let you change the configuration" do
17
+ it "lets you change the configuration" do
18
18
  subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
19
19
  expect(subject.ffmpeg_path).to eq('/usr/local/ffmpeg-1.0/bin/ffmpeg')
20
20
 
21
21
  subject.kdu_compress_path = '/opt/local/bin/kdu_compress'
22
22
  expect(subject.kdu_compress_path).to eq('/opt/local/bin/kdu_compress')
23
-
24
23
  end
25
24
 
26
- it "should let you set a custom output file service" do
25
+ it "lets you set a custom output file service" do
27
26
  output_file_service = double("MyOutputFileService")
28
27
  subject.output_file_service = output_file_service
29
28
  expect(subject.output_file_service).to eq(output_file_service)
30
29
  end
31
30
 
32
- it "should let you set a custom source file service" do
31
+ it "lets you set a custom source file service" do
33
32
  source_file_service = double("MyRetriveSourceFileService")
34
33
  subject.source_file_service = source_file_service
35
34
  expect(subject.source_file_service).to eq(source_file_service)
36
35
  end
37
36
 
38
- it "should let you reset the configuration" do
37
+ it "lets you reset the configuration" do
39
38
  subject.ffmpeg_path = '/usr/local/ffmpeg-1.0/bin/ffmpeg'
40
39
  subject.reset_config!
41
40
  expect(subject.ffmpeg_path).to eq('ffmpeg')
@@ -44,5 +43,4 @@ describe "the configuration" do
44
43
  subject.reset_config!
45
44
  expect(subject.kdu_compress_path).to eq('kdu_compress')
46
45
  end
47
-
48
46
  end
@@ -5,41 +5,28 @@ describe Hydra::Derivatives do
5
5
  class CustomFile < ActiveFedora::Base
6
6
  include Hydra::Derivatives
7
7
  end
8
- class CustomProcessor < Hydra::Derivatives::Processors::Processor
9
- end
10
- class CustomSourceFileService
11
- end
12
- class CustomOutputFileService
13
- end
14
8
  end
15
9
 
16
- after(:all) do
17
- Object.send(:remove_const, :CustomFile)
18
- Object.send(:remove_const, :CustomProcessor)
19
- Object.send(:remove_const, :CustomSourceFileService)
20
- Object.send(:remove_const, :CustomOutputFileService)
21
- end
10
+ after(:all) { Object.send(:remove_const, :CustomFile) }
22
11
 
23
12
  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)
27
- end
28
- subject { Class.new { include Hydra::Derivatives } }
13
+ before { subject.source_file_service = custom_source_file_service }
29
14
 
30
15
  context "as a global configuration setting" do
16
+ let(:custom_source_file_service) { "fake service" }
17
+ subject { CustomFile }
18
+
31
19
  it "utilizes the default source file service" do
32
20
  expect(subject.source_file_service).to eq(custom_source_file_service)
33
21
  end
34
22
  end
35
23
 
36
24
  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 }
25
+ let(:custom_source_file_service) { "another fake service" }
26
+ subject { CustomFile.new }
40
27
 
41
28
  it "accepts a custom source file service as an option" do
42
- expect(subject.source_file_service).to eq(another_custom_source_file_service)
29
+ expect(subject.source_file_service).to eq(custom_source_file_service)
43
30
  end
44
31
  end
45
32
  end
@@ -1,25 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Hydra::Derivatives::Logger do
4
-
5
4
  context "with log levels" do
5
+ let(:levels) { %w(unknown fatal error warn info debug) }
6
6
 
7
- let(:levels) { ["unknown", "fatal", "error", "warn", "info", "debug"] }
8
-
9
- it "should respond successfully" do
7
+ it "responds successfully" do
10
8
  levels.each do |level|
11
- expect(Hydra::Derivatives::Logger.respond_to?(level)).to be_truthy
9
+ expect(described_class.respond_to?(level)).to be_truthy
12
10
  end
13
11
  end
14
- it "should accept messages" do
15
- expect(Hydra::Derivatives::Logger.warn("message")).to be_truthy
12
+ it "accepts messages" do
13
+ expect(described_class.warn("message")).to be_truthy
16
14
  end
17
15
  end
18
16
 
19
17
  context "with garbage" do
20
- it "should raise an error" do
21
- expect{Hydra::Derivatives::Logger.garbage}.to raise_error(NoMethodError)
18
+ it "raises an error" do
19
+ expect { described_class.garbage }.to raise_error(NoMethodError)
22
20
  end
23
21
  end
24
-
25
22
  end
@@ -1,60 +1,79 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Transcoder" do
3
+ describe "Transcoding" do
4
4
  before(:all) do
5
5
  class GenericFile < ActiveFedora::Base
6
6
  include Hydra::Derivatives
7
7
  property :mime_type_from_fits, predicate: ::RDF::URI('http://example.com/mime'), multiple: false
8
8
  has_subresource 'original_file'
9
9
 
10
- def create_derivatives(filename)
10
+ def create_derivatives(_filename)
11
11
  case mime_type_from_fits
12
12
  when 'application/pdf'
13
13
  PdfDerivatives.create(self, source: :original_file,
14
- outputs: [{ label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" }])
14
+ outputs: [{ label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" }])
15
15
  FullTextExtract.create(self, source: :original_file, outputs: [{ url: "#{uri}/fulltext" }])
16
16
  when 'audio/wav'
17
- AudioDerivatives.create(self, source: :original_file, outputs: [{ label: :mp3, format: 'mp3', url: "#{uri}/mp3" }, { label: :ogg, format: 'ogg', url: "#{uri}/ogg" }])
17
+ AudioDerivatives.create(self, source: :original_file,
18
+ outputs: [
19
+ { label: :mp3, format: 'mp3', url: "#{uri}/mp3" },
20
+ { label: :ogg, format: 'ogg', url: "#{uri}/ogg" }])
18
21
  when 'video/avi'
19
22
  VideoDerivatives.create(self, source: :original_file,
20
- outputs: [
21
- { label: :mp4, format: 'mp4', url: "#{uri}/original_file_mp4" },
22
- { label: :webm, format: 'webm', url: "#{uri}/original_file_webm" },
23
- { label: :thumbnail, format: 'jpg', url: "#{uri}/thumbnail" }])
23
+ outputs: [
24
+ { label: :mp4, format: 'mp4', url: "#{uri}/original_file_mp4" },
25
+ { label: :webm, format: 'webm', url: "#{uri}/original_file_webm" },
26
+ { label: :thumbnail, format: 'jpg', url: "#{uri}/thumbnail" }])
24
27
  when 'image/png', 'image/jpg'
25
28
  ImageDerivatives.create(self, source: :original_file,
26
29
  outputs: [
27
30
  { label: :medium, size: "300x300>", url: "#{uri}/original_file_medium" },
28
- { label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" },
29
- { label: :access, url: "#{uri}/access", format: 'jpg' },
31
+ { label: :thumb, size: "100x100>", url: "#{uri}/original_file_thumb" },
32
+ { label: :access, format: 'jpg', url: "#{uri}/access" },
30
33
  ])
31
34
  when 'application/vnd.ms-powerpoint'
32
- DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'pptx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
35
+ DocumentDerivatives.create(self, source: :original_file,
36
+ outputs: [
37
+ { label: :preservation, format: 'pptx', url: "#{uri}/original_file_preservation" },
38
+ { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
39
+ { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }])
33
40
  when 'text/rtf'
34
- DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'odf' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
41
+ DocumentDerivatives.create(self, source: :original_file,
42
+ outputs: [
43
+ { label: :preservation, format: 'odf', url: "#{uri}/original_file_preservation" },
44
+ { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
45
+ { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }])
35
46
  when 'application/msword'
36
- DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'docx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
47
+ DocumentDerivatives.create(self, source: :original_file,
48
+ outputs: [
49
+ { label: :preservation, format: 'docx', url: "#{uri}/original_file_preservation" },
50
+ { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
51
+ { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }])
37
52
  when 'application/vnd.ms-excel'
38
- DocumentDerivatives.create(self, source: :original_file, outputs: [{ label: :preservation, format: 'xslx' }, { label: :access, format: 'pdf' }, { label: :thumnail, format: 'jpg' }])
53
+ DocumentDerivatives.create(self, source: :original_file,
54
+ outputs: [
55
+ { label: :preservation, format: 'xslx', url: "#{uri}/original_file_preservation" },
56
+ { label: :access, format: 'pdf', url: "#{uri}/original_file_access" },
57
+ { label: :thumnail, format: 'jpg', url: "#{uri}/original_file_thumbnail" }])
39
58
  when 'image/tiff'
40
- Jpeg2kImageDerivatives.create(self, source: :original_file, outputs: [
41
- { label: :resized, recipe: :default, resize: "600x600>", processor: 'jpeg2k_image', url: "#{uri}/resized" },
42
- { label: :config_lookup, recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" },
43
- { label: :string_recipe, recipe: '-quiet', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" },
44
- { label: :diy, processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }
45
- ])
59
+ Jpeg2kImageDerivatives.create(self, source: :original_file,
60
+ outputs: [
61
+ { label: :resized, recipe: :default, processor: 'jpeg2k_image', resize: "600x600>", url: "#{uri}/resized" },
62
+ { label: :config_lookup, recipe: :default, processor: 'jpeg2k_image', url: "#{uri}/config_lookup" },
63
+ { label: :string_recipe, recipe: '-quiet', processor: 'jpeg2k_image', url: "#{uri}/string_recipe" },
64
+ { label: :diy, processor: 'jpeg2k_image', url: "#{uri}/original_file_diy" }])
46
65
  when 'image/x-adobe-dng'
47
- ImageDerivatives.create(self, source: :original_file, outputs: [
48
- { label: :access, size: "300x300>", format: 'jpg', processor: :raw_image },
49
- { label: :thumb, size: "100x100>", format: 'jpg', processor: :raw_image }
50
- ])
51
- end
66
+ ImageDerivatives.create(self, source: :original_file,
67
+ outputs: [
68
+ { label: :access, size: "300x300>", format: 'jpg', processor: :raw_image },
69
+ { label: :thumb, size: "100x100>", format: 'jpg', processor: :raw_image }])
70
+ end
52
71
  end
53
72
  end
54
73
  end
55
74
 
56
75
  after(:all) do
57
- Object.send(:remove_const, :GenericFile);
76
+ Object.send(:remove_const, :GenericFile)
58
77
  end
59
78
 
60
79
  describe "with an attached image" do
@@ -67,7 +86,7 @@ describe "Transcoder" do
67
86
  end
68
87
  end
69
88
 
70
- it "should transcode" do
89
+ it "transcodes" do
71
90
  expect(file.attached_files.key?('original_file_medium')).to be_falsey
72
91
  file.create_derivatives(filename)
73
92
  file.reload
@@ -81,7 +100,7 @@ describe "Transcoder" do
81
100
  end
82
101
  end
83
102
 
84
- describe "with an attached RAW image", unless: $in_travis do
103
+ describe "with an attached RAW image", unless: in_travis? do
85
104
  let(:filename) { File.expand_path('../../fixtures/test.dng', __FILE__) }
86
105
  let(:attachment) { File.open(filename) }
87
106
  let(:file) do
@@ -92,8 +111,8 @@ describe "Transcoder" do
92
111
  end
93
112
  end
94
113
 
95
- it "should transcode" do
96
- expect(file.attached_files.key?('access')).to be_falsey
114
+ it "transcodes" do
115
+ expect(file.attached_files.key?('access')).to be_falsey
97
116
  expect(file.attached_files.key?('thumb')).to be_falsey
98
117
 
99
118
  file.create_derivatives(filename)
@@ -104,7 +123,7 @@ describe "Transcoder" do
104
123
  end
105
124
  end
106
125
 
107
- describe "with an attached pdf", unless: $in_travis do
126
+ describe "with an attached pdf", unless: in_travis? do
108
127
  let(:filename) { File.expand_path('../../fixtures/test.pdf', __FILE__) }
109
128
  let(:attachment) { File.open(filename) }
110
129
  let(:file) do
@@ -115,23 +134,28 @@ describe "Transcoder" do
115
134
  end
116
135
  end
117
136
 
118
- it "should transcode" do
137
+ it "transcodes" do
119
138
  expect(file.attached_files.key?('original_file_thumb')).to be_falsey
120
139
  file.create_derivatives(filename)
121
140
  file.reload
122
141
  expect(file.attached_files['original_file_thumb']).to have_content
123
142
  expect(file.attached_files['original_file_thumb'].mime_type).to eq('image/png')
124
- expect(file.attached_files['fulltext'].content).to match /This PDF file was created using CutePDF/
143
+ expect(file.attached_files['fulltext'].content).to match(/This PDF file was created using CutePDF/)
125
144
  expect(file.attached_files['fulltext'].mime_type).to eq 'text/plain'
126
145
  end
127
146
  end
128
147
 
129
- describe "with an attached audio", unless: $in_travis do
148
+ describe "with an attached audio", unless: in_travis? do
130
149
  let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
131
150
  let(:attachment) { File.open(filename) }
132
- let(:file) { GenericFile.new(mime_type_from_fits: 'audio/wav').tap { |t| t.original_file.content = attachment; t.save } }
151
+ let(:file) do
152
+ GenericFile.new(mime_type_from_fits: 'audio/wav').tap do |t|
153
+ t.original_file.content = attachment
154
+ t.save
155
+ end
156
+ end
133
157
 
134
- it "should transcode" do
158
+ it "transcodes" do
135
159
  file.create_derivatives(filename)
136
160
  file.reload
137
161
  expect(file.attached_files['original_file_mp3']).to have_content
@@ -141,18 +165,18 @@ describe "Transcoder" do
141
165
  end
142
166
  end
143
167
 
144
- describe "when the source datastrem has an unknown mime_type", unless: $in_travis do
168
+ describe "when the source datastrem has an unknown mime_type", unless: in_travis? do
145
169
  let(:filename) { File.expand_path('../../fixtures/piano_note.wav', __FILE__) }
146
170
  let(:attachment) { File.open(filename) }
147
171
  let(:file) do
148
172
  GenericFile.new(mime_type_from_fits: 'audio/wav').tap do |t|
149
- t.original_file.content = attachment;
150
- t.original_file.mime_type = 'audio/vnd.wav';
173
+ t.original_file.content = attachment
174
+ t.original_file.mime_type = 'audio/vnd.wav'
151
175
  t.save
152
176
  end
153
177
  end
154
178
 
155
- it "should transcode" do
179
+ it "transcodes" do
156
180
  allow_any_instance_of(::Logger).to receive(:warn)
157
181
  file.create_derivatives(filename)
158
182
  file.reload
@@ -161,7 +185,7 @@ describe "Transcoder" do
161
185
  end
162
186
  end
163
187
 
164
- describe "with an attached video", unless: $in_travis do
188
+ describe "with an attached video", unless: in_travis? do
165
189
  let(:filename) { File.expand_path('../../fixtures/countdown.avi', __FILE__) }
166
190
  let(:attachment) { File.open(filename) }
167
191
  let(:file) do
@@ -171,7 +195,7 @@ describe "Transcoder" do
171
195
  end
172
196
  end
173
197
 
174
- it "should transcode" do
198
+ it "transcodes" do
175
199
  file.create_derivatives(filename)
176
200
  file.reload
177
201
  expect(file.attached_files['original_file_mp4']).to have_content
@@ -190,13 +214,13 @@ describe "Transcoder" do
190
214
  Hydra::Derivatives::Processors::Video::Processor.timeout = nil # clear timeout
191
215
  end
192
216
 
193
- it "should raise a timeout" do
217
+ it "raises a timeout" do
194
218
  expect { file.create_derivatives(filename) }.to raise_error Hydra::Derivatives::TimeoutError
195
219
  end
196
220
  end
197
221
  end
198
222
 
199
- describe "with an attached Powerpoint", unless: $in_travis do
223
+ describe "with an attached Powerpoint", unless: in_travis? do
200
224
  let(:filename) { File.expand_path('../../fixtures/FlashPix.ppt', __FILE__) }
201
225
  let(:attachment) { File.open(filename) }
202
226
  let(:file) do
@@ -205,7 +229,7 @@ describe "Transcoder" do
205
229
  end
206
230
  end
207
231
 
208
- it "should transcode" do
232
+ it "transcodes" do
209
233
  file.create_derivatives(filename)
210
234
  file.reload
211
235
  expect(file.attached_files['original_file_thumbnail']).to have_content
@@ -217,12 +241,17 @@ describe "Transcoder" do
217
241
  end
218
242
  end
219
243
 
220
- describe "with an attached rich text format", unless: $in_travis do
244
+ describe "with an attached rich text format", unless: in_travis? do
221
245
  let(:filename) { File.expand_path('../../fixtures/sample.rtf', __FILE__) }
222
246
  let(:attachment) { File.open(filename) }
223
- let(:file) { GenericFile.new(mime_type_from_fits: 'text/rtf').tap { |t| t.original_file.content = attachment; t.save } }
247
+ let(:file) do
248
+ GenericFile.new(mime_type_from_fits: 'text/rtf').tap do |t|
249
+ t.original_file.content = attachment
250
+ t.save
251
+ end
252
+ end
224
253
 
225
- it "should transcode" do
254
+ it "transcodes" do
226
255
  file.create_derivatives(filename)
227
256
  file.reload
228
257
  expect(file.attached_files['original_file_thumbnail']).to have_content
@@ -234,12 +263,19 @@ describe "Transcoder" do
234
263
  end
235
264
  end
236
265
 
237
- describe "with an attached word doc format", unless: $in_travis do
238
- let(:filename) { File.expand_path('../../fixtures/test.doc', __FILE__) }
266
+ describe "with an attached word doc format", unless: in_travis? do
267
+ let(:filename) { File.expand_path('../../fixtures/test.doc', __FILE__) }
239
268
  let(:attachment) { File.open(filename) }
240
- let(:file) { GenericFile.new(mime_type_from_fits: 'application/msword').tap { |t| t.original_file.content = attachment; t.save } }
241
269
 
242
- it "should transcode" do
270
+ let(:file) do
271
+ GenericFile.new(mime_type_from_fits: 'application/msword').tap do |t|
272
+ t.original_file.content = attachment
273
+ t.original_file.mime_type = 'application/msword'
274
+ t.save
275
+ end
276
+ end
277
+
278
+ it "transcodes" do
243
279
  file.create_derivatives(filename)
244
280
  file.reload
245
281
  expect(file.attached_files['original_file_thumbnail']).to have_content
@@ -251,12 +287,19 @@ describe "Transcoder" do
251
287
  end
252
288
  end
253
289
 
254
- describe "with an attached excel format", unless: $in_travis do
255
- let(:filename) { File.expand_path('../../fixtures/test.xls', __FILE__) }
256
- let(:attachment) { File.open(filename)}
257
- let(:file) { GenericFile.new(mime_type_from_fits: 'application/vnd.ms-excel').tap { |t| t.original_file.content = attachment; t.save } }
290
+ describe "with an attached excel format", unless: in_travis? do
291
+ let(:filename) { File.expand_path('../../fixtures/test.xls', __FILE__) }
292
+ let(:attachment) { File.open(filename) }
293
+
294
+ let(:file) do
295
+ GenericFile.new(mime_type_from_fits: 'application/vnd.ms-excel').tap do |t|
296
+ t.original_file.content = attachment
297
+ t.original_file.mime_type = 'application/vnd.ms-excel'
298
+ t.save
299
+ end
300
+ end
258
301
 
259
- it "should transcode" do
302
+ it "transcodes" do
260
303
  file.create_derivatives(filename)
261
304
  file.reload
262
305
  expect(file.attached_files['original_file_thumbnail']).to have_content
@@ -268,11 +311,18 @@ describe "Transcoder" do
268
311
  end
269
312
  end
270
313
 
271
- describe "with an attached tiff", unless: $in_travis do
314
+ describe "with an attached tiff", unless: in_travis? do
272
315
  let(:filename) { File.expand_path('../../fixtures/test.tif', __FILE__) }
273
- let(:attachment) { File.open(filename)}
274
- let(:file) { GenericFile.new(mime_type_from_fits: 'image/tiff').tap { |t| t.original_file.content = attachment; t.save } }
275
- it "should transcode" do
316
+ let(:attachment) { File.open(filename) }
317
+
318
+ let(:file) do
319
+ GenericFile.new(mime_type_from_fits: 'image/tiff').tap do |t|
320
+ t.original_file.content = attachment
321
+ t.save
322
+ end
323
+ end
324
+
325
+ it "transcodes" do
276
326
  file.create_derivatives(filename)
277
327
  file.reload
278
328
  expect(file.attached_files['original_file_diy']).to have_content