Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Make DeleteJob work wth new class method .find #912

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/jobs/bulkrax/delete_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ class DeleteJob < ApplicationJob
queue_as :import

def perform(entry, importer_run)
obj = entry.factory.find
obj&.delete
obj = entry.factory.class.find(entry.raw_metadata["id"])
kirkkwang marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, why can we do entry.factory.find?

It seams like we could be able to call entry.factory.delete(user: importer_run.importer.user) and it would do the right thing.


if defined?(Valkyrie) && obj.class < Valkyrie::Resource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 11 through 13 go in the Bulkrax::ValkyrieObjectFactory as the delete-ish method.

Hyrax.persister.delete(resource: obj)
Hyrax.index_adapter.delete(resource: obj)
Hyrax.publisher.publish('object.deleted', object: obj, user: importer_run.importer.user)
else
obj&.delete
end

# rubocop:disable Rails/SkipsModelValidations
ImporterRun.increment_counter(:deleted_records, importer_run.id)
ImporterRun.decrement_counter(:enqueued_records, importer_run.id)
Expand Down
18 changes: 11 additions & 7 deletions spec/jobs/bulkrax/delete_work_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ module Bulkrax
subject(:delete_work_job) { described_class.new }
let(:entry) { create(:bulkrax_entry) }
let(:importer_run) { create(:bulkrax_importer_run) }
let(:factory) do
Bulkrax::ObjectFactory.new(attributes: {},
source_identifier_value: '123',
work_identifier: :source,
work_identifier_search_field: :source_identifier)
end

describe 'successful job object removed' do
before do
work = instance_double("Work")
factory = instance_double("Bulkrax::ObjectFactory")
expect(work).to receive(:delete).and_return true
expect(factory).to receive(:find).and_return(work)
expect(entry).to receive(:factory).and_return(factory)
allow(work).to receive(:delete).and_return true
allow(factory.class).to receive(:find).and_return(work)
allow(entry).to receive(:factory).and_return(factory)
end

it 'increments :deleted_records' do
Expand All @@ -31,9 +36,8 @@ module Bulkrax

describe 'successful job object not found' do
before do
factory = instance_double("Bulkrax::ObjectFactory")
expect(factory).to receive(:find).and_return(nil)
expect(entry).to receive(:factory).and_return(factory)
allow(factory.class).to receive(:find).and_return(nil)
allow(entry).to receive(:factory).and_return(factory)
end

it 'increments :deleted_records' do
Expand Down
Loading