OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[63521] Do nothing if relation to delete does not exist anymore
Christophe Bliardcd7403932b9b
diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rbindex e949dec1758..196b8a001fb 100644--- a/app/controllers/work_package_relations_controller.rb+++ b/app/controllers/work_package_relations_controller.rb@@ -33,7 +33,7 @@ class WorkPackageRelationsController < ApplicationControllerinclude OpTurbo::DialogStreamHelperbefore_action :set_work_package- before_action :set_relation, except: %i[new create]+ before_action :set_relation, only: %i[edit update]before_action :authorizedef new@@ -90,7 +90,13 @@ class WorkPackageRelationsController < ApplicationControllerenddef destroy- service_result = Relations::DeleteService.new(user: current_user, model: @relation).call+ @relation = @work_package.relations.find_by(id: params[:id])+ service_result =+ if @relation+ Relations::DeleteService.new(user: current_user, model: @relation).call+ else+ ServiceResult.success+ endrespond_with_relations_tab_update(service_result)enddiff --git a/spec/controllers/work_package_relations_controller_spec.rb b/spec/controllers/work_package_relations_controller_spec.rbindex 0503650f5ac..99502174f41 100644--- a/spec/controllers/work_package_relations_controller_spec.rb+++ b/spec/controllers/work_package_relations_controller_spec.rb@@ -165,5 +165,18 @@ RSpec.describe WorkPackageRelationsController do.with(component: an_instance_of(WorkPackageRelationsTab::IndexComponent))expect { relation.reload }.to raise_error(ActiveRecord::RecordNotFound)end++ it "does nothing if the given relation does not exist" do+ deleted_relation_id = relation.id+ relation.destroy+ delete("destroy", params: { work_package_id: work_package.id, id: deleted_relation_id }, as: :turbo_stream)++ expect(response).to be_successful++ expect(WorkPackageRelationsTab::IndexComponent).to have_received(:new)+ .with(work_package:)+ expect(controller).to have_received(:replace_via_turbo_stream)+ .with(component: an_instance_of(WorkPackageRelationsTab::IndexComponent))+ endendend