fix: assign_to.procedure_presentation should return an ActiveModel::Errors if needed

the caller will then calls `errors.full_messages`
This commit is contained in:
simon lehericey 2024-10-31 03:27:05 +01:00
parent 59b7b3dc91
commit f27598f235
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 4 additions and 2 deletions

View file

@ -24,7 +24,9 @@ class AssignTo < ApplicationRecord
errors = begin errors = begin
procedure_presentation.errors if procedure_presentation&.invalid? procedure_presentation.errors if procedure_presentation&.invalid?
rescue ActiveRecord::RecordNotFound => e rescue ActiveRecord::RecordNotFound => e
[e.message] errors = ActiveModel::Errors.new(self)
errors.add(:procedure_presentation, e.message)
errors
end end
if errors.present? if errors.present?

View file

@ -45,7 +45,7 @@ describe AssignTo, type: :model do
it do it do
expect(procedure_presentation_or_default).to be_persisted expect(procedure_presentation_or_default).to be_persisted
expect(procedure_presentation_or_default).to be_valid expect(procedure_presentation_or_default).to be_valid
expect(errors).to be_present expect(errors.full_messages).to include(/unable to find procedure 666/)
expect(assign_to.procedure_presentation).not_to be(procedure_presentation) expect(assign_to.procedure_presentation).not_to be(procedure_presentation)
end end
end end