From 9c94d26f3d0f87b09b6fba19cd1d2da65c74474d Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Mon, 21 Oct 2019 22:43:25 -0400 Subject: [PATCH] automatically convert valkyrie resource to ActiveJobProxy when enqueuing --- app/jobs/hyrax/application_job.rb | 5 +++++ spec/jobs/visibility_copy_job_spec.rb | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/jobs/hyrax/application_job.rb b/app/jobs/hyrax/application_job.rb index ed25d4e9b3..1695b81da9 100644 --- a/app/jobs/hyrax/application_job.rb +++ b/app/jobs/hyrax/application_job.rb @@ -3,5 +3,10 @@ module Hyrax # This allows downstream applications to manipulate all the hyrax jobs by # including modules on this class. class ApplicationJob < ::ApplicationJob + before_enqueue do |job| + job.arguments.map! do |arg| + arg.is_a?(Valkyrie::Resource) ? Hyrax::ActiveJobProxy.new(resource: arg) : arg + end + end end end diff --git a/spec/jobs/visibility_copy_job_spec.rb b/spec/jobs/visibility_copy_job_spec.rb index 0c9fafad11..205f189d7a 100644 --- a/spec/jobs/visibility_copy_job_spec.rb +++ b/spec/jobs/visibility_copy_job_spec.rb @@ -6,8 +6,9 @@ let(:resource) { FactoryBot.create(:work_with_files).valkyrie_resource } let(:queries) { Hyrax.query_service.custom_queries } - it 'serializes proxies' do - expect { described_class.perform_later(proxy) }.not_to raise_error + it 'converts resource to proxy when enqueuing' do + expect { described_class.perform_later(resource) } + .to have_enqueued_job.with("_aj_globalid" => proxy.to_global_id.to_s) end it 'copies visibility to file sets' do