Skip to content

Commit

Permalink
Don't fail if model doesn't respond to marked for destruction (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
santib authored Oct 3, 2024
1 parent a403b8a commit dc91c8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .reek.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ detectors:
allow_calls: []
FeatureEnvy:
enabled: true
exclude:
exclude:
- 'YAAF::Form#promote_legacy_errors'
- 'YAAF::Form#save_models'
InstanceVariableAssumption:
Expand All @@ -44,7 +44,8 @@ detectors:
max_params: 3
ManualDispatch:
enabled: true
exclude: []
exclude:
- 'YAAF::Form#save_models'
MissingSafeMethod:
enabled: false
exclude: []
Expand Down
6 changes: 5 additions & 1 deletion lib/yaaf/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ def save_models(options)
options.merge!(validate: false)

models.map do |model|
model.marked_for_destruction? ? model.destroy! : model.save!(**options)
if model.respond_to?(:marked_for_destruction?) && model.marked_for_destruction?
model.destroy!
else
model.save!(**options)
end
end
end

Expand Down

0 comments on commit dc91c8e

Please sign in to comment.