From e1e1e53bed53f56fd2c45df805c00c58f687a0d9 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Guerra Date: Thu, 19 Dec 2024 12:19:44 -0300 Subject: [PATCH] fix: avoid deleting manual assignments while syncing demand --- app/controllers/demands_controller.rb | 2 +- spec/controllers/demands_controller_spec.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/demands_controller.rb b/app/controllers/demands_controller.rb index 6cd865188..82a45f393 100644 --- a/app/controllers/demands_controller.rb +++ b/app/controllers/demands_controller.rb @@ -105,7 +105,7 @@ def demand_efforts private def clean_assignments_efforts - @demand.item_assignments.destroy_all + @demand.item_assignments.joins(:demand_efforts).where(demand_efforts: { automatic_update: true }).destroy_all @demand.demand_efforts.where(automatic_update: true).destroy_all end diff --git a/spec/controllers/demands_controller_spec.rb b/spec/controllers/demands_controller_spec.rb index 8c7c2fa3d..3d952d21d 100644 --- a/spec/controllers/demands_controller_spec.rb +++ b/spec/controllers/demands_controller_spec.rb @@ -385,8 +385,10 @@ it 'calls the services and the reader' do first_assignment = Fabricate :item_assignment, demand: first_demand second_assignment = Fabricate :item_assignment, demand: first_demand - first_effort = Fabricate :demand_effort, demand: first_demand - other_effort = Fabricate :demand_effort, demand: first_demand + manual_assignment = Fabricate :item_assignment, demand: first_demand + first_effort = Fabricate :demand_effort, demand: first_demand, automatic_update: true, item_assignment: first_assignment + other_effort = Fabricate :demand_effort, demand: first_demand, automatic_update: true, item_assignment: second_assignment + manual_effort = Fabricate :demand_effort, demand: first_demand, automatic_update: false, item_assignment: manual_assignment expect(Jira::ProcessJiraIssueJob).to receive(:perform_later) put :synchronize_jira, params: { company_id: company, id: first_demand } @@ -396,6 +398,8 @@ expect(first_demand.reload.item_assignments).not_to include(first_assignment, second_assignment) expect(first_demand.demand_efforts).not_to include(first_effort, other_effort) + expect(first_demand.demand_efforts).to include(manual_effort) + expect(first_demand.item_assignments).to include(manual_assignment) end end end