Skip to content

Commit

Permalink
Merge pull request #150 from projecthydra-labs/remove_derivatives_spec
Browse files Browse the repository at this point in the history
Provide test coverage for a/v specs and remove CurationConcerns::CreateDerivativesService
  • Loading branch information
mjgiarlo committed Aug 13, 2015
2 parents 7389529 + 1f5cff4 commit 14ec5ab
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 221 deletions.
4 changes: 1 addition & 3 deletions app/helpers/curation_concerns/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ module UrlHelper
# override Blacklight so we can use our 'curation_concern' namespace
# We may also pass in a ActiveFedora document instead of a SolrDocument
def url_for_document doc, options = {}
if Hydra::Works.generic_file?(doc)
main_app.curation_concerns_generic_file_path(doc)
elsif doc.collection?
if doc.collection?
doc
else
polymorphic_path([main_app, :curation_concerns, doc])
Expand Down
3 changes: 2 additions & 1 deletion curation_concerns-models/app/jobs/create_derivatives_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def run
if generic_file.video?
return unless CurationConcerns.config.enable_ffmpeg
end
CurationConcerns::CreateDerivativesService.run(generic_file)

generic_file.create_derivatives
generic_file.save
end
end

This file was deleted.

16 changes: 8 additions & 8 deletions curation_concerns-models/curation_concerns-models.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

# spec.add_dependency 'hydra-head', "~> 9.0.0.beta1"
# spec.add_dependency "active-fedora", "~> 9.0.0.beta5"
spec.add_dependency "active_attr"
spec.add_dependency 'hydra-works'#, '~> 0.0.1'
spec.add_dependency 'active_fedora-noid'
spec.add_dependency 'active_attr'
spec.add_dependency 'nest', '~> 1.1'
spec.add_dependency 'hydra-collections', [">= 5.0.2", "< 6.0"]
spec.add_dependency 'hydra-collections', '~> 6.0.0.alpha'
spec.add_dependency 'hydra-head', '~> 9.2.2'
spec.add_dependency 'hydra-works', '~> 0.1'
spec.add_dependency 'active-fedora', '~> 9.3.0'
spec.add_dependency 'active_fedora-noid', '~> 1.0.2'
spec.add_dependency 'resque', '~> 1.23'
spec.add_dependency 'resque-pool', '~> 0.3'

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
spec.add_development_dependency 'bundler', '~> 1.6'
spec.add_development_dependency 'rake'
end
5 changes: 3 additions & 2 deletions spec/helpers/url_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
expect(helper.url_for_document document).to eq "/concern/generic_works/#{work.id}"
end
context "when document is a GenericFile" do
let(:document) { GenericFile.new id: '123' }
it { should eq "/concern/generic_files/123" }
let(:file) { FactoryGirl.create(:generic_file) }
subject { helper.url_for_document file }
it { should eq "/concern/generic_files/#{file.id}" }
end
end

7 changes: 5 additions & 2 deletions spec/jobs/characterize_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

subject { CharacterizeJob.new(generic_file.id) }

it 'spawns a CreateDerivatives job' do
# Now that CreateDerivativesJob calls generic_file.create_derivatives directly
# this test needs to be travis exempt.
it 'runs CurationConcerns::CharacterizationService that spawns a CreateDerivativesJob', unless: $in_travis do
expect(CurationConcerns::CharacterizationService).to receive(:run).with(generic_file)
expect(CurationConcerns::CreateDerivativesService).to receive(:run).with(generic_file)
expect(CreateDerivativesJob).to receive(:new).with(generic_file.id).once.and_call_original
subject.run
end

end
7 changes: 3 additions & 4 deletions spec/jobs/create_derivatives_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe CurationConcerns::CreateDerivativesService do
describe CurationConcerns::CreateDerivativesJob do
before do
@ffmpeg_enabled = CurationConcerns.config.enable_ffmpeg
CurationConcerns.config.enable_ffmpeg = true
Expand All @@ -15,9 +15,8 @@

subject { CreateDerivativesJob.new('123') }

# Should be refactored to test CurationConcerns::CreateDerivativesService
it "should run the derivative creation service and save" do
expect(CurationConcerns::CreateDerivativesService).to receive(:run).with(generic_file)
it "should call create_derivatives and save on a generic_file" do
expect(generic_file).to receive(:create_derivatives)
expect(generic_file).to receive(:save)
subject.run
end
Expand Down
1 change: 0 additions & 1 deletion spec/jobs/ingest_local_file_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

it "should have attached a file" do
expect(CurationConcerns::CharacterizationService).to receive(:run).with(generic_file)
expect(CurationConcerns::CreateDerivativesService).to receive(:run).with(generic_file)
job.run
expect(generic_file.reload.original_file.size).to eq(4218)
end
Expand Down
88 changes: 88 additions & 0 deletions spec/models/curation_concerns/generic_file/derivatives_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
require 'spec_helper'

describe CurationConcerns::GenericFile do

describe 'audiovisual transcoding' do
before do
file = File.open(File.join(fixture_path, file_name), 'r')
Hydra::Works::UploadFileToGenericFile.call(generic_file, file)
allow_any_instance_of(Hydra::Works::GenericFile::Base).to receive(:mime_type).and_return(mime_type)
generic_file.save!
end


context 'with a video (.avi) file', unless: $in_travis do
let(:mime_type) { 'video/avi' }
let(:file_name) { 'countdown.avi' }
let(:generic_file) { GenericFile.create { |gf| gf.apply_depositor_metadata('jcoyne@example.com') } }

it 'transcodes to webm and mp4' do
generic_file.create_derivatives
derivative = generic_file.webm
expect(derivative).not_to be_nil
expect(derivative.content).not_to be_nil
expect(derivative.mime_type).to eq('video/webm')

derivative2 = generic_file.mp4
expect(derivative2).not_to be_nil
expect(derivative2.content).not_to be_nil
expect(derivative2.mime_type).to eq('video/mp4')
end
end

context 'with an audio (.wav) file', unless: $in_travis do
let(:mime_type) { 'audio/wav' }
let(:file_name) { 'piano_note.wav' }
let(:generic_file) { GenericFile.create { |gf| gf.apply_depositor_metadata('jcoyne@example.com') } }

it 'transcodes to mp3 and ogg' do
generic_file.create_derivatives
derivative = generic_file.mp3
expect(derivative).not_to be_nil
expect(derivative.content).not_to be_nil
expect(derivative.mime_type).to eq('audio/mpeg')

derivative2 = generic_file.ogg
expect(derivative2).not_to be_nil
expect(derivative2.content).not_to be_nil
expect(derivative2.mime_type).to eq('audio/ogg')
end
end

context 'with an mp3 file', unless: $in_travis do
let(:mime_type) { 'audio/mpeg' }
let(:file_name) { 'test5.mp3' }
let(:generic_file) { GenericFile.create { |gf| gf.apply_depositor_metadata('jcoyne@example.com') } }

xit 'should copy the content to the mp3 datastream and transcode to ogg' do
generic_file.create_derivatives
derivative = generic_file.mp3

expect(derivative.size).to eq(generic_file.original_file.size)
expect(derivative.mime_type).to eq('audio/mpeg')
derivative2 = generic_file.ogg
expect(derivative2.content).not_to be_nil
expect(derivative2.mime_type).to eq('audio/ogg')
end
end

context 'with an ogg file', unless: $in_travis do
let(:mime_type) { 'audio/ogg' }
let(:file_name) { 'Example.ogg' }
let(:generic_file) { GenericFile.create { |gf| gf.apply_depositor_metadata('jcoyne@example.com') } }

xit 'should copy the content to the ogg datastream and transcode to mp3' do
generic_file.create_derivatives
derivative = generic_file.mp3
expect(derivative).not_to be_nil
expect(derivative.content).not_to be_nil
expect(derivative.mime_type).to eq('audio/mpeg')

derivative2 = generic_file.ogg
expect(derivative2).not_to be_nil
expect(derivative2.size).to eq(generic_file.original_file.size)
expect(derivative2.mime_type).to eq('audio/ogg')
end
end
end
end
2 changes: 1 addition & 1 deletion spec/models/generic_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
end

it "is a Hydra::Works GenericFile" do
expect(Hydra::Works.generic_file?(subject)).to be_truthy
expect(subject).to be_works_generic_file
end

it "should have depositor" do
Expand Down
171 changes: 0 additions & 171 deletions spec/services/create_derivatives_service_spec.rb

This file was deleted.

Loading

0 comments on commit 14ec5ab

Please sign in to comment.