Skip to content

Commit

Permalink
Merge pull request #4916 from samvera/gh-4196-ingest-local-file-job-v…
Browse files Browse the repository at this point in the history
…alkyrization

Refactoring to make an easier change
  • Loading branch information
elrayle authored May 5, 2021
2 parents a859788 + 787513f commit 7f346f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
6 changes: 6 additions & 0 deletions app/jobs/ingest_local_file_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ class IngestLocalFileJob < Hyrax::ApplicationJob
# @param [String] path
# @param [User] user
def perform(file_set, path, user)
perform_af(file_set, path, user)
end

private

def perform_af(file_set, path, user)
file_set.label ||= File.basename(path)

actor = Hyrax::Actors::FileSetActor.new(file_set, user)
Expand Down
56 changes: 28 additions & 28 deletions spec/jobs/ingest_local_file_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@

RSpec.describe IngestLocalFileJob do
let(:user) { create(:user) }
let(:path) { File.join(fixture_path, 'world.png') }

let(:file_set) { FileSet.new }
let(:actor) { double }
let(:path) do
File.join(fixture_path, 'world.png')
end

before do
allow(Hyrax::Actors::FileSetActor).to receive(:new).with(file_set, user).and_return(actor)
end

it 'has attached a file' do
expect(FileUtils).not_to receive(:rm)
expect(actor).to receive(:create_content).and_return(true)
described_class.perform_now(file_set, path, user)
end
context 'when use_valkyrie is false' do
let(:actor) { double }
let(:file_set) { FileSet.new }

context 'when an error is encountered when trying to save the file to disk' do
let(:callback) do
instance_double(Hyrax::Callbacks::Registry)
end
let(:config) do
instance_double(Hyrax::Configuration)
before do
allow(Hyrax::Actors::FileSetActor).to receive(:new).with(file_set, user).and_return(actor)
end

before do
allow(callback).to receive(:run)
allow(config).to receive(:callback).and_return(callback)
allow(Hyrax).to receive(:config).and_return(config)
allow(actor).to receive(:create_content).and_raise(SystemCallError, "example file system error")
it 'has attached a file' do
expect(FileUtils).not_to receive(:rm)
expect(actor).to receive(:create_content).and_return(true)
described_class.perform_now(file_set, path, user)
end

it "invokes the file failure callback" do
expect(callback).to have_received(:run).with(:after_import_local_file_failure, file_set, user, path, warn: false)
context 'when an error is encountered when trying to save the file to disk' do
let(:callback) do
instance_double(Hyrax::Callbacks::Registry)
end
let(:config) do
instance_double(Hyrax::Configuration)
end

before do
allow(callback).to receive(:run)
allow(config).to receive(:callback).and_return(callback)
allow(Hyrax).to receive(:config).and_return(config)
allow(actor).to receive(:create_content).and_raise(SystemCallError, "example file system error")
described_class.perform_now(file_set, path, user)
end

it "invokes the file failure callback" do
expect(callback).to have_received(:run).with(:after_import_local_file_failure, file_set, user, path, warn: false)
end
end
end
end

0 comments on commit 7f346f9

Please sign in to comment.