diff options
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 6 | ||||
| -rw-r--r-- | app/workers/referential_destroy_worker.rb | 8 | ||||
| -rw-r--r-- | spec/workers/referential_destroy_worker_spec.rb | 8 |
3 files changed, 20 insertions, 2 deletions
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index f3dc0c9b3..44c6b174b 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -18,9 +18,11 @@ class WorkbenchesController < BreadcrumbController def delete_referentials referentials = resource.referentials.where(id: params[:referentials]) - if referentials.destroy_all - flash[:notice] = t('notice.referentials.deleted') + referentials.each do |referential| + ReferentialDestroyWorker.perform_async(referential.id) + referential.update_attribute(:ready, false) end + flash[:notice] = t('notice.referentials.deleted') redirect_to resource end diff --git a/app/workers/referential_destroy_worker.rb b/app/workers/referential_destroy_worker.rb new file mode 100644 index 000000000..9c4ef3081 --- /dev/null +++ b/app/workers/referential_destroy_worker.rb @@ -0,0 +1,8 @@ +class ReferentialDestroyWorker + include Sidekiq::Worker + + def perform(id) + ref = Referential.find id + ref.destroy if ref + end +end diff --git a/spec/workers/referential_destroy_worker_spec.rb b/spec/workers/referential_destroy_worker_spec.rb new file mode 100644 index 000000000..b24d72fd3 --- /dev/null +++ b/spec/workers/referential_destroy_worker_spec.rb @@ -0,0 +1,8 @@ +require 'rails_helper' +RSpec.describe ReferentialDestroyWorker, type: :worker do + let!(:referential) { create :referential } + + it 'should destroy referential on worker perform' do + expect{ReferentialDestroyWorker.new.perform(referential.id)}.to change(Referential, :count).by(-1) + end +end |
