aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXinhui2017-03-06 15:39:33 +0100
committerXinhui2017-03-06 15:39:39 +0100
commitdaec6d64491babba57bdd2f6177610efdad11506 (patch)
tree52acf8b939d4fd48e2625eab7d8d062611c6e67b
parenta0d2463c8eb3ca9c901ff67d0e1126dd7fa988f7 (diff)
downloadchouette-core-daec6d64491babba57bdd2f6177610efdad11506.tar.bz2
ReferentialDestroyWorker
Refs #2695
-rw-r--r--app/controllers/workbenches_controller.rb6
-rw-r--r--app/workers/referential_destroy_worker.rb8
-rw-r--r--spec/workers/referential_destroy_worker_spec.rb8
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