From 08c0c599b8da213e12781d2fa9b4a22447431cf0 Mon Sep 17 00:00:00 2001 From: Santiago Bartesaghi Date: Tue, 8 Oct 2024 16:14:04 -0300 Subject: [PATCH] Improve model destroy --- .reek.yml | 2 ++ lib/yaaf/form.rb | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.reek.yml b/.reek.yml index 07936c9..0a334c6 100644 --- a/.reek.yml +++ b/.reek.yml @@ -26,6 +26,7 @@ detectors: exclude: - 'YAAF::Form#promote_legacy_errors' - 'YAAF::Form#save_models' + - 'YAAF::Form#validate_models' InstanceVariableAssumption: enabled: false IrresponsibleModule: @@ -46,6 +47,7 @@ detectors: enabled: true exclude: - 'YAAF::Form#save_models' + - 'YAAF::Form#validate_models' MissingSafeMethod: enabled: false exclude: [] diff --git a/lib/yaaf/form.rb b/lib/yaaf/form.rb index 8e7c1f5..8e0417d 100644 --- a/lib/yaaf/form.rb +++ b/lib/yaaf/form.rb @@ -62,7 +62,11 @@ def save_models(options) end def validate_models - models.each { |model| promote_errors(model) if model.invalid? } + models.each do |model| + next if model.respond_to?(:marked_for_destruction?) && model.marked_for_destruction? + + promote_errors(model) if model.invalid? + end end def promote_errors(model)