From cf5538a25138b5d6f4e85c269cab59716e733468 Mon Sep 17 00:00:00 2001 From: Lelievre-david <81243462+Lelievre-david@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:05:27 +0100 Subject: [PATCH] =?UTF-8?q?fix(request):=20supprimer=20les=20requests=5Fdi?= =?UTF-8?q?stributions=20quand=20une=20request=20est=20termin=C3=A9e=20#91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/request.rb | 6 ++++++ db/seeds.rb | 6 ------ spec/acceptance/api/v1/requests_controller_spec.rb | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/models/request.rb b/app/models/request.rb index 45eff57..a1ad65a 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -73,6 +73,12 @@ class Request < ApplicationRecord length: { minimum: 1, message: :at_least_one } validates :plant_stage, presence: true end + + after_transition to: :completed, do: :cleanup_request_distributions + end + + def cleanup_request_distributions + request_distributions.destroy_all end end diff --git a/db/seeds.rb b/db/seeds.rb index b33fd6f..debdaf0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -50,12 +50,6 @@ area: 40 ) - Pot.create!( - name: 'My other pot', - shape: :other, - area: 120 - ) - building1 = Building.create!( name: 'Main Building', description: 'The main building that houses the primary operations.' diff --git a/spec/acceptance/api/v1/requests_controller_spec.rb b/spec/acceptance/api/v1/requests_controller_spec.rb index 5c32fa5..c7782a3 100644 --- a/spec/acceptance/api/v1/requests_controller_spec.rb +++ b/spec/acceptance/api/v1/requests_controller_spec.rb @@ -217,6 +217,7 @@ request.reload expect(response_body).to eq(request.to_blueprint) expect(request.status).to eq(:completed) + expect(request.request_distributions).to be_empty end end